class OCI8
def exec(sql, *bindvars, &block)
conn.logoff
conn.exec('CREATE TABLE test (col1 CHAR(6))') # => 0
conn = OCI8.new('scott', 'tiger')
example:
conn.logoff
puts num_rows.to_s + ' rows were updated.'
num_rows = conn.exec('UPDATE emp SET sal = sal * 1.1')
conn = OCI8.new('scott', 'tiger')
example:
It returns the number of processed rows.
== Other SQL statements
conn.exec(sql, *bindvars) { |*outvars| outvars }
FYI, the following code do same on ruby-oci8 1.0 and ruby-oci8 2.0.
conn.logoff
end
puts num # => 123
puts str # => '0123'
conn.exec("BEGIN :str := TO_CHAR(:num, 'FM0999'); END;", 'ABCD', 123) do |str, num|
conn = OCI8.new('scott', 'tiger')
executed.
If a block is given, the bind variables' values are passed to the block after
conn.logoff
# => 1
conn.exec("BEGIN :str := TO_CHAR(:num, 'FM0999'); END;", 'ABCD', 123)
conn = OCI8.new('scott', 'tiger')
example:
It returns the number of processed rows.
== PL/SQL block (ruby-oci8 2.0)
If a block is given, it is ignored.
same with that of bind variables.
which may modified by PL/SQL statement. The order of array is
123". This method returns the array of these bind variables,
is 4 and whose value is 'ABCD'" and "the number whose value is
and :num. These initial values are "the string whose width
Above example uses two bind variables which names are :str
conn.logoff
# => ["0123", 123]
conn.exec("BEGIN :str := TO_CHAR(:num, 'FM0999'); END;", 'ABCD', 123)
conn = OCI8.new('scott', 'tiger')
example:
It returns the array of bind variables' values.
== PL/SQL block (ruby-oci8 1.0)
conn.logoff
puts num_rows.to_s + ' rows were processed.'
end
puts r.join(',')
num_rows = conn.exec('SELECT * FROM emp') do |r|
conn = OCI8.new('scott', 'tiger')
example:
data is passed to the block as array. NULL value becomes nil in ruby.
It acts as iterator and returns the processed row counts. Fetched
== select statements with a block
conn.logoff
cursor.close
end
puts r.join(',')
while r = cursor.fetch()
cursor = conn.exec('SELECT * FROM emp')
conn = OCI8.new('scott', 'tiger')
example:
It returns the instance of OCI8::Cursor.
== select statements without block
before execution.
When bindvars are specified, they are bound as bind variables
create, alter and drop; and PL/SQL.
the type of sql statement: select; insert, update and delete;
Executes the sql statement. The type of return value depends on
def exec(sql, *bindvars, &block) @last_error = nil exec_internal(sql, *bindvars, &block) end