25
Oracle Live SQL Quick Introduction to Oracle live SQL Johan Louwers – [email protected]

Capgemini oracle live-sql

Embed Size (px)

Citation preview

Oracle Live SQLQuick Introduction to Oracle live SQL

Johan Louwers – [email protected]

2Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

• xxx

Introduction

3Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

4Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

Home - Tab• The Home tab is the starting point for your Oracle Live SQL session after you login.

5Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

SQL Worksheet - TabProvides you the ability to write SQL statements and execute them against the Oracle Live SQL schema.

As an example you can see the execution of the select sysdate from dual statement in the example on the right.

6Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

SQL Session- TabProvides access to information of your current session and previous sessions. On the main tab you can see information of the most recent statements executed against your schema. Your Live SQL session provides temporary access to an Oracle Database schema. Your session also persists a record of each SQL statement run. To preserve your work save your session as a SQL script. You can also reset your session to return to fresh empty schema.

A number of sub-tabs are provided:•Previous sessions•Utilization•NLS•Preferences

7Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

SQL Session- TabPrevious Sessions:Previous Sessions are a logged collection of SQL statements that you have entered using this system in the past. Your lease on a database schema may have expired, however you can view these SQL statements, replay the SQL statements in your current session, or save an old session as a named SQL script.

8Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

SQL Session- TabUtilization:Your Live SQL usage is controlled by various limits. You can see your consumption of these limits using this page.

9Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

SQL Session- TabNLS:Each Live SQL page request is a new database session. To preserve NLS state between SQL statement execution over multiple page posts this application remembers your NLS settings and applies them to ensure each session has proper NLS.

10Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

SQL Session- TabPreferences:In essence the only preference you can currently set is the “maximum rows to query”

11Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

Schema TabSchema:A database schema is a logical container for data structures, called schema objects. Examples of schema objects are tables, stored procedures and indexes. This Live SQL application automatically creates a schema for your use. Your schema will be allocated to you for the duration of your Live SQL session.

12Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

Schema TabDefault Schema:By default you will have your own schema and a number of pre-populated schema’s which you can use as an example to run some code against. For example, the Human Resources (HR), Sales History (SH) and World Data (WORLD) schema are available from the right hand side menu.

13Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

Schema TabExample Schema:In the example on the right you can see the content of the sales history (SH) schema which is filled with a number of objects.

14Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

Schema TabExample Schema:When clicking on one of the tables (in this case the costs table) you will be able to see the definition of the table. Interesting to see is that also a number of syntax examples is given.

SQLProvides a number of SQL operations example

JAVAProvides an example of a select and a insert statement

PL/SQLProvides an example of a Package to perform basic Table Operations.

PerlProvides an example of perl code

15Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

select PROD_ID,TIME_ID,PROMO_ID,CHANNEL_ID,UNIT_COST,UNIT_PRICE from COSTS

select PROD_ID,TIME_ID,PROMO_ID,CHANNEL_ID,UNIT_COST,UNIT_PRICE from COSTS where

insert into COSTS ( PROD_ID,TIME_ID,PROMO_ID,CHANNEL_ID,UNIT_COST,UNIT_PRICE ) values ( :PROD_ID,:TIME_ID,:PROMO_ID,:CHANNEL_ID,:UNIT_COST,:UNIT_PRICE );

update COSTS set PROD_ID= :PROD_ID,TIME_ID= :TIME_ID,PROMO_ID= :PROMO_ID,CHANNEL_ID= :CHANNEL_ID,UNIT_COST= :UNIT_COST,UNIT_PRICE= :UNIT_PRICE where

delete from COSTS where

SQL Example(s)

16Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

Java select exampleimport java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;

public class TestSQL {

public void getEmps() throws SQLException{ DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); Connection conn = DriverManager.getConnection("", "myusername", "my password"); PreparedStatement statement = conn.prepareStatement("select PROD_ID,TIME_ID,PROMO_ID,CHANNEL_ID,UNIT_COST,UNIT_PRICE from COSTS where "); ResultSet resultSet = statement.executeQuery(); while(resultSet.next()){ System.out.println(resultSet.getObject(PROD_ID)); System.out.println(resultSet.getObject(TIME_ID)); System.out.println(resultSet.getObject(PROMO_ID)); System.out.println(resultSet.getObject(CHANNEL_ID)); System.out.println(resultSet.getObject(UNIT_COST)); System.out.println(resultSet.getObject(UNIT_PRICE)); } } }

17Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

Java Insert exampleimport java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;

public class TestSQL {

public void getEmps() throws SQLException{ DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); Connection conn = DriverManager.getConnection("", "myusername", "my password"); PreparedStatement statement = conn.prepareStatement("insert into COSTS " + " (PROD_ID,TIME_ID,PROMO_ID,CHANNEL_ID,UNIT_COST,UNIT_PRICE)" + " values " + " (:PROD_ID,:TIME_ID,:PROMO_ID,:CHANNEL_ID,:UNIT_COST,:UNIT_PRICE) "); statement.setObject(?, "VALUE FOR PROD_ID"); statement.setObject(?, "VALUE FOR TIME_ID"); statement.setObject(?, "VALUE FOR PROMO_ID"); statement.setObject(?, "VALUE FOR CHANNEL_ID"); statement.setObject(?, "VALUE FOR UNIT_COST"); statement.setObject(?, "VALUE FOR UNIT_PRICE"); statement.execute(); } }

18Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

PL/SQL examplecreate or replace package COSTS_METHODSasprocedure add_row ( p_PROD_ID in NUMBER default null ,p_TIME_ID in DATE default null ,p_PROMO_ID in NUMBER default null ,p_CHANNEL_ID in NUMBER default null ,p_UNIT_COST in NUMBER default null ,p_UNIT_PRICE in NUMBER default null );procedure update_row ( p_PROD_ID in NUMBER default null ,p_TIME_ID in DATE default null ,p_PROMO_ID in NUMBER default null ,p_CHANNEL_ID in NUMBER default null ,p_UNIT_COST in NUMBER default null ,p_UNIT_PRICE in NUMBER default null );

procedure delete_row ( );

end COSTS_METHODS;/

create or replace package body COSTS_METHODSasprocedure add_row ( p_PROD_ID in NUMBER default null ,p_TIME_ID in DATE default null ,p_PROMO_ID in NUMBER default null ,p_CHANNEL_ID in NUMBER default null ,p_UNIT_COST in NUMBER default null ,p_UNIT_PRICE in NUMBER default null )isbegininsert into COSTS ( PROD_ID, TIME_ID, PROMO_ID, CHANNEL_ID, UNIT_COST, UNIT_PRICE) values ( p_PROD_ID, p_TIME_ID, p_PROMO_ID, p_CHANNEL_ID, p_UNIT_COST, p_UNIT_PRICE);end add_row;

procedure update_row ( p_PROD_ID in NUMBER default null ,p_TIME_ID in DATE default null ,p_PROMO_ID in NUMBER default null ,p_CHANNEL_ID in NUMBER default null ,p_UNIT_COST in NUMBER default null ,p_UNIT_PRICE in NUMBER default null )isbegin update COSTS set PROD_ID=p_PROD_ID, TIME_ID=p_TIME_ID, PROMO_ID=p_PROMO_ID, CHANNEL_ID=p_CHANNEL_ID, UNIT_COST=p_UNIT_COST, UNIT_PRICE=p_UNIT_PRICE where ();end update_row;

procedure delete_row ( )isbegin delete COSTS where ;end delete_row;end COSTS_METHODS;/show errors

19Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

Perl exampleuse DBI;if (!($dbh = DBI->connect ("DBI:Oracle:XE","scott","tiger"))){ die ("Failed to connect to database: " . DBI->errstr);};$sql =qq("SELECT ". "FROM COSTS ". "WHERE ");if (!($sth = $dbh->prepare ($sql))){ die ("Failed to prepare statement: " . DBI->errstr);};

$sth->execute;my @row;while (@row = $sth->fetchrow_array) { # retrieve one row print join(", ", @row), "\n";}$sth->finish;$dbh->disconnect;use DBI;if (!($dbh = DBI->connect ("DBI:Oracle:XE","scott","tiger"))){

die ("Failed to connect to database: " . DBI->errstr);};$sql =qq("SELECT ". "FROM COSTS ". "WHERE ");if (!($sth = $dbh->prepare ($sql))){ die ("Failed to prepare statement: " . DBI->errstr);};

$sth->execute;my @row;while (@row = $sth->fetchrow_array) { # retrieve one row print join(", ", @row), "\n";}$sth->finish;$dbh->disconnect;

20Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

Schema TabCreating a object:When under your own schema you have the option to create objects within your own schema. As can be seen in the example on the right you have the four options:

•Create object• Create typical database objects using graphic

user interface.•SQL Worksheet

• Manually enter SQL CREATE command using the SQL worksheet.

•Upload Script• Upload a SQL script from your client

computer.•Using Community Code

• Create database objects using code developed by others.

21Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Capgemini – Oracle live SQL

Schema TabCreating a object:When using the create object you will have a guided GUI way of creating the following objects:

• Table• View• PL/SQL Procedure• PL/SQL Function• PL/SQL Package• Sequence• Type• Trigger• Index• Synonym

22Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Design TabUse this page to rapidly design a schema. Click the Add Table(s) button to add one or more tables. This design tool uses a SQL shorthand syntax to speed data model design. Once designed, you create a SQL Script which will be available under My Scripts that can be run to create the objects in your current schema or run within another database.

23Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

My Scripts TabUse this page to quickly get access to the scripts you have created. To save your "code" enter commands in the SQL Worksheet. Once you have a collection of work you wish to save click the Save Session button to save your SQL session history as a SQL Script. Once you save your work as a named SQL script you can annotate, share, edit and replay the scripts

24Copyright © Capgemini 2015. All Rights ReservedOracle Live SQL – Johan Louwers

Community Code TabUse this page to search for code that is created by and shared with the community. Examples can be found in this location.

The information contained in this presentation is proprietary.© 2014 Capgemini. All rights reserved.

www.capgemini.com

About CapgeminiWith almost 140,000 people in 40 countries, Capgemini is one of the world’s foremost providers of consulting, technology and outsourcing services. The Group reported 2013 global revenues of EUR 10.1 billion. Together with its clients, Capgemini creates and delivers business and technology solutions that fit their needs and drive the results they want. A deeply multicultural organization, Capgemini has developed its own way of working, the Collaborative Business ExperienceTM, and draws on Rightshore®, its worldwide delivery model.

Rightshore® is a trademark belonging to Capgemini