我正在运行在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
我不确定为什么它会抛出mysql解析错误,当特定的代码集只是试图连接到oracle数据库并运行oracle存储过程时。
编辑:我能够通过删除&#39; =&#39;来修复解析错误。从以下一行:
establish_connection = "db3_#{Rails.env}"
但是,我收到以下错误:
ActionView :: Template :: Error(ORA-06550:第1行,第53列:PLS-00201: 标识符&#39; VAULT&#39;必须声明ORA-06550:第1行第7列: PL / SQL:忽略语句):
如果我硬编码&#34; VAULT&#34;我的存储过程正常。如下:
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);
答案 0 :(得分:0)
行。所以我在运行存储过程时遇到了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: 标识符&#39; VAULT&#39;必须声明ORA-06550:第1行第7列: PL / SQL:忽略语句):
由于某种原因,它并没有将其解释为字符串。
因此我必须为#{vault_cd}添加单引号才能使其正常工作:
sql =
"BEGIN #{Pkgltd::PKG_LTD}.GET_PAN('
8042049440330819','32', '#{vault_cd}', '0',vpan, errormsg, errorcode, sperrormsg);