【发布时间】:2016-04-28 07:54:58
【问题描述】:
我正在尝试通过一个sql文件在sqlplus中执行以下代码:
connect sys/knl_test7 as sysdba
grant sysdba to user1 identified by user1;
grant sysoper to user2 identified by user2;
variable c number;
begin
:c := dbms_sql.open_cursor;
for i in 3 .. 98 loop
dbms_sql.parse(:c, 'grant sysdba to user'||to_char(i)||' identified by user'||to_char(i), dbms_sql.v7);
dbms_lock.sleep(5);
end loop;
dbms_sql.close_cursor(:c);
tkzpwfsync.check_condition('(select count(username) from v$pwfile_users where username like ''USER%'')=98');
end;
/
但是在运行脚本后,我收到以下错误:
begin
*
ERROR at line 1:
ORA-00905 missing keyword
check_condition 过程如下,它主要验证提供的条件是否为真。
create or replace package tkzpwfsync is
procedure check_condition(condition varchar2);
end;
/
show errors
create or replace package body tkzpwfsync is
procedure check_condition(condition varchar2) is
x integer;
c number;
begin
x := 0;
c := dbms_sql.open_cursor;
dbms_sql.parse(c,'select 1 into x from dual where '||condition,dbms_sql.v7);
if (x!=1) then raise_application_error(-20001,'Condition '||condition||' is not met.'); end if;
dbms_sql.close_cursor(c);
end;
end;
/
show errors
create public synonym tkzpwfsync for tkzpwfsync;
grant execute on tkzpwfsync to public;
【问题讨论】:
-
我可能弄错了 - 但你不是在连接字符串 ([user]/[pwd]@[target DB]) 和 c 变量的“DECLARE”中缺少目标数据库吗?应该是“DECLARE c number”,不是吗?
-
正是必须合并的内容
-
tkzpwfsync.wait在做什么?您传递的字符串不是有效的语句,那么它是否将其用作其他动态 SQL 中的条件?不过,错误消息暗示了一些更基本的东西。 (如果您通过 ORACLE_SID 而不是通过 SQL*Net 连接到本地 DB,则不需要提供 @DBNAME;并且如果 PL/SQL 变量会执行异常,则绑定变量很好;并且解析有效,但立即执行更常见)。 -
如果我排除了
wait电话,您所拥有的一切正常。所以我仍然认为这将是wait调用产生错误;你显示了整个堆栈跟踪,还是有另一行说ORA-06512: at line 8? -
@Rene 连接命令没问题。也不需要声明。
标签: database oracle plsql sqlplus