如何在Oracle PL/SQL游标中遍历列 [英] How to loop through columns in an oracle pl/sql cursor
本文介绍了如何在Oracle PL/SQL游标中遍历列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个动态游标,我想遍历游标中存在的列.我该怎么办?
I am creating a dynamic cursor and I would like to loop over the columns that exist in the cursor. How would I do that?
例如:
create or replace procedure dynamic_cursor(empid in varchar2, RC IN OUT sys_refcursor) as
stmt varchar2(100);
begin
stmt := 'select * from employees where id = ' || empid;
open RC for stmt using val;
for each {{COLUMN OR SOMETHING}}
--TODO: Get this to work
loop;
end;
推荐答案
您将需要使用方法4 .
You will need to use Oracle Dynamic SQL, most likely method 4.
抱歉,以上内容适用于Pro * C.您将需要使用 DBMS_SQL 包装.它相当复杂,但是将允许您在运行时解析,执行和获取所需的任意SQL语句.特别要看一下示例3和8.
Sorry, the above is for Pro*C. You will need to use the DBMS_SQL package. It's fairly complex, but will allow you to parse, execute, and fetch any arbitrary SQL statement you need, all at run time. In particular, have a look at examples 3 and 8.
这篇关于如何在Oracle PL/SQL游标中遍历列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文