問題描述
如何識別 For / Select / Loop 中的行號 (How do I identify the row number in a For / Select / Loop)
我有一段來自 Oracle 過程的代碼。這部分工作正常:
for r in (select * from json_table
(l_resp, '$.items[0].volumeInfo.authors[*]'
columns author varchar2(256) path '$'
)
)
loop
dbms_output.put_line('The value of Author ' || ' is: ' || r.author);
end loop r;
我想做的是獲取當前正在處理的行號。類似於“r”行的 ROWNUM。 我想將 dbms_output 行調整為如下所示:
dbms_output.put_line('The value of Author ' || r.rownum || ' is: ' || r.author);
但是 r.rownum 不起作用。如何引用“r.rownum”之類的內容?
參考解法
方法 1:
I found a way.
For rowz in
(select rownum rn, j_auth_tab.*
from json_table(l_resp, '$.items[0].volumeInfo.authors[*]'
columns author varchar2(512) path '$') j_auth_tab)
Loop
dbms_output.put_line('Rownum: ' || rowz.rn || ' Author: ' || rowz.author);
End loop rowz;
That solved my problem.
(by user3138025、user3138025)