如何遍历 oracle pl/sql 游标中的列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2608475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 20:23:43  来源:igfitidea点击:

How to loop through columns in an oracle pl/sql cursor

oracleplsql

提问by Lloyd

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;     

回答by DCookie

You will need to use Oracle Dynamic SQL, most likely method 4.

您将需要使用Oracle 动态 SQL,很可能是方法 4

EDIT: Sorry, the above is for Pro*C. You will need to use the DBMS_SQLpackage. 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.

编辑:抱歉,以上内容适用于 Pro*C。您将需要使用DBMS_SQL包。它相当复杂,但允许您在运行时解析、执行和获取您需要的任意 SQL 语句。特别是,请查看示例 3 和 8。