PlSql动态游标用输入动态表名创建

时间:2014-10-30 09:55:57

标签: plsql plsqldeveloper

您好我的PL / SQL功能

create or replace
PROCEDURE DiffrencesIdentifyerProc(db_nameFirst VARCHAR2,db_nameSecond VARCHAR2,table_name VARCHAR2) IS

dbremort varchar2(100):= db_nameFirst;
dblocal varchar2(100):= db_nameSecond;
tableName varchar2(100) := table_name;

CURSOR cur IS
SELECT * FROM s1.ENTITYFIELDS  MINUS SELECT * FROM s2.ENTITYFIELDS;
BEGIN
FOR e IN cur
LOOP
dbms_output.put_line(e.ATTACH_NAME ); 
END LOOP; 
END DiffrencesIdentifyerProc;

我想要的是

CURSOR cur IS
 SELECT * FROM s1.ENTITYFIELDS  MINUS SELECT * FROM s2.ENTITYFIELDS;

选择要传递参数的部件,如

SELECT * FROM dbremort.dbremort   MINUS SELECT * FROM dbremort.dbremort ;

我该怎么办?

1 个答案:

答案 0 :(得分:1)

将您的查询构建/构建到varchar2(或在Oracle 11g或更新版本上为clob)变量,然后使用native dynamic SQLopen for ...语句打开游标和fetch语句以从中获取。

请记住,无论如何,您必须有一个静态声明的结构来从光标中获取数据,因此您的动态查询必须具有相同数量的选定列identical (or implicitly convertable) data types