Connecting to Oracle DB using Ruby

╄→гoц情女王★ 提交于 2019-12-03 01:32:29
peter

the third parameter needs to be the TNS hostname, if you use SQL plus it is also the third parameter in the connectstring, you can find it also in the tnsnames.ora file in the oracle maps

in SQLPlus : connect user/password@hostname;
in oci8 : conn = OCI8.new('SomeUser','SomePass',hostname)

Here a working sample, obfuscated the parameters of course

require 'oci8'
oci = OCI8.new('****','***','****.***')
oci.exec('select * from table') do |record|
  puts record.join(',')
end
durgaprasad vakacharla
require 'oci8'
oci = OCI8.new('system','prasad','127.0.0.1:1521')
oci.exec("CREATE TABLE states1 (
           id CHAR(2) PRIMARY KEY,
           name VARCHAR2(15) NOT NULL,
           capital VARCHAR2(25) NOT NULL)")
durgaprasad vakacharla
require 'oci8'
oci = OCI8.new('system','prasad','127.0.0.1:1521')
oci.exec("insert into states1  values(1,'prasad','visakhapatnam')")
oci.exec("commit")
oci.exec('select * from states1') do |record|
    puts record.join(',')
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!