• Aucun résultat trouvé

Beginning SQL: Beginning SQL: Differences Between SQL Differences Between SQL Server and Oracle Server and Oracle

N/A
N/A
Protected

Academic year: 2022

Partager "Beginning SQL: Beginning SQL: Differences Between SQL Differences Between SQL Server and Oracle Server and Oracle"

Copied!
32
0
0

Texte intégral

(1)

Beginning SQL:

Beginning SQL:

Differences Between SQL Differences Between SQL

Server and Oracle Server and Oracle

Les Kopari Les Kopari

Independent Consultant Independent Consultant

A Quick Intro for SQL Server Users

(2)

Introduction Introduction

If 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 Agenda

I. Quick Intro for SQL Server Users I. Quick Intro for SQL Server Users

II. Some Detail: Joins, Subqueries, Deletes II. Some Detail: Joins, Subqueries, Deletes

III. Certain Conceptual Differences III. Certain Conceptual Differences

IV. Powerful New Features IV. Powerful New Features V. Summary & References V. Summary & References

(4)

Don’t Use Databases Don’t Use Databases

SQL Server

use

mydatabase

Oracle

connect mydatabase/mypassword

(5)

Use Dual Use Dual

SQL Server

Oracle

select getdate();

select sysdate from dual;

(6)

Select Into Select Into

SQL Server

Oracle

select getdate() mycolumn into mytable;

insert into mytable (mycolumn) values(sysdate);

(7)

Inserts Inserts

SQL Server

Oracle

Insert mytable values(‘more text’);

Insert into mytable values(‘more text’);

(8)

Updates Updates

SQL Server

update mytable

set mycolumn=myothertable.mycolumn from mytable,myothertable

where mytable.mycolumn like 'MY%'

and myothertable.myothercolumn='some text';

(9)

Updates Updates

Oracle

update mytable set mycolumn=

(select a.mycolumn

from myothertable a

where myothertable.myothercolumn='some text';

)

where mytable.mycolumn like 'MY%';

(10)

Deletes Deletes

SQL Server

delete mytable where mycolumn like 'some%';

Oracle

delete from mytable

where mycolumn like 'some%';

(11)

Software Software

• isql

• osql: for queries developed in SQL Analyzer

• sqlplus SQL Server

Oracle

(12)

II. A Little More Detail II. A Little More Detail

• Outer JoinOuter Join

• Sub-Queries in Place of ColumnsSub-Queries in Place of Columns

• Deletes With a Second From ClauseDeletes With a Second From Clause

(13)

Outer Join Outer Join

SQL Server SQL Server

select d.deptname, e.ename from dept d, select d.deptname, e.ename from dept d, emp e where d.empno *= e.enum;

emp e where d.empno *= e.enum;

Oracle Oracle

select d.deptname,e.ename from dept d, select d.deptname,e.ename from dept d, emp e where d.empno = e.enum (+);

emp e where d.empno = e.enum (+);

(14)

SubQueries in Place of Columns SubQueries in Place of Columns

SQL ServerSQL 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 SubQueries in Place of Columns

Oracle 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 Delete with Second From Clause

SQL Server 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 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 III. More Depth

• The Connect ConceptThe Connect Concept

• Other Conceptual DifferencesOther Conceptual Differences

• Data Type DifferencesData Type Differences

• Column AliasesColumn Aliases

• Sub-QueriesSub-Queries

(19)

The Connect Concept The Connect Concept

SQL Server SQL Server

Multiple databasesMultiple databases Oracle

Oracle

Single DatabaseSingle Database

Multiple tablespaces, schemas, usersMultiple tablespaces, schemas, users

(20)

Other Conceptual Differences 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 Only in Oracle

• ClustersClusters

• PackagesPackages

• Triggers for each rowTriggers for each row

• SynonymsSynonyms

• SnapshotsSnapshots

(22)

Data Type Differences 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 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 Time

SQL Server SQL Server

Datetime: 1/300th secondDatetime: 1/300th second Oracle

Oracle

Date: 1 secondDate: 1 second

Timestamp: 1/100 millionth secondTimestamp: 1/100 millionth second

(25)

Column Aliases Column Aliases

SQL Server SQL Server

select a=deptid, b=deptname,c=empno select a=deptid, b=deptname,c=empno from dept;

from dept;

Oracle Oracle

select deptid a, deptname b, empno c select deptid a, deptname b, empno c from dept;

from dept;

(26)

Sub-queries, again Sub-queries, again

SQL ServerSQL 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 Sub-queries, again

Oracle 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 Powerful New Features

Regular Expressions: Operators & FunctionsRegular Expressions: Operators & Functions

Operator: REGEXP_LIKEOperator: REGEXP_LIKE

Functions: REGEXP_INSTRFunctions: REGEXP_INSTR

REGEXP_SUBSTRREGEXP_SUBSTR

REGEXP_REPLACEREGEXP_REPLACE

(29)

Regular Expressions Regular Expressions

Select zip Select zip

from zipcodefrom zipcode

where regexp_like (zip, ‘[^[:digit:]]’);

where regexp_like (zip, ‘[^[:digit:]]’);

(30)

Regular Expressions 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 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 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

Références

Documents relatifs

• Microsoft spatial data types provide SQL access to spatial data. Administering Your Microsoft SQL

including relational database server, full text indexing and search, XML data import and export, distributed and heterogeneous data integration, analysis server and client for

 Database with Integrated OLAP and Data Transformation Services (DTS).  Integration with the

• Ensure the domain account can run queries against the other server.. Lab

• Specify report, execution conditions, parameters, rendering Specify report, execution conditions, parameters, rendering format, delivery location, etc. format, delivery

Microsoft SQL Server Microsoft SQL Server Administration for SAP Administration for SAP SQL Server Architecture SQL Server Architecture...

SQL Server 2005 ofrece una plataforma de datos más confiable, segura y SQL Server 2005 ofrece una plataforma de datos más confiable, segura y productiva para aplicaciones de unidad

What you need to know is that if you alter or build an index on a table that has data in it, and you don’t let SQL Server update the statistics on the table, then SQL Server could