如何使用 DBI 连接在 Ruby 中运行 PL/SQL 语句
我想运行一个简单的 PL/SQL 来测试是否可以打印标准输出。
PL/SQL 块应输出:“总数为:157”
我运行以下 Ruby 脚本,但它没有打印任何内容。请您指教。
require 'dbi'
dbh = DBI.connect('DBI:ODBC:hr','hr','hr')
dbh.do("BEGIN DBMS_OUTPUT.ENABLE; END;")
db_read_str = <<-EOS
declare
c number;
begin
select count(*) into c
from exo_user where sys_logon like 'uk%';
DBMS_OUTPUT.PUT_LINE('The total number is: ' || c);
end;
EOS
rs = dbh.prepare(db_read_str)
rs.execute
dbh.select_all(db_read_str) do |row|
p row
end
rs.finish
看来走这条路会很困难。让我解释一下我需要什么,并请告诉我应该做什么。我需要操作一些数据来生成报告。我获得的数据可以调用 CpuReporting.getgridusage(300) 函数。该程序需要用 Ruby 编写。 另请参阅:从引用游标中获取所有记录套餐
I'd like to run a simple PL/SQL to test if it is possible to print the standard output.
The PL/SQL block should output: "The total number is: 157"
I run the following Ruby script and it didn't print anything. Would you please advise.
require 'dbi'
dbh = DBI.connect('DBI:ODBC:hr','hr','hr')
dbh.do("BEGIN DBMS_OUTPUT.ENABLE; END;")
db_read_str = <<-EOS
declare
c number;
begin
select count(*) into c
from exo_user where sys_logon like 'uk%';
DBMS_OUTPUT.PUT_LINE('The total number is: ' || c);
end;
EOS
rs = dbh.prepare(db_read_str)
rs.execute
dbh.select_all(db_read_str) do |row|
p row
end
rs.finish
Looks like going on this route can be difficult. Let me explain what I need and please advise what should I do. I need to manipulate some data to produce a report. The data I have got can be calling a CpuReporting.getgridusage(300) function. The program needs to be written in Ruby.
also see: Get all records from a Ref Cursor in a Package
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论