Presented By www.kellytechno.com
Presented By
www.kellytechno.com
IntroductionIf 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.
www.kellytechno.com
AgendaI. Quick Intro for SQL Server UsersII. Some Detail: Joins, Subqueries, DeletesIII. Certain Conceptual DifferencesIV. Powerful New FeaturesV. Summary & References
www.kellytechno.com
Don’t Use DatabasesSQL Server
use mydatabase
Oracle
connect mydatabase/mypassword
www.kellytechno.com
Use DualSQL Server
Oracle
select getdate();
select sysdate from dual;
www.kellytechno.com
Select IntoSQL Server
Oracle
select getdate() mycolumn into mytable;
insert into mytable (mycolumn)
values(sysdate);
www.kellytechno.com
InsertsSQL Server
Oracle
Insert mytable values(‘more text’);
Insert into mytable values(‘more text’);
www.kellytechno.com
UpdatesSQL Server
update mytable set mycolumn=myothertable.mycolumn from mytable,myothertable where mytable.mycolumn like 'MY%'
and myothertable.myothercolumn='some text';
www.kellytechno.com
UpdatesOracleupdate mytableset mycolumn=(select a.mycolumn from myothertable a where myothertable.myothercolumn='some text';)
where mytable.mycolumn like 'MY%';
www.kellytechno.com
DeletesSQL Server
delete mytable where mycolumn like 'some%';
Oracle
delete from mytable
where mycolumn like 'some%';
www.kellytechno.com
Software
• isql
• osql: for queries developed in SQL Analyzer
• sqlplus
SQL Server
Oracle
www.kellytechno.com
II. A Little More DetailOuter JoinSub-Queries in Place of ColumnsDeletes With a Second From Clause
www.kellytechno.com
Outer JoinSQL 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 (+);
www.kellytechno.com
SubQueries in Place of ColumnsSQL Server
select distinct year,q1 = (select Amount amt FROM saleswhere Quarter=1 AND year = s.year),q2 = (SELECT Amount amt FROM saleswhere Quarter=2 AND year = s.year),q3 = (SELECT Amount amt FROM saleswhere Quarter=3 AND year = s.year),q4 = (SELECT Amount amt FROM saleswhere Quarter=4 AND year = s.year)
from sales s;
www.kellytechno.com
SubQueries in Place of ColumnsOracle
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;
www.kellytechno.com
Delete with Second From ClauseSQL 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';
www.kellytechno.com
Delete with Second From Clause
Oracle
deletefrom productswhere ( a, b ) in( select a, bfrom product_deleteswhere c = 'd' );
www.kellytechno.com
III. More DepthThe Connect ConceptOther Conceptual DifferencesData Type DifferencesColumn AliasesSub-Queries
www.kellytechno.com
The Connect ConceptSQL Server Multiple databasesOracle Single Database Multiple tablespaces, schemas, users
www.kellytechno.com
Other Conceptual DifferencesSQL ServerDatabase owner, DBOGroup/RoleNon-unique indexT-SQL stored procedure {TriggerCompex ruleColumn identity property
OracleSchemaRoleIndexPL/SQL procedurePL/SQL functionBEFORE triggerAfter triggerSequence
www.kellytechno.com
Only in OracleClustersPackagesTriggers for each rowSynonymsSnapshots
www.kellytechno.com
Data Type DifferencesSQL Server OracleINTEGER 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
www.kellytechno.com
Data Type DifferencesSQL Server OracleVARBINARY RAW(n) or BLOBDATETIME DATESMALL-DATETIME DATEMONEY NUMBER(19,4)NCHAR(n) CHAR(n*2)NVARCHAR(n) VARCHAR(n*2)SMALLMONEY NUMBER(10,4)TIMESTAMP NUMBERSYSNAME VARCHAR2(30), VARCHAR2(128)
www.kellytechno.com
TimeSQL Server Datetime: 1/300th secondOracle Date: 1 second Timestamp: 1/100 millionth second
www.kellytechno.com
Column AliasesSQL Server select a=deptid, b=deptname,c=empno
from dept;Oracle select deptid a, deptname b, empno c from
dept;
www.kellytechno.com
Sub-queries, againSQL Server
SELECT ename, deptnameFROM emp, deptWHERE emp.enum = 10AND(SELECT security_codeFROM employee_securityWHERE empno = emp.enum) =
(SELECT security_codeFROM security_master
WHERE sec_level = dept.sec_level);
www.kellytechno.com
Sub-queries, againOracle
SELECT empname, deptnameFROM emp, deptWHERE emp.empno = 10AND EXISTS (SELECT security_codeFROM employee_security esWHERE es.empno = emp.empnoAND es.security_code =
(SELECT security_codeFROM security_masterWHERE sec_level = dept.sec_level));
www.kellytechno.com
Powerful New FeaturesRegular Expressions: Operators & FunctionsOperator: REGEXP_LIKEFunctions: REGEXP_INSTR REGEXP_SUBSTR REGEXP_REPLACE
www.kellytechno.com
Regular ExpressionsSelect zip from zipcode where regexp_like (zip, ‘[^[:digit:]]’);
www.kellytechno.com
Regular ExpressionsSELECT REGEXP_INSTR('Joe Smith,
10045 Berry Lane, San Joseph, CA 91234-1234',
' [[:digit:]]{5}(-[[:digit:]]{4})?$')
AS starts_at
FROM dual
www.kellytechno.com