ORACLE动态SQL执行问题(100分)

  • 主题发起人 主题发起人 li2
  • 开始时间 开始时间
L

li2

Unregistered / Unconfirmed
GUEST, unregistred user!
有过程如下:
procedure exec_sql(p_sql in varchar2) as
v_Cursor BINARY_INTEGER;
v_ReturnCode BINARY_INTEGER;
begin
v_Cursor := DBMS_SQL.OPEN_CURSOR;
-- Parse and execute the statement.
DBMS_SQL.PARSE(v_Cursor, p_sql, DBMS_SQL.NATIVE);
v_ReturnCode := DBMS_SQL.EXECUTE(v_Cursor);
-- Close the cursor.
DBMS_SQL.CLOSE_CURSOR(v_Cursor);
end;
调用时用
SQL> begin
2 exec_sql('create table abcd as select sysdate tmp from dual');
3 end;
4 /
begin
*
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "SYS.DBMS_SYS_SQL", line 491
ORA-06512: at "SYS.DBMS_SQL", line 32
ORA-06512: at "LI2.EXEC_SQL", line 7
ORA-06512: at line 2

但如改为执行 DROP TABLE 就正常,请问是什么原因.
过程创建,执行的用户有DBA权限,
 
那你直接在sqlplus执行 create table abcd as select sysdate tmp from dual 正常吗
 
DBA的权限做这事肯定正常,是不是动态SQL中就不能创建对象,我用的数据库是 805
 
没有的事
 
你肯定运行正常?
 
是的,
SQL> create table abcd as select sysdate tmp from dual;

Table created.
 
我也想不通,SQL NAVIGATOR 的运行情况如下:
***** SCRIPT START : Session:local-LI2:1 31-三月-02 11:23:39 pm ****

SCRIPT File: UnNamed1

Starting from line number : 1


Processing ...
DECLARE
P_SQL VARCHAR2(2000);
BEGIN
-- Assign IN and IN/OUT parameters
P_SQL := 'create table abcd as select sysdate tmp from dual';

-- Now call the stored program
LI2.EXEC_SQL(P_SQL);

-- Output the results

COMMIT; -- Auto-Commit option in Setup menu is ON
END;


DECLARE
*
ORA-01031: insufficient privileges ORA-06512: at "SYS.DBMS_SYS_SQL", line 491 ORA-06512: at "SYS.DBMS_SQL", line 32 ORA-06512: at "LI2.EXEC_SQL", line 7 ORA-06512: at line 8
***** SCRIPT stopped due to error *****

DECLARE
P_SQL VARCHAR2(2000);
BEGIN
-- Assign IN and IN/OUT parameters

P_SQL := 'drop table abcd';

-- Now call the stored program
LI2.EXEC_SQL(P_SQL);

-- Output the results

COMMIT; -- Auto-Commit option in Setup menu is ON
END;

Statement processed

***** SCRIPT END : 31-三月-02 11:28:14 pm ****
 
明天我去单位试试,这里试不了
 
vreate database link 就试过动态的
create table倒没试过,明天回去单位看看
 
805建表只能用dbms_sql包
 
咳,慕容贤弟,你老眼昏花了,人家不就是用的dbms_sql包嘛
 
知道为什么了
先运行 GRANT CREATE TABLE TO LI2 就可以了,各位能告诉我为什么吗?
LI2 用户有DBA权限
 
哦,天,我今天上班闲了一天,很无聊,找不到什么事情做,居然忘了试了:)
 
虽然没帮上忙,但还是要谢谢各位的热心解答
 
后退
顶部