SlideShare a Scribd company logo
Beginning SQL: Differences Between SQL Server and Oracle Les Kopari Independent Consultant A Quick Intro for SQL Server Users
Introduction I f you're new to SQL or just new to Oracle SQL, perhaps coming from a Microsoft SQL Server environment, it may seem like the two versions should be very similar, and they are, to a certain degree, but they are also very different in some important and basic ways .
Agenda I. Quick Intro for SQL Server Users II. Some Detail: Joins, Subqueries, Deletes III. Certain Conceptual Differences IV. Powerful New Features V. Summary & References
Don’t Use Databases SQL  Server use mydatabase Oracle connect mydatabase/mypassword
Use Dual SQL  Server Oracle select getdate(); select sysdate from dual;
Select Into SQL  Server Oracle select getdate() mycolumn into mytable; insert into mytable (mycolumn) values(sysdate);
Inserts SQL  Server Oracle Insert mytable values(‘more text’); Insert into mytable values(‘more text’);
Updates SQL  Server update mytable set mycolumn=myothertable.mycolumn from mytable,myothertable where mytable.mycolumn like 'MY%' and myothertable.myothercolumn='some text';
Updates Oracle update mytable set mycolumn= (select a.mycolumn from myothertable a where myothertable.myothercolumn='some text'; ) where mytable.mycolumn like 'MY%';
Deletes SQL  Server delete mytable where mycolumn like 'some%'; Oracle delete from mytable  where mycolumn like 'some%';
Software isql osql: for queries developed in SQL Analyzer sqlplus SQL  Server Oracle
II. A Little More Detail Outer Join Sub-Queries in Place of Columns Deletes With a Second From Clause
Outer Join SQL Server select d.deptname, e.ename from dept d, emp e where d.empno *= e.enum; Oracle select d.deptname,e.ename from dept d, emp e where d.empno = e.enum (+);
SubQueries in Place of Columns SQL Server select distinct year, q1 = (select Amount amt FROM sales where Quarter=1 AND year = s.year), q2 = (SELECT Amount amt FROM sales where Quarter=2 AND year = s.year), q3 = (SELECT Amount amt FROM sales where Quarter=3 AND year = s.year), q4 = (SELECT Amount amt FROM sales where Quarter=4 AND year = s.year) from sales s;
SubQueries in Place of Columns Oracle SELECT year, DECODE( quarter, 1, amount, 0 ) q1, DECODE( quarter, 2, amount, 0 ) q2, DECODE( quarter, 3, amount, 0 ) q3, DECODE( quarter, 4, amount, 0 ) q4 FROM sales s;
Delete with Second From Clause SQL Server delete from products from products, product_deletes where products.a = product_deletes.a and products.b = product_deletes.b and product_deletes.c = 'd';
Delete with Second From Clause Oracle delete from products where ( a, b ) in ( select a, b from product_deletes where c = 'd' );
III. More Depth The Connect Concept Other Conceptual Differences Data Type Differences Column Aliases Sub-Queries
The Connect Concept SQL Server Multiple databases Oracle Single Database Multiple tablespaces, schemas, users
Other Conceptual Differences SQL Server Database owner, DBO Group/Role Non-unique index T-SQL stored procedure { Trigger Compex rule Column identity property Oracle Schema Role Index PL/SQL procedure PL/SQL function BEFORE trigger After trigger Sequence
Only in Oracle Clusters Packages Triggers for each row Synonyms Snapshots
Data Type Differences SQL Server Oracle INTEGER  NUMBER(10) SMALLINT  NUMBER(6) TINYINT  NUMBER(3) REAL FLOAT FLOAT FLOAT BIT NUMBER(1) VARCHAR(n) VARCHAR2(n) TEXT CLOB IMAGE BLOB BINARY(n) RAW(n) or BLOB
Data Type Differences SQL Server Oracle VARBINARY RAW(n) or BLOB DATETIME DATE SMALL-DATETIME DATE MONEY NUMBER(19,4) NCHAR(n) CHAR(n*2) NVARCHAR(n) VARCHAR(n*2) SMALLMONEY NUMBER(10,4) TIMESTAMP NUMBER SYSNAME     VARCHAR2(30),  VARCHAR2(128)
Time SQL Server Datetime: 1/300th second Oracle Date: 1 second Timestamp: 1/100 millionth second
Column Aliases SQL Server select a=deptid, b=deptname,c=empno  from dept; Oracle select deptid a, deptname b, empno c from dept;
Sub-queries, again SQL Server SELECT ename, deptname FROM emp, dept WHERE emp.enum = 10 AND(SELECT security_code FROM employee_security WHERE empno = emp.enum) = (SELECT security_code FROM security_master WHERE sec_level = dept.sec_level);
Sub-queries, again Oracle SELECT empname, deptname FROM emp, dept WHERE emp.empno = 10 AND EXISTS (SELECT security_code FROM employee_security es WHERE es.empno = emp.empno AND es.security_code = (SELECT security_code FROM security_master WHERE sec_level =   dept.sec_level));
Powerful New Features Regular Expressions: Operators & Functions Operator: REGEXP_LIKE Functions: REGEXP_INSTR REGEXP_SUBSTR REGEXP_REPLACE
Regular Expressions Select zip from zipcode where regexp_like (zip, ‘[^[:digit:]]’);
Regular Expressions SELECT REGEXP_INSTR('Joe Smith,  10045 Berry Lane, San Joseph, CA 91234-1234', ' [[:digit:]]{5}(-[[:digit:]]{4})?$') AS starts_at FROM dual
Summary This discussion has been an attempt at a light and lively introduction to the Oracle database world for those familiar with the Microsoft SQL Server database products.  Much more in-depth examples are available in the references shown that follow, from which many of the examples were drawn and for which we can thank the authors involved. Welcome Aboard!
References Oracle Migration Workbench Reference Guide for SQL Server and Sybase Adaptive Server Migrations, Release 9.2.0 for Microsoft Windows 98/2000/NT and Microsoft Windows XP, Part Number B10254-01 Oracle Technology Network, OTN: http://otn.oracle.com/software/index.html Writing Better SQL Using Regular Expressions, By Alice Rischert http://otn.oracle.com/oramag/webcolumns/2003/techarticles/rischert_regexp_pt1.html

More Related Content

PPT
plsql Lec11
PPT
Les23[1]Handling Exceptions
PPT
plsql Les09
PPTX
Oracle views
PPT
Les19[1]Writing Control Structures
PPT
Les02[1]Restricting and Sorting Data
PPT
Les22[1]Advanced Explicit Cursor Concepts
PPT
Les08[1] Producing Readable Output with SQL*Plus
plsql Lec11
Les23[1]Handling Exceptions
plsql Les09
Oracle views
Les19[1]Writing Control Structures
Les02[1]Restricting and Sorting Data
Les22[1]Advanced Explicit Cursor Concepts
Les08[1] Producing Readable Output with SQL*Plus

What's hot (19)

PPT
plsql Les08
PPTX
PL-SQL DIFFERENT PROGRAMS
PPT
PHP tips by a MYSQL DBA
RTF
Trigger and cursor program using sql
PPT
02 Writing Executable Statments
PPT
Les06[1]Subqueries
PPT
plsql les06
PPT
Les07[1]Multiple-Column Subqueries
PPT
Oracle PL/SQL Bulk binds
PPT
07 Using Oracle-Supported Package in Application Development
PPT
Les01[1]Writing Basic SQL Statements
PPT
10 Creating Triggers
PPT
Single row functions
PPT
PPT
plsql les10
PPTX
PL/SQL User-Defined Functions in the Read World
PDF
TSQL Coding Guidelines
plsql Les08
PL-SQL DIFFERENT PROGRAMS
PHP tips by a MYSQL DBA
Trigger and cursor program using sql
02 Writing Executable Statments
Les06[1]Subqueries
plsql les06
Les07[1]Multiple-Column Subqueries
Oracle PL/SQL Bulk binds
07 Using Oracle-Supported Package in Application Development
Les01[1]Writing Basic SQL Statements
10 Creating Triggers
Single row functions
plsql les10
PL/SQL User-Defined Functions in the Read World
TSQL Coding Guidelines
Ad

Viewers also liked (16)

PPTX
Sql intro
PPT
Active Server Page(ASP)
PPTX
New HTML5/CSS3 techniques
PPT
PPTX
Introduction to HTML5 & CSS3
PDF
Bootstrap 3 - Sleek, intuitive, and powerful mobile first front-end framework...
PDF
Bootstrap 3 Basic - Bangkok WordPress Meetup
PPTX
Bootstrap ppt
PPT
cascading style sheet ppt
ODP
PHP Web Programming
PDF
HTML5 for PHP Developers - IPC
PDF
Introduction to PHP
PPT
PDF
Introduction to Bootstrap
PDF
Html / CSS Presentation
Sql intro
Active Server Page(ASP)
New HTML5/CSS3 techniques
Introduction to HTML5 & CSS3
Bootstrap 3 - Sleek, intuitive, and powerful mobile first front-end framework...
Bootstrap 3 Basic - Bangkok WordPress Meetup
Bootstrap ppt
cascading style sheet ppt
PHP Web Programming
HTML5 for PHP Developers - IPC
Introduction to PHP
Introduction to Bootstrap
Html / CSS Presentation
Ad

Similar to Beg sql (20)

PPT
Introduction to Threading in .Net
PPTX
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
PPTX
Oracle Database 12c - New Features for Developers and DBAs
PPTX
Oracle Database 12c - New Features for Developers and DBAs
PPTX
PPT
Oracle training-institutes-in-hyderabad
PPTX
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
PPTX
Beginers guide for oracle sql
DOC
Oracle notes
PDF
SQL Macros - Game Changing Feature for SQL Developers?
PDF
Ruby on Rails Oracle adaptera izstrāde
PPT
01 basic orders
PPTX
Oracle Database 12c New Features for Developers and DBAs - OTN TOUR LA 2015
PPTX
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
PPTX
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
PDF
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
PPTX
Web Cloud Computing SQL Server - Ferrara University
PDF
Avoiding cursors with sql server 2005 tech republic
PDF
Oracle SQL Basics
PDF
SQL Performance Tuning and New Features in Oracle 19c
Introduction to Threading in .Net
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
Oracle training-institutes-in-hyderabad
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
Beginers guide for oracle sql
Oracle notes
SQL Macros - Game Changing Feature for SQL Developers?
Ruby on Rails Oracle adaptera izstrāde
01 basic orders
Oracle Database 12c New Features for Developers and DBAs - OTN TOUR LA 2015
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
Web Cloud Computing SQL Server - Ferrara University
Avoiding cursors with sql server 2005 tech republic
Oracle SQL Basics
SQL Performance Tuning and New Features in Oracle 19c

Recently uploaded (20)

PPTX
master seminar digital applications in india
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Cell Types and Its function , kingdom of life
PDF
Yogi Goddess Pres Conference Studio Updates
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Lesson notes of climatology university.
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Trump Administration's workforce development strategy
PDF
Computing-Curriculum for Schools in Ghana
master seminar digital applications in india
2.FourierTransform-ShortQuestionswithAnswers.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Cell Types and Its function , kingdom of life
Yogi Goddess Pres Conference Studio Updates
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Orientation - ARALprogram of Deped to the Parents.pptx
Anesthesia in Laparoscopic Surgery in India
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
O7-L3 Supply Chain Operations - ICLT Program
Lesson notes of climatology university.
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Supply Chain Operations Speaking Notes -ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Trump Administration's workforce development strategy
Computing-Curriculum for Schools in Ghana

Beg sql

  • 1. Beginning SQL: Differences Between SQL Server and Oracle Les Kopari Independent Consultant A Quick Intro for SQL Server Users
  • 2. Introduction I f you're new to SQL or just new to Oracle SQL, perhaps coming from a Microsoft SQL Server environment, it may seem like the two versions should be very similar, and they are, to a certain degree, but they are also very different in some important and basic ways .
  • 3. Agenda I. Quick Intro for SQL Server Users II. Some Detail: Joins, Subqueries, Deletes III. Certain Conceptual Differences IV. Powerful New Features V. Summary & References
  • 4. Don’t Use Databases SQL Server use mydatabase Oracle connect mydatabase/mypassword
  • 5. Use Dual SQL Server Oracle select getdate(); select sysdate from dual;
  • 6. Select Into SQL Server Oracle select getdate() mycolumn into mytable; insert into mytable (mycolumn) values(sysdate);
  • 7. Inserts SQL Server Oracle Insert mytable values(‘more text’); Insert into mytable values(‘more text’);
  • 8. Updates SQL Server update mytable set mycolumn=myothertable.mycolumn from mytable,myothertable where mytable.mycolumn like 'MY%' and myothertable.myothercolumn='some text';
  • 9. Updates Oracle update mytable set mycolumn= (select a.mycolumn from myothertable a where myothertable.myothercolumn='some text'; ) where mytable.mycolumn like 'MY%';
  • 10. Deletes SQL Server delete mytable where mycolumn like 'some%'; Oracle delete from mytable where mycolumn like 'some%';
  • 11. Software isql osql: for queries developed in SQL Analyzer sqlplus SQL Server Oracle
  • 12. II. A Little More Detail Outer Join Sub-Queries in Place of Columns Deletes With a Second From Clause
  • 13. Outer Join SQL Server select d.deptname, e.ename from dept d, emp e where d.empno *= e.enum; Oracle select d.deptname,e.ename from dept d, emp e where d.empno = e.enum (+);
  • 14. SubQueries in Place of Columns SQL Server select distinct year, q1 = (select Amount amt FROM sales where Quarter=1 AND year = s.year), q2 = (SELECT Amount amt FROM sales where Quarter=2 AND year = s.year), q3 = (SELECT Amount amt FROM sales where Quarter=3 AND year = s.year), q4 = (SELECT Amount amt FROM sales where Quarter=4 AND year = s.year) from sales s;
  • 15. SubQueries in Place of Columns Oracle SELECT year, DECODE( quarter, 1, amount, 0 ) q1, DECODE( quarter, 2, amount, 0 ) q2, DECODE( quarter, 3, amount, 0 ) q3, DECODE( quarter, 4, amount, 0 ) q4 FROM sales s;
  • 16. Delete with Second From Clause SQL Server delete from products from products, product_deletes where products.a = product_deletes.a and products.b = product_deletes.b and product_deletes.c = 'd';
  • 17. Delete with Second From Clause Oracle delete from products where ( a, b ) in ( select a, b from product_deletes where c = 'd' );
  • 18. III. More Depth The Connect Concept Other Conceptual Differences Data Type Differences Column Aliases Sub-Queries
  • 19. The Connect Concept SQL Server Multiple databases Oracle Single Database Multiple tablespaces, schemas, users
  • 20. Other Conceptual Differences SQL Server Database owner, DBO Group/Role Non-unique index T-SQL stored procedure { Trigger Compex rule Column identity property Oracle Schema Role Index PL/SQL procedure PL/SQL function BEFORE trigger After trigger Sequence
  • 21. Only in Oracle Clusters Packages Triggers for each row Synonyms Snapshots
  • 22. Data Type Differences SQL Server Oracle INTEGER NUMBER(10) SMALLINT NUMBER(6) TINYINT NUMBER(3) REAL FLOAT FLOAT FLOAT BIT NUMBER(1) VARCHAR(n) VARCHAR2(n) TEXT CLOB IMAGE BLOB BINARY(n) RAW(n) or BLOB
  • 23. Data Type Differences SQL Server Oracle VARBINARY RAW(n) or BLOB DATETIME DATE SMALL-DATETIME DATE MONEY NUMBER(19,4) NCHAR(n) CHAR(n*2) NVARCHAR(n) VARCHAR(n*2) SMALLMONEY NUMBER(10,4) TIMESTAMP NUMBER SYSNAME VARCHAR2(30), VARCHAR2(128)
  • 24. Time SQL Server Datetime: 1/300th second Oracle Date: 1 second Timestamp: 1/100 millionth second
  • 25. Column Aliases SQL Server select a=deptid, b=deptname,c=empno from dept; Oracle select deptid a, deptname b, empno c from dept;
  • 26. Sub-queries, again SQL Server SELECT ename, deptname FROM emp, dept WHERE emp.enum = 10 AND(SELECT security_code FROM employee_security WHERE empno = emp.enum) = (SELECT security_code FROM security_master WHERE sec_level = dept.sec_level);
  • 27. Sub-queries, again Oracle SELECT empname, deptname FROM emp, dept WHERE emp.empno = 10 AND EXISTS (SELECT security_code FROM employee_security es WHERE es.empno = emp.empno AND es.security_code = (SELECT security_code FROM security_master WHERE sec_level = dept.sec_level));
  • 28. Powerful New Features Regular Expressions: Operators & Functions Operator: REGEXP_LIKE Functions: REGEXP_INSTR REGEXP_SUBSTR REGEXP_REPLACE
  • 29. Regular Expressions Select zip from zipcode where regexp_like (zip, ‘[^[:digit:]]’);
  • 30. Regular Expressions SELECT REGEXP_INSTR('Joe Smith, 10045 Berry Lane, San Joseph, CA 91234-1234', ' [[:digit:]]{5}(-[[:digit:]]{4})?$') AS starts_at FROM dual
  • 31. Summary This discussion has been an attempt at a light and lively introduction to the Oracle database world for those familiar with the Microsoft SQL Server database products. Much more in-depth examples are available in the references shown that follow, from which many of the examples were drawn and for which we can thank the authors involved. Welcome Aboard!
  • 32. References Oracle Migration Workbench Reference Guide for SQL Server and Sybase Adaptive Server Migrations, Release 9.2.0 for Microsoft Windows 98/2000/NT and Microsoft Windows XP, Part Number B10254-01 Oracle Technology Network, OTN: http://otn.oracle.com/software/index.html Writing Better SQL Using Regular Expressions, By Alice Rischert http://otn.oracle.com/oramag/webcolumns/2003/techarticles/rischert_regexp_pt1.html