read_update jruby中的pl / sql失败

时间:2014-01-13 23:32:17

标签: oracle plsql jruby oci

我正在尝试使用jdbc驱动程序连接到oracle db,该部分工作正常。之后我想执行一些pl / sql bolck,这就是我遇到问题的地方,这似乎是语法上的。有人可以帮我解决这个问题吗?我试图找出但不能。以下是代码段。

   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.

谢谢。

2 个答案:

答案 0 :(得分:0)

将重大错误的plsql重构为plsql过程并使用https://github.com/rsim/ruby-plsql从ruby中调用它

答案 1 :(得分:0)

该错误消息表明您有SQL语法错误,特别是围绕撇号。我会puts stmt并检查它。