[英]PLS-00201: identifier when running oracle stored procedure through rails
I am running to run an oracle stored procedure in rails, but I am getting the following error: 我正在运行以在Rails中运行oracle存储过程,但出现以下错误:
ActionView::Template::Error (undefined method `parse' for
#<Mysql2::Client:0x00000008ef4310>):
in the following line: 在以下行中:
cursor = connection.parse(sql)
This is my database.yml file 这是我的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: *****
these are my 2 model classes: 这些是我的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: sts.rb:
module Sts
PKG_LTD ="PKG_LTD"
class Base < ActiveRecord::Base
self.abstract_class = true
establish_connection = "db3_#{Rails.env}"
end
end
I am not sure why it is throwing mysql parse error, when the specific set of code is only trying to connect to the oracle database and running the oracle stored procedure. 当特定的代码集仅尝试连接到oracle数据库并运行oracle存储过程时,我不确定为什么会引发mysql parse错误。
EDIT: I was able to fix the parse error by removing the '=' from the following line: 编辑:我能够通过删除以下行中的'='来修复解析错误:
establish_connection = "db3_#{Rails.env}"
However, I am getting the following error: 但是,我收到以下错误:
ActionView::Template::Error (ORA-06550: line 1, column 53: PLS-00201: identifier 'VAULT' must be declared ORA-06550: line 1, column 7: PL/SQL: Statement ignored):
ActionView :: Template :: Error(ORA-06550:第1行,第53列:PLS-00201:标识符'VAULT'必须声明为ORA-06550:第1行,第7列:PL / SQL:语句被忽略):
My stored procedure works fine if I hardcode "VAULT" as follows: 如果我对“ VAULT”进行硬编码,则我的存储过程可以正常工作,如下所示:
sql =
"BEGIN #{Pkgltd::PKG_LTD}.GET_PAN('
8042049440330819','32', 'VAULT', '0',vpan, errormsg, errorcode, sperrormsg);
But if I pass it as a function argument and call it, i get the above error: 但是,如果我将其作为函数参数传递并调用它,则会收到上述错误:
sql =
"BEGIN #{Pkgltd::PKG_LTD}.GET_PAN('
8042049440330819','32', #{vault_cd}, '0',vpan, errormsg, errorcode, sperrormsg);
OK. 好。 So I ran into 3 different errors while running the stored procedure.
因此,在运行存储过程时遇到了3个不同的错误。
The first error was: 第一个错误是:
ActionView::Template::Error (undefined method `parse' for
#<Mysql2::Client:0x00000008ef4310>):
It was fixed by changing the code from: 通过更改以下代码来解决此问题:
establish_connection = "db3_#{Rails.env}"
to 至
establish_connection "db3_#{Rails.env}"
The second error was: 第二个错误是:
OCIError: ORA-01036: illegal variable name/number
OCIError:ORA-01036:非法的变量名称/编号
It was fixed by updating the sql from: 通过从以下位置更新sql进行了修复:
sql =
"BEGIN #{Pkgltd::PKG_LTD}.GET_PAN('
8042049440330819','32', 'VAULT', '0',vpan, errormsg, errorcode, sperrormsg);
to add symbols 添加符号
sql =
"BEGIN #{Pkgltd::PKG_LTD}.GET_PAN('
8042049440330819','32', 'VAULT', '0',:vpan, :errormsg, :errorcode, sperrormsg);
The final error was: 最终错误是:
ActionView::Template::Error (ORA-06550: line 1, column 53: PLS-00201: identifier 'VAULT' must be declared ORA-06550: line 1, column 7: PL/SQL: Statement ignored):
ActionView :: Template :: Error(ORA-06550:第1行,第53列:PLS-00201:标识符'VAULT'必须声明为ORA-06550:第1行,第7列:PL / SQL:语句被忽略):
For some reason it was not interpreting this as a string. 由于某种原因,它没有将其解释为字符串。
So I had to add single quotes even for #{vault_cd} to make it work: 因此,即使是#{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.