[英]PLS-00201: identifier when running oracle stored procedure through rails
我正在運行以在Rails中運行oracle存儲過程,但出現以下錯誤:
ActionView::Template::Error (undefined method `parse' for
#<Mysql2::Client:0x00000008ef4310>):
在以下行中:
cursor = connection.parse(sql)
這是我的database.yml文件
development:
adapter: mysql2
database: db1
username: user1
password: *****
host: *****
port: 3306
db1_development:
adapter: mysql2
username: user2
password: ****
database: ****
host: *****
port: 3306
db2_development:
adapter: mysql2
database: user3
username: ******
password: ******
host: *****
port: 3309
db3_development:
adapter: oracle_enhanced
database: user3
username: *****
password: *****
這些是我的2個模型類:
module Sts
class StsLtd < Sts::Base
def number
errormsg = nil
errorcode = nil
sperrormsg = nil
vpan = nil
sql =
"BEGIN #{Pkgltd::PKG_LTD}.GET_PAN('
8042049440330819','32', 'TEST', '0',vpan, errormsg, errorcode, sperrormsg);
END;"
connection = self.connection.raw_connection
cursor = connection.parse(sql)
cursor.bind_param(:errormsg, nil, String, 1000)
cursor.bind_param(:errorcode, nil, String, 1000)
cursor.bind_param(:sperrormsg, nil, String, 1000
cursor.bind_param(:vpan, nil, String, 1000)
cursor.exec
vpan, errormsg, errorcode, sperrormsg, vpan = cursor[:vpan], cursor[:errormsg], cursor[:errorcode], cursor[:sperrormsg]
cursor.close
vpan
end
end
end
sts.rb:
module Sts
PKG_LTD ="PKG_LTD"
class Base < ActiveRecord::Base
self.abstract_class = true
establish_connection = "db3_#{Rails.env}"
end
end
當特定的代碼集僅嘗試連接到oracle數據庫並運行oracle存儲過程時,我不確定為什么會引發mysql parse錯誤。
編輯:我能夠通過刪除以下行中的'='來修復解析錯誤:
establish_connection = "db3_#{Rails.env}"
但是,我收到以下錯誤:
ActionView :: Template :: Error(ORA-06550:第1行,第53列:PLS-00201:標識符'VAULT'必須聲明為ORA-06550:第1行,第7列:PL / SQL:語句被忽略):
如果我對“ VAULT”進行硬編碼,則我的存儲過程可以正常工作,如下所示:
sql =
"BEGIN #{Pkgltd::PKG_LTD}.GET_PAN('
8042049440330819','32', 'VAULT', '0',vpan, errormsg, errorcode, sperrormsg);
但是,如果我將其作為函數參數傳遞並調用它,則會收到上述錯誤:
sql =
"BEGIN #{Pkgltd::PKG_LTD}.GET_PAN('
8042049440330819','32', #{vault_cd}, '0',vpan, errormsg, errorcode, sperrormsg);
好。 因此,在運行存儲過程時遇到了3個不同的錯誤。
第一個錯誤是:
ActionView::Template::Error (undefined method `parse' for
#<Mysql2::Client:0x00000008ef4310>):
通過更改以下代碼來解決此問題:
establish_connection = "db3_#{Rails.env}"
至
establish_connection "db3_#{Rails.env}"
第二個錯誤是:
OCIError:ORA-01036:非法的變量名稱/編號
通過從以下位置更新sql進行了修復:
sql =
"BEGIN #{Pkgltd::PKG_LTD}.GET_PAN('
8042049440330819','32', 'VAULT', '0',vpan, errormsg, errorcode, sperrormsg);
添加符號
sql =
"BEGIN #{Pkgltd::PKG_LTD}.GET_PAN('
8042049440330819','32', 'VAULT', '0',:vpan, :errormsg, :errorcode, sperrormsg);
最終錯誤是:
ActionView :: Template :: Error(ORA-06550:第1行,第53列:PLS-00201:標識符'VAULT'必須聲明為ORA-06550:第1行,第7列:PL / SQL:語句被忽略):
由於某種原因,它沒有將其解釋為字符串。
因此,即使是#{vault_cd},我也必須添加單引號以使其起作用:
sql =
"BEGIN #{Pkgltd::PKG_LTD}.GET_PAN('
8042049440330819','32', '#{vault_cd}', '0',vpan, errormsg, errorcode, sperrormsg);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.