繁体   English   中英

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM