31
Presented By www.kellytechno.com

Oracle training-institutes-in-hyderabad

Embed Size (px)

Citation preview

Page 1: Oracle training-institutes-in-hyderabad

Presented By

www.kellytechno.com

Page 2: Oracle training-institutes-in-hyderabad

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

Page 3: Oracle training-institutes-in-hyderabad

AgendaI. Quick Intro for SQL Server UsersII. Some Detail: Joins, Subqueries, DeletesIII. Certain Conceptual DifferencesIV. Powerful New FeaturesV. Summary & References

www.kellytechno.com

Page 4: Oracle training-institutes-in-hyderabad

Don’t Use DatabasesSQL Server

use mydatabase

Oracle

connect mydatabase/mypassword

www.kellytechno.com

Page 5: Oracle training-institutes-in-hyderabad

Use DualSQL Server

Oracle

select getdate();

select sysdate from dual;

www.kellytechno.com

Page 6: Oracle training-institutes-in-hyderabad

Select IntoSQL Server

Oracle

select getdate() mycolumn into mytable;

insert into mytable (mycolumn)

values(sysdate);

www.kellytechno.com

Page 7: Oracle training-institutes-in-hyderabad

InsertsSQL Server

Oracle

Insert mytable values(‘more text’);

Insert into mytable values(‘more text’);

www.kellytechno.com

Page 8: Oracle training-institutes-in-hyderabad

UpdatesSQL Server

update mytable set mycolumn=myothertable.mycolumn from mytable,myothertable where mytable.mycolumn like 'MY%'

and myothertable.myothercolumn='some text';

www.kellytechno.com

Page 9: Oracle training-institutes-in-hyderabad

UpdatesOracleupdate mytableset mycolumn=(select a.mycolumn from myothertable a where myothertable.myothercolumn='some text';)

where mytable.mycolumn like 'MY%';

www.kellytechno.com

Page 10: Oracle training-institutes-in-hyderabad

DeletesSQL Server

delete mytable where mycolumn like 'some%';

Oracle

delete from mytable

where mycolumn like 'some%';

www.kellytechno.com

Page 11: Oracle training-institutes-in-hyderabad

Software

• isql

• osql: for queries developed in SQL Analyzer

• sqlplus

SQL Server

Oracle

www.kellytechno.com

Page 12: Oracle training-institutes-in-hyderabad

II. A Little More DetailOuter JoinSub-Queries in Place of ColumnsDeletes With a Second From Clause

www.kellytechno.com

Page 13: Oracle training-institutes-in-hyderabad

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

Page 14: Oracle training-institutes-in-hyderabad

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

Page 15: Oracle training-institutes-in-hyderabad

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

Page 16: Oracle training-institutes-in-hyderabad

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

Page 17: Oracle training-institutes-in-hyderabad

Delete with Second From Clause

Oracle

deletefrom productswhere ( a, b ) in( select a, bfrom product_deleteswhere c = 'd' );

www.kellytechno.com

Page 18: Oracle training-institutes-in-hyderabad

III. More DepthThe Connect ConceptOther Conceptual DifferencesData Type DifferencesColumn AliasesSub-Queries

www.kellytechno.com

Page 19: Oracle training-institutes-in-hyderabad

The Connect ConceptSQL Server Multiple databasesOracle Single Database Multiple tablespaces, schemas, users

www.kellytechno.com

Page 20: Oracle training-institutes-in-hyderabad

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

Page 21: Oracle training-institutes-in-hyderabad

Only in OracleClustersPackagesTriggers for each rowSynonymsSnapshots

www.kellytechno.com

Page 22: Oracle training-institutes-in-hyderabad

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

Page 23: Oracle training-institutes-in-hyderabad

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

Page 24: Oracle training-institutes-in-hyderabad

TimeSQL Server Datetime: 1/300th secondOracle Date: 1 second Timestamp: 1/100 millionth second

www.kellytechno.com

Page 25: Oracle training-institutes-in-hyderabad

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

Page 26: Oracle training-institutes-in-hyderabad

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

Page 27: Oracle training-institutes-in-hyderabad

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

Page 28: Oracle training-institutes-in-hyderabad

Powerful New FeaturesRegular Expressions: Operators & FunctionsOperator: REGEXP_LIKEFunctions: REGEXP_INSTR REGEXP_SUBSTR REGEXP_REPLACE

www.kellytechno.com

Page 29: Oracle training-institutes-in-hyderabad

Regular ExpressionsSelect zip from zipcode where regexp_like (zip, ‘[^[:digit:]]’);

www.kellytechno.com

Page 30: Oracle training-institutes-in-hyderabad

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

Page 31: Oracle training-institutes-in-hyderabad