13 Copyright © 2004, Oracle. All rights reserved. Migrating SQL Statements.

Slides:



Advertisements
Similar presentations
Basic SQL Introduction Presented by: Madhuri Bhogadi.
Advertisements

Introduction To SQL Lynnwood Brown President System Managers LLC Copyright System Managers LLC 2003 all rights reserved.
Introduction to Structured Query Language (SQL)
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 8 Advanced SQL.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
Introduction to Structured Query Language (SQL)
2 Copyright © 2004, Oracle. All rights reserved. Creating Stored Functions.
Copyright  Oracle Corporation, All rights reserved. 4 Creating Functions.
Chapter 2 Basic SQL SELECT Statements
4 Copyright © 2004, Oracle. All rights reserved. Database Interfaces.
How to Hack a Database.  What is SQL?  Database Basics  SQL Insert Basics  SQL Select Basics  SQL Where Basics  SQL AND & OR Basics  SQL Update.
Functions Lesson 10. Skills Matrix Function A function is a piece of code or routine that accepts parameters and stored as an object in SQL Server. The.
Using SQL Queries to Insert, Update, Delete, and View Data Date Retrieval from a single table & Calculations © Abdou Illia MIS Spring 2015.
Chapter 2 Basic SQL SELECT Statements Oracle 10g: SQL.
SQL Training SQL Statements – Part 1. Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. Lesson Objectives Explain the role of SQL.
1 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Database Technical Session By: Prof. Adarsh Patel.
Module 1: Introduction to Transact-SQL
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
10 Copyright © 2009, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
Chapter 2: SQL – The Basics Objectives: 1.The SQL execution environment 2.SELECT statement 3.SQL Developer & SQL*Plus.
1 Copyright © 2004, Oracle. All rights reserved. Introduction.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Quick review of SQL And conversion to Oracle SQL.
11 Copyright © Oracle Corporation, All rights reserved. Creating Views.
Upgrading to SQL Server 2000 Kashef Mughal. Multiple Versions SQL Server 2000 supports multiple versions of SQL Server on the same machine It does that.
LECTURE 1 INTRODUCTION TO PL/SQL Tasneem Ghnaimat.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
Comparing SQL Server and Oracle Comparing Oracle and SQL Server Similarities Similar Schema Objects (tables, views) Similar Datatypes Referential Integrity.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
SQL. Originally developed by IBM Standardized in 80’s by ANSI and ISO Language to access relational database and English-like non-procedural Predominant.
1 Copyright © 2009, Oracle. All rights reserved. Controlling User Access.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
 CONACT UC:  Magnific training   
8 Copyright © 2005, Oracle. All rights reserved. Managing Schema Objects.
19 Copyright © 2004, Oracle. All rights reserved. Coding PL/SQL Triggers.
1 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
1 Copyright © 2009, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
12 Copyright © 2004, Oracle. All rights reserved. Application Migration: Overview.
7 Copyright © 2004, Oracle. All rights reserved. Managing Schema Objects.
1 Copyright © 2005, Oracle. All rights reserved. Oracle Database Administration: Overview.
1 Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Oracle & SQL Introduction
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
ATS Application Programming: Java Programming
Database Systems: Design, Implementation, and Management Tenth Edition
ORACLE SQL Developer & SQLPLUS Statements
Contents Preface I Introduction Lesson Objectives I-2
Chapter 8 Advanced SQL.
Database Systems: Design, Implementation, and Management Tenth Edition
Presentation transcript:

13 Copyright © 2004, Oracle. All rights reserved. Migrating SQL Statements

13-2 Copyright © 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Identify SQL similarities and incompatibilities between SQL Server and Oracle databases Convert SQL statements to run in an Oracle database

13-3 Copyright © 2004, Oracle. All rights reserved. What Is SQL? Structured Query Language (SQL) provides statements for a variety of tasks: Querying data Inserting, updating, and deleting rows in a table Creating, replacing, altering, and dropping objects Controlling access to the database and its objects

13-4 Copyright © 2004, Oracle. All rights reserved. Migrating SQL Statements Both SQL Server and Oracle databases: –Support ANSI SQL-92 standard –Provide extensions to SQL-92 standard Similar in function Different in syntax Convert SQL Server statements to Oracle- supported syntax wherever they are used: –Application code –Stored procedures –Triggers –Scripts

13-5 Copyright © 2004, Oracle. All rights reserved. Object Name Changes The way to reference a table or view in a SQL statement is different: SQL Server – database_name.owner_name.table_name Oracle database – user_schema.table_name Example accessing other schema: SQL ServerOracle SELECT * FROM oe.sa_dba.orders SELECT * FROM sa.orders

13-6 Copyright © 2004, Oracle. All rights reserved.

13-7 Copyright © 2004, Oracle. All rights reserved. Connecting to the Database With multiple databases in SQL Server, you use the following command to switch databases: With only one database in Oracle, you issue one of the following commands to switch schemas: SQL> Use hr SQL> CONNECT hr/hr; SQL> SET ROLE hr_clerk;

13-8 Copyright © 2004, Oracle. All rights reserved. Data Query and Manipulation In both databases, the following data query and manipulation statements have similar constructs, with some exceptions: SELECT INSERT UPDATE DELETE

13-9 Copyright © 2004, Oracle. All rights reserved. The SELECT Statement The Oracle SELECT statement is similar to the SQL Server SELECT statement. ClauseDescription SELECT Columns returned FROM Tables where data is retrieved WHERE Conditions to restrict rows returned GROUP BY Returns a single row of summary information for each group HAVING Conditions to restrict groups returned ORDER BY Sorts rows returned

13-10 Copyright © 2004, Oracle. All rights reserved.

13-11 Copyright © 2004, Oracle. All rights reserved. SELECT Statement: FROM Clause In SQL Server, the FROM clause is optional. In Oracle, the FROM clause is required. SQL> SELECT sysdate 2 FROM dual; SQL> SELECT getdate()

13-12 Copyright © 2004, Oracle. All rights reserved. SELECT Statement: SELECT INTO Clause In SQL Server, the SELECT INTO clause is used. For the Oracle database, rewrite the statement by using the INSERT INTO clause. SQL> INSERT INTO contacts 2 SELECT cust_first_name, cust_last_name 3 FROM customers; SQL> SELECT cust_first_name, cust_last_name 2 INTO contacts 3 FROM customers

13-13 Copyright © 2004, Oracle. All rights reserved. SELECT Statement: Column Alias In SQL Server, an example using a column alias: In Oracle, the column alias is placed after the column name: SQL> SELECT cust_ 2 FROM customers; SQL> SELECT = cust_ 2 FROM customers

13-14 Copyright © 2004, Oracle. All rights reserved. The INSERT Statement SQL> INSERT INTO regions 2 VALUES (202, ‘Southeast’); SQL> INSERT regions 2 VALUES (202, ‘Southeast’) In SQL Server, the INTO clause is optional. In Oracle, the INTO clause is required.

13-15 Copyright © 2004, Oracle. All rights reserved. The UPDATE Statement SQL Server example: Rewrite in Oracle: SQL> UPDATE inventories 2 SET quantity_on_hand = 0 3 WHERE product_id IN (SELECT product_id 4 FROM product_information 5 WHERE product_status = ‘planned’); SQL> UPDATE inventories 2 SET quantity_on_hand = 0 3 FROM inventories i, product_information p 4 WHERE i.product_id = p.product_id 5 and product_status=‘planned’

13-16 Copyright © 2004, Oracle. All rights reserved. The DELETE Statement SQL Server: Rewrite in Oracle: SQL> DELETE FROM inventories 2 FROM inventories i, product_information p 3 WHERE i.product_id = p.product_id 4 AND supplier_id = SQL> DELETE FROM inventories 2 WHERE product_id IN (SELECT product_id 3 FROM product_information 4 WHERE supplier_id = );

13-17 Copyright © 2004, Oracle. All rights reserved. Operators Examples of operator differences: SQL ServerOracle Value comparison WHERE qty !< 100WHERE qty >= 100 Null value comparison WHERE status = NULL WHERE status IS NULL String concatenation and literals SELECT fname + ‘ ‘ + lname AS name SELECT fname || ‘ ‘ || lname AS name

13-18 Copyright © 2004, Oracle. All rights reserved. Full Notes Page

13-19 Copyright © 2004, Oracle. All rights reserved. Built-In Functions Both SQL Server and Oracle have proprietary built-in functions: SQL ServerOracle Character char()chr() Null test isnull(qty, 0)nvl(qty,0)

13-20 Copyright © 2004, Oracle. All rights reserved. Data Type Conversion SQL Server uses the CONVERT function to convert data types. Replace with the appropriate equivalent Oracle function: SQL> SELECT TO_CHAR(sysdate) 2 FROM dual; SQL> SELECT CONVERT(char, GETDATE())

13-21 Copyright © 2004, Oracle. All rights reserved. SQL> SELECT customer_id, date_of_birth 2 FROM customers 3 WHERE cust_ = ‘ ’ NULL-Handling Semantics SQL Server interprets the empty string as a single blank space. The Oracle database interprets the empty string as a NULL value. Rewrite to use a single blank space and not the empty string. SQL> SELECT customer_id, date_of_birth 2 FROM customers 3 WHERE cust_ = ‘’

13-22 Copyright © 2004, Oracle. All rights reserved. Oracle-Reserved Words Many words are valid in SQL Server 2000 but are reserved words in Oracle Database 10g: Modify SQL statements to not use Oracle-reserved words. WordSQL ServerOracle ACCESS COMMENT DATE GROUP LEVEL

13-23 Copyright © 2004, Oracle. All rights reserved. Full Notes Page

13-24 Copyright © 2004, Oracle. All rights reserved. Migration Guidelines Guidelines for converting SQL statements: Modify SELECT, INSERT, UPDATE, and DELETE statements by using: –Qualified table or view names –Valid operators and built-in functions Apply changes to SQL statements wherever they are used. Test your application code to verify functionality. Tune queries for performance.

13-25 Copyright © 2004, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: Identify SQL similarities and incompatibilities between SQL Server and Oracle databases Convert SQL statements to run in an Oracle database

13-26 Copyright © 2004, Oracle. All rights reserved. Practice Overview: Migrating SQL Statements This practice covers the following topics: Rewriting SQL Server SQL statements to run in Oracle Database 10g Testing the modified statements in SQL*Plus