Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread
Message: 97149
BY: Eric Peterson (ericdp)
DATE: 2011-11-14 16:10
SUBJECT: read output from anonymous pl/sql block

 

Is there any way to capture the output of an anonymous PL/SQL block that send it's output through DBMS_OUTPUT.put_line?

thanks
eric




> cat db.rb
#!/usr/bin/env ruby19 -KU -w
# encoding: UTF-8
require 'oci8'

dbh = OCI8.new( 'scott', 'tiger', 'dev' )
# puts dbh.class # OCI8

sql_smnt = <<-EOT
DECLARE
l_now VARCHAR2(20 CHAR) := TO_CHAR( SYSDATE, 'DD Mon YYYY HH24:MI:SS' );
BEGIN
DBMS_OUTPUT.put_line( 'This is a test. ' || l_now );
DBMS_OUTPUT.put_line( 'This is a another test. ' || l_now );
END;
EOT

puts '***> Before'
indx = 1
num_rows = dbh.exec( sql_smnt ) do |r|
# puts r.class # NilClass
puts "#{indx} : [#{r}]"
indx += 1
end
puts num_rows.to_s + ' rows read.'
puts '***> After'

dbh.logoff
exit 0





> ./db.rb
/usr/local/lib/ruby/site_ruby/1.9.1/oci8/object.rb:374: warning: assigned but unused variable - args
***> Before
1 : []
2 rows read.
***> After



Thread View

Thread Author Date
read output from anonymous pl/sql blockEric Peterson2011-11-14 16:10
      RE: read output from anonymous pl/sql blockRaimonds Simanovskis2011-11-14 20:31
            RE: read output from anonymous pl/sql blockEric Peterson2011-11-14 22:29
      RE: read output from anonymous pl/sql blockBeethoven Cheng2012-07-11 18:46

Post a followup to this message