简体   繁体   中英

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:

ActionView::Template::Error (undefined method `parse' for
#<Mysql2::Client:0x00000008ef4310>):

in the following line:

   cursor = connection.parse(sql)

This is my database.yml file

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:

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

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.

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

My stored procedure works fine if I hardcode "VAULT" as follows:

    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.

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

It was fixed by updating the sql from:

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

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:

 sql =

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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