2014-01-17 41 views
0

我想用ruby-oci8 gem執行存儲過程。 而我可以執行正常的查詢,但不是我的程序。用ruby-oci8執行程序

# irb -r oci8 
Warning: NLS_LANG is not set. fallback to US7ASCII. 
irb(main):001:0> conn = OCI8.new('AAA/[email protected]//10.112.68.14:1521/dptedp0') 
irb(main):002:0> conn.exec("SELECT * FROM mytable"){|r| puts r.join(", ")} 
1, user1, data1 
2, user2, data2 
irb(main):003:0> conn.exec("ALTER TRIGGER trigger_mytable_id ENABLE") 
=> 0 
irb(main):004:0> conn.exec("ALTER TRIGGER trigger_mytable_id DISABLE") 
=> 0 

直到這裏所有的工作正常,但是當我嘗試執行一個程序,它沒有工作。

irb(main):005:0> conn.exec("EXECUTE reset_seq('mytable_id_seq', 'mytable', 'id')") 
OCIError: ORA-00900: invalid SQL statement 
     from stmt.c:253:in oci8lib_191.so 
     from /opt/ruby/gems/ruby-oci8-2.1.2/lib/oci8/oci8.rb:474:in `exec' 
     from /opt/ruby/gems/ruby-oci8-2.1.2/lib/oci8/oci8.rb:282:in `exec_internal' 
     from /opt/ruby/gems/ruby-oci8-2.1.2/lib/oci8/oci8.rb:275:in `exec' 
     from (irb):9 
     from /usr/bin/irb:12:in `<main>' 

我的程序在sqldeveloper中運行良好。

execute reset_seq('lrf_id_seq', 'lrf', 'id') 
    anonymous block completed 

我沒有返回任何值。 有沒有可能用oci8 gem執行這樣的程序?

我使用: 紅寶石1.9.3p429 紅寶石OCI8(2.1.2)

回答

3

EXECUTE不是由紅寶石/ OCI8公認的 - 你應該換你的電話insided匿名PL/SQL塊來代替:

require 'oci8' 

conn = OCI8.new('AAA/[email protected]//10.112.68.14:1521/dptedp0') 
conn.exec("begin reset_seq('mytable_id_seq', 'mytable', 'id'); end;") 
+0

坦克你,它完美 – fabio

+2

僅供參考,EXECUTE是SQLPLUS命令。 Sqlplus將'EXECUTE xxxx'轉換爲'begin xxxx;結束;'並將轉換後的字符串發送到Oracle服務器。 –