如何循环访问 oracle pl/sql 游标中的列
我正在创建一个动态游标,我想循环游标中存在的列。我该怎么做呢?
例如:
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;
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?
For example:
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要使用 Oracle 动态 SQL ,最有可能是方法 4。
编辑:
抱歉,以上内容适用于 Pro*C。您将需要使用 DBMS_SQL 包。它相当复杂,但允许您在运行时解析、执行和获取所需的任意 SQL 语句。特别是看一下示例 3 和 8。
You will need to use Oracle Dynamic SQL, most likely method 4.
EDIT:
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.