create or replace
PROCEDURE PROCEDURENEW
(pi_procname varchar2,
PO_CURSOR OUT sys_refcursor)
IS
P_RS sys_refcursor;
L_COLS NUMBER;
L_DESC DBMS_SQL.DESC_TAB;
L_CURS INTEGER;
L_VARCHAR VARCHAR2(400);
out_result VARCHAR2(600);
out_result1 VARCHAR2(400);
v_sql varchar2(300);
out_result2 varchar2(300);
v_sql1 varchar2(300);
BEGIN
-- //These two lines are showing an error.
v_sql1 := 'SELECT'||pi_procname||'from dual';
execute immediate 'begin'||v_sql1||'(P_RS);end;' USING P_RS;
-- //These above two lines are showing an error.
L_CURS := DBMS_SQL.TO_CURSOR_NUMBER(P_RS);
DBMS_SQL.DESCRIBE_COLUMNS(
C => L_CURS, COL_CNT => L_COLS,
DESC_T => L_DESC);
FOR i IN 1..L_COLS LOOP
DBMS_SQL.DEFINE_COLUMN(L_CURS, i, L_VARCHAR, 4000);
END LOOP;
FOR i IN 1..L_COLS LOOP
IF(
L_DESC(i).col_name = 'CREATEDBY' OR L_DESC(i).col_name = 'CREATEDDT' OR
L_DESC(i).col_name = 'CREATEDAT' OR L_DESC(i).col_name = 'UPDATEDBY' OR
L_DESC(i).col_name = 'UPDATEDDT' OR L_DESC(i).col_name = 'UPDATEDAT' OR
L_DESC(i).col_name = 'ROWVERSION'
) THEN
DBMS_SQL.COLUMN_VALUE(L_CURS, i, L_VARCHAR);
L_VARCHAR := NULL;
ELSE
out_result := out_result||
CASE
WHEN i = 1 THEN
NULL
ELSE
','
END || L_DESC(i).col_name;
END IF;
END LOOP;
WHILE DBMS_SQL.FETCH_ROWS(L_CURS) > 0 LOOP
FOR i IN 1..L_COLS LOOP
IF(
L_DESC(i).col_name = 'CREATEDBY' or L_DESC(i).col_name = 'CREATEDDT' or
L_DESC(i).col_name = 'CREATEDAT' or L_DESC(i).col_name = 'UPDATEDBY' or
L_DESC(i).col_name = 'UPDATEDDT' or L_DESC(i).col_name = 'UPDATEDAT' or
L_DESC(i).col_name = 'ROWVERSION'
)
THEN
DBMS_SQL.COLUMN_VALUE(L_CURS, i, L_VARCHAR);
L_VARCHAR := NULL;
ELSE
DBMS_SQL.COLUMN_VALUE(L_CURS, i, L_VARCHAR);
out_result1 := out_result1|| CHR(10) ||L_VARCHAR ;
END IF;
END LOOP;
END LOOP;
out_result2 := out_result ||chr(10)|| out_result1;
DBMS_SQL.CLOSE_CURSOR(L_CURS);
OPEN PO_CURSOR for select out_result2 from dual;
END PROCEDURENEW;
我希望从ui动态地将过程名称传递给数据库,并在网格中显示结果。
我尝试编写一个过程,该过程将过程名称作为输入并执行过程,并将结果作为REF_CURSOR
传递。
要执行的过程也在ref cursor中返回结果。
但是当编译上面的proc时,我面临很多错误。
我想知道在上面的过程中调用过程名称的方法。
答案 0 :(得分:1)
应该是这样的
execute immediate 'begin '||pi_procname||'(:P_RS);end;' USING OUT P_RS;
注意'begin'之后的空格字符!