Skip to content

Commit c349a58

Browse files
committed
added select examples
1 parent 4960d5f commit c349a58

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Code Sample from the tutorial at https://learncodeshare.net/2016/09/09/select-crud-using-ruby-oci8/
2+
# section titled "Select specific rows"
3+
# Using the base template, the example code executes a simple query using named bind variables,
4+
# uses fetchall to retrieve the data and displays the results.
5+
6+
require 'oci8'
7+
connectString = ENV['DB_CONNECT'] # The environment variable for the connect string: DB_CONNECT=user/password@database
8+
con = OCI8.new(connectString)
9+
10+
# Query for Kim
11+
person_name = 'Kim'
12+
statement = 'select id, name, age, notes from lcs_people where name=:name'
13+
cursor = con.parse(statement)
14+
cursor.bind_param('name', person_name)
15+
cursor.exec
16+
cursor.fetch do |row|
17+
printf "Id: %d, Name: %s, Age: %d, Notes: %s\n", row[0], row[1], row[2], row[3]
18+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Code Sample from the tutorial at https://learncodeshare.net/2016/09/09/select-crud-using-ruby-oci8/
2+
# section titled "Extra Fun 1"
3+
# Using the base template, the example code executes a simple query, uses fetchall to retrieve the data
4+
# and displays the results.
5+
6+
require 'oci8'
7+
connectString = ENV['DB_CONNECT'] # The environment variable for the connect string: DB_CONNECT=user/password@database
8+
con = OCI8.new(connectString)
9+
10+
statement = 'select id, name, age, notes from lcs_people order by age'
11+
cursor = con.parse(statement)
12+
cursor.exec
13+
cursor.fetch do |row|
14+
printf "Id: %d, Name: %s, Age: %d, Notes: %s\n", row[0], row[1], row[2], row[3]
15+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Code Sample from the tutorial at https://learncodeshare.net/2016/09/09/select-crud-using-ruby-oci8/
2+
# section titled "Extra Fun 2"
3+
# Using the base template, the example code executes a simple query using named bind variables,
4+
# uses fetchall to retrieve the data and displays the results.
5+
6+
require 'oci8'
7+
connectString = ENV['DB_CONNECT'] # The environment variable for the connect string: DB_CONNECT=user/password@database
8+
con = OCI8.new(connectString)
9+
10+
statement = 'select id, name, age, notes from lcs_people where age > :age'
11+
cursor = con.parse(statement)
12+
cursor.bind_param('age', 30)
13+
cursor.exec
14+
cursor.fetch do |row|
15+
printf "Id: %d, Name: %s, Age: %d, Notes: %s\n", row[0], row[1], row[2], row[3]
16+
end

ruby/CRUD-examples/select/simple.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Code Sample from the tutorial at https://learncodeshare.net/2016/09/09/select-crud-using-ruby-oci8/
2+
# section titled "Simple query"
3+
# Using the base template, the example code executes a simple query, uses fetchall to retrieve the data
4+
# and displays the results.
5+
6+
require 'oci8'
7+
connectString = ENV['DB_CONNECT'] # The environment variable for the connect string: DB_CONNECT=user/password@database
8+
con = OCI8.new(connectString)
9+
10+
# Query all rows
11+
con = OCI8.new(connectString)
12+
statement = 'select id, name, age, notes from lcs_people'
13+
cursor = con.parse(statement)
14+
cursor.exec
15+
cursor.fetch do |row|
16+
print row
17+
end

ruby/CRUD-examples/select/template.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Code Sample from the tutorial at https://learncodeshare.net/2016/09/09/select-crud-using-ruby-oci8/
2+
# The following code is used as the base template for the other examples.
3+
4+
require 'oci8'
5+
connectString = ENV['DB_CONNECT'] # The environment variable for the connect string: DB_CONNECT=user/password@database
6+
con = OCI8.new(connectString)
7+
8+
# Your code here

0 commit comments

Comments
 (0)