PLS-00201: 运行 oracle 存储过程通过 rails 时的标识符

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

我不确定为什么抛出 mysql 解析错误,当特定代码集仅尝试连接到 oracle 数据库和 运行ning oracle 存储过程时。

编辑:我能够通过从以下行中删除“=”来修复解析错误:

establish_connection = "db3_#{Rails.env}"

但是,我收到以下错误:

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):

如果我硬编码 "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: illegal variable name/number

它已通过更新 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: line 1, column 53: PLS-00201: identifier 'VAULT' must be declared ORA-06550: line 1, column 7: PL/SQL: Statement ignored):

出于某种原因,它没有将其解释为字符串。

所以我不得不为 #{vault_cd} 添加单引号以使其工作:

 sql =

      "BEGIN #{Pkgltd::PKG_LTD}.GET_PAN('
        8042049440330819','32', '#{vault_cd}', '0',vpan, errormsg, errorcode, sperrormsg);