oracle存储过程的一个问题(100分)

  • 主题发起人 主题发起人 wx_zhang
  • 开始时间 开始时间
W

wx_zhang

Unregistered / Unconfirmed
GUEST, unregistred user!
在ORACLE的存储过程中能不能把表的名字用变量来表示?象定义SSS变量,然后根据不同的情况
给SSS赋值,最后再

select * from sss
 
可以,用动态游标
CREATE OR REPLACE PROCEDURE do_two_unrelated_actions
(tab_in IN VARCHAR2)
IS
cur INTEGER := DBMS_SQL.OPEN_CURSOR;

BEGIN
/* Piece together a CREATE INDEX statement. */
DBMS_SQL.PARSE (cur, 'Select * From' || tab_in , DBMS_SQL.NATIVE);
DBMS_SQL.EXECUTE (cur);
DBMS_SQL.CLOSE_CURSOR (cur);
END;
 
再详细些好吗?没接触过这种游标

在DBMS_SQL.EXECUTE (cur)后怎么访问结果集?
 
ROCEDURE fill_block (where_clause_in IN VARCHAR2)
IS
c INTEGER := DBMS_SQL.OPEN_CURSOR;
emprec employee%ROWTYPE;
employee_id integer;
employee_nm varchar2(30);

fdbk INTEGER;
BEGIN
DBMS_SQL.PARSE (c, 'SELECT employee_id, last_name ' ||
' FROM employee' , DBMS_SQL.NATIVE);
DBMS_SQL.DEFINE_COLUMN (c, 1, emprec.empno);
DBMS_SQL.DEFINE_COLUMN (c, 2, emprec.ename, 30);
fdbk:= DBMS_SQL.EXECUTE (c);
LOOP
EXIT WHEN DBMS_SQL.FETCH_ROWS (c) = 0;
DBMS_SQL.COLUMN_VALUE (c, 1, emprec.empno);
DBMS_SQL.COLUMN_VALUE (c, 2, emprec.ename);
employee_id := emprec.empno;
employee_nm := emprec.ename;
END LOOP;

/* Clean up the cursor */
DBMS_SQL.CLOSE_CURSOR (c);
END;
 
接受答案了.
 
后退
顶部