【发布时间】:2014-01-13 23:32:16
【问题描述】:
我正在尝试使用 jdbc 驱动程序连接到 oracle db,并且该部分工作正常。之后我想执行一些 pl/sql bolck,这就是我遇到的问题,这似乎是语法问题。有人可以帮我解决这个问题吗?我试图弄清楚,但不能。下面是代码sn-p。
userlist = ['John', 'Sam', 'Lucia']
$userlist.each do|usr|
puts "Working on #{usr}"
stmt = <<-EOF
DECLARE
CURSOR cur IS
SELECT sid, serial#
FROM v$session WHERE username = upper('#{usr}');
BEGIN
FOR rec IN cur
LOOP
EXECUTE IMMEDIATE 'ALTER USER #{usr} IDENTIFIED BY chng';
dbms_output.put_line('Killing sessions which belong to #{usr}...');
EXECUTE IMMEDIATE 'ALTER SYSTEM KILL SESSION '''||session_rec.sid||','||session_rec.serial#'''';
END LOOP;
END;
EOF
#in the initialize method I established the connection and it is working fine.
plsql_stmt = @conn.create_statement
plsql_stmt.execute_update(stmt)
end
错误信息:
Working on John
NativeException: java.sql.SQLException: ORA-06550: line 10, column 100:
PLS-00103: Encountered the symbol "'" when expecting one of the following:
. ( * @ % & = - + ; < / > at in is mod remainder not rem
return returning <an exponent (**)> <> or != or ~= >= <= <>
and or like like2 like4 likec between into using || bulk
member submultiset
The symbol "*" was substituted for "'" to continue.
谢谢。
【问题讨论】:
-
你试过在sqldeveloper中执行代码吗?
-
我会
puts stmt并检查它。错误消息表明您有一个放错位置的撇号。 -
我正在使用 putty 在 linux box 上执行代码。
-
@Shepmaster:感谢您打印查询的建议。我错过了'||'在“Alter system kill”查询结束时。更正为
EXECUTE IMMEDIATE 'ALTER SYSTEM KILL SESSION '''||session_rec.sid||','||session_rec.serial#||'''';
标签: oracle plsql jruby oracle-call-interface