Your SlideShare is downloading. ×
  • Like
2008 2086 Gangler
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

2008 2086 Gangler



  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. 2086/Migrating SQL Server 2005 Applications to Oracle Mike Gangler Ithaka / JStor Session # 2086
  • 2. Speaker and Company Information• Database Specialist with JSTOR –• 20+ Years DBA experience• Presented Collaborate in ’07, SEMOP, Regional user Groups and at many IOUG-Alive events• Experience with FOCUS, IMS DB/DC, DB2, Sybase, and MSSQL 6.5 databases prior to assignment.• JSTOR - is a not-for-profit organization dedicated to helping the scholarly community discover, use, and build upon a wide range of intellectual content in a trusted digital archive. We collaborate with organizations that benefit the scholarly community.
  • 3. Agenda• Introduction• Overview of Problem• Basic and Fundamental Differences• Database Locking•• Data Objects• Data Types• Data Access – DML and Examples
  • 4. Introduction• This session will describe the lessons learned during the process of converting an MSSQL database application to Oracle.• Session targeted towards Oracle DBA’s with little or no MSSQL experience.• JSTOR purchased a 3rd party product that was using primarily MSSQL.• Agreement was that JSTOR would convert MSSQL patches and coding to Oracle (If and when needed).• Project started in 2006 and we launched the new product in April 2008.• Using Oracle 10G release 2 and Grid Control on Sun Solaris X86-64 machines• 3rd Party using SQL Server 2005
  • 5. Overview of Problem• JSTOR Is primarily a Oracle Shop• 3rd Party is primarily a MSSQL Shop• Coding was supposed to be “Database Agnostic”• Limited assistance from 3rd Party• Limited experience with MSSQL• 2 development centers – Santa Clara and Ann Arbor – code control – version control – little or no communication• 3 – 5 patches a day
  • 6. Basic and Fundamental Differences• Database, Instance and Storage Architecture – Terminology – Characteristic Differences – Comparison of Core Objects – Storage Architecture – Data Blocks, Extents and Segments – Memory Address Space – Oracle – Memory Address Space – MSSQL – Process and Thread-based Architecture – Background Processes
  • 7. Basic and Fundamental Differences -Database and Instance• Terminology – – Oracle Instance = Memory and Processes related to a Database. – Oracle Database = Files containing application and system information – MSSQL Instance = set of binaries isolating the SQL Server database Engine Services. • Every Instance will have its own system database and separate Admin parms. – MSSQL Database = Oracle schema with a Master DB (System Tables).
  • 8. Basic and Fundamental Differences –Database and InstanceCharacteristic Oracle SQL ServerMinimum Block Size 2KB 8KBMaximum Block Size 16KB 8KBMaximum Blocks Per File 4 Million blocks 2 Million BlocksMaximum File Size 64Gb 16TBMaximum # of Files 65K 32KMaximum DB Size 4PB 1EBInstances Per Server Based on Server 50 ResourcesMax # of tablespaces 65K 32K File GroupsMax log file size 64 Gb 32TBMax # of tablespaces 65K 32K File Groups
  • 9. Basic and Fundamental Differences –Comparison of Core ObjectsOracle SQL ServerTable TableIndex IndexView ViewSynonym SynonymSequence N/AProcedure Stored ProcedureFunction FunctionPackage N/AStreams Service Broker QueueXMLDB XML Schema CollectionObject Type Type
  • 10. Basic and Fundamental Differences – StorageArchitecture• Physical – Oracle Data file = MSSQL data file or Device• Logical – Oracle tablespace = MSSQL File Group – Oracle Segment = MSSQL Heap/Index – Oracle Extent = MSSQL Extent – Oracle Blocks = MSSQL Pages
  • 11. Basic and Fundamental Differences –DataBlocks, Extents and segments• Smallest unit of logical storage – Oracle = Block – MSSQL = Page• Block size – Oracle is variable – MSSQL is fixed at 8kb• Extent size – Oracle is variable – MSSQL are fixed at 64kb
  • 12. Basic and Fundamental Differences –MemoryAddress Space - Oracle• Memory Allocation Concepts – Oracle – Oracle is static – Allocated at Startup – MSSQL is Dynamic – Variables set by administrator – ASSM introduced in Oracle 10g
  • 13. Basic and Fundamental Differences –MemoryAddress Space – MSSQL 2005• Memory Allocation Concepts – MSSQL 2005 – Allocations are constantly changed based on RDBMS needs and operating system needs (Self Tuning). – Allocation is dynamic at higher level (Memory pool, etc.) and lower level ( Buffer cache, procedure cache, etc.) components. – Very Few configurable parameters – Min server memory and max server memory settings• Memory address range – Leveraging Address Windowing Extensions (AWE)
  • 14. Basic and Fundamental Differences –Processand Thread-based Architecture• Process is an independent piece of code with its own memory space• Thread is spawned by a process and works within the parents memory space• Advantages of using Threads: – Reduced overhead in context switching and reduction in overall memory requirements – Microsoft fibers are light-weight threads further reduces context switching overheads by running purely in user mode• Oracle uses processes in Unix and Threads in Windows• Both Oracle and SQL Server use threads and optionally fibers. Threads/fibers are scheduled onto a CPU by a user mode Scheduler (UMS)• Process/thread can be tied to processors in both Oracle (Windows) and SQL Server 2005 using CPU affinity feature.
  • 15. Basic and Fundamental Differences –Background ProcessesOracle Oracle ID SQL Server requiredProcessesProcess PMON SQLOS MandatorymonitorSystem SMON Database MandatoryMonitor Cleanups and ShrinkingDB Writers DBWn Lazywriter MandatoryCheckpoint CKPT Database MandatoryProcesses CheckpointRecoverer RECO MS DTC OptionalLogwriter LGWR Log Writer Mandatory
  • 16. Basic and Fundamental Differences –Background Processes Oracle Oracle ID SQL Server required Processes Archive ARCn N/A N/A Job Queue Jnnn SQL Agent Mandatory Process Parallel Pnnn Worker Optional Slave Threads processes Dispatcher Dnnn Networker Mandatory Threads Shared Snnn Worker Mandatory Servers Threads
  • 17. Database Locking• MSSQL – Prior to SQLSERVER 2005 – Select statements obtain shared locks on pages/rows. • Prevents other statements from obtaining an exclusive lock on those pages/rows. • All Update statements require exclusive lock. • These locks will lock all update transactions until the select commits or roll backs. • transactions are physically serialized whenever 1 transaction selects the data and 1 changes.• ORACLE – – Readers don’t block writers and writers don’t block readers.
  • 18. Database Locking – Row Vs Page• MSSQL – Prior to MSSQL 2005 no row level locking – Does page level locking, which blocks all rows on the page. – MSSQL2005 – does a form of row level locking. – MSSQL2005 – Escalates locks at row level to page level automatically.• ORACLE – Row level locking – Only one row is locked when DML is changing the row.
  • 19. Data ObjectsOracle SQL ServerHeap-Organized Table HeapClustered Table N/APartitioned Table N/ANested Table N/ATemporary Table Temporary TableExternal Table ** Linked Server FeatureObject Table Table VariableIndexed-Organized Table Clustered Index
  • 20. Data Objects - Table• Heap is the default Form of data organization in a table, where data is stored in an unordered manner• In Oracle, Index Organized Tables store data in a B- Tree structure in primary key order.• SQL Server offers clustered indexes where data can be ordered by any column• Oracle and MSSQL offer local and global temporary tables to store transient application data
  • 21. Data Objects – Indexes (Diff)Index Scheme Oracle MSSQLB-tree Composite Yes (32 Cols) Yes (16 Cols)B-Tree Reverse Yes NoB-Tree Key Compressed Yes NoB-Tree Function Based Yes NoB-Tree IOT Yes Yes (Clustered)B-Tree Partition Yes NoBitmap Yes NoBitmap Join Yes No
  • 22. Data Objects – Views (Diff)View Type Oracle MSSQLObject Views Yes NoIndexed Views No Yes Updateable Views – Restrictions in MSSQL can be bypassed by defining a “INSTEAD OF” trigger on the view. INLINE Views – MSSQL use Derived tables and CTE (Common table Expressions)
  • 23. Data Types – Character BasedOracle Type Oracle Size SQL Type SQL SizeChar 1 – 2000 Char 1 - 8000NChar 1 – 2000 NChar 1 – 4000Varchar 1 – 4000 Varchar 1 - 8000NVarchar 1 – 4000 NVarchar 1 - 8000Varchar2 1 – 4000 Varchar 1 - 8000NVarchar2 1 – 4000 Nvarchar 1 - 8000LONG 1 – 2Gb Text 2GBCLOB 4GB Text 2GBNCLOB 4GB NText 2GBBLOB 4GB Image 2GB
  • 24. Data Types – Numeric Data Oracle Type SQL Type Number(19,0) Bigint Int / Number(10,0) int Smallint / smallint Number(6,0) Number(3,0) tinyint Number(p,0) decimal Number(p,0) Numeric(p,s) Float / Number(38) Float Number(1) Bit Number(19,4) Money Number(10,4) Small Money
  • 25. Data Types – Other Types Oracle Type SQL Type Date datetime Date Smalldatetime Timestamp datetime RAW(n) / BLOB Binary(n) RAW(n) / BLOB VARBINARY(n) FLOAT FLOAT REAL FLOAT
  • 26. Date Data Types• MSSQL datetime accurate up to 3.33 Milliseconds.• Oracle “date” is accurate up to 1 second.• Oracle’s timestamp up to 1 Millisecond.• MSSQL “smalldatetime” up to 1 Minute.• If application requires sub second Date Precision use Oracle’s “timestamp”.• MSSQL “timestamp” not related to “datetime” – MSSQL2005 – “timestamp” = SQL2000 – “rowversion. – Its a unique value which is changed every time the row is updated
  • 27. Data Access – DML and ExamplesMSSQL OracleGO Semi Colon (;)Select sqrt(100) Select sqrt(100) from dualSelect ‘last Name’=lastname Select lastname “Last Name”from …. from …. Or Select lastname as ‘last name’ from ….Select lastname +’,’+firstname Select lastname||’,’||firstnamefrom …. from …Select top 5 from table Select * from table where rownum <=5
  • 28. Data Access – DML and examplesMSSQL OracleLeft outer Join Where ta.col(+) = tb.colNullif(exp,exp) caseISNULL(EXP,VAL) NVL(exp,val)Select getdate() Select sysdate from dualCase Case or decodeSelect 3+5 (from not required) Select 3+5 from dualCreate procedure Create or replace procedureSp_rename n/a – procedure to emulate the sp_rename function.
  • 29. Select clause Differences• MSSQL – “TOP” – “IDENTITYCOL” – “ROWGUIDCOL” – Column Alias – select c1 = ‘alias’ from t1• ORACLE – Select c1 from t1 where rownum < n – Doesn’t support “identitycol” – Doesn’t support “rowguidcol” (sys_guid) – Column alias – select c1 “alias’ from t1
  • 30. Update Statements• MSSQL – Supports a “FROM” clause – MSSQL Example: • Update t1 set col1=0 from t1=a, t2=b where a.c2 = b.c2• ORACLE – Doesn’t Support a “FROM” clause – Oracle Example: • Update t1 set col1=0 where col1 in (select col1 from t2 where c3 = ‘USA’)
  • 31. Delete Statements• MSSQL – Supports a “FROM” clause – MSSQL Example: • Delete tableA from tableA a, tableB b where a.c1 = b.c1• ORACLE – Doesn’t Support a “FROM” clause – Oracle Example: • Delete tableA a • Where exists (select * from tableB b where a.c1 = b.c1)
  • 32. “Into” Clause• MSSQL – Select * into t1 from t2 – Insert * into t1 from t2• ORACLE – Create table t1 as select * from t2 – Insert into t1 as select * from t2
  • 33. Global Tables Examples• MSSQL Create table #a_temp_table (col1 INT, col2 char(1))• Oracle Create global temporary table tt_a_temp_table (col1 number(6), col2 char(1)) On commit reserve rows
  • 34. Empty String Literals• MSSQL – interprets empty string as a single blank space• Oracle – interprets empty string as NULL• MSSQL – Insert into table (c1, c2) values (‘foo’,’’) – Select c1 from table where c1 = ‘’• Oracle – Insert into table (c1,c2) values ‘foo’, ‘ ‘) – Select c1 from table where c1 = ‘ ‘
  • 35. Remote Objects• MSSQL – Server_name.database_name.object_owner.object_name – Example: •• ORACLE – Object_owner.object_name@database_name – Example •
  • 36. OperatorsOperator MSSQL OracleLess than or equal to <= or !> <=Greater than or equal >= or !< >=toPattern matches Like ‘a%’ or LIKE’a[x-z]’ Like ‘a%’ or LIKE ‘a%’Equal to a member of a IN or =ANY =SOME or INsetLess than or equal to <=ALL or !>all <=allevery member of thesetGreater than or equal >=ALL or !<all >=allto every member of theset
  • 37. FunctionsMSSQL OracleCurrent_timestamp sysdateCurrent_user userDatalength LengthHost_id Userenv(‘terminal’)Host_name Userenv(‘host’)Isdate N/AISNULL NVLNULLIF CASESESSION_USER USER
  • 39. Easy T-SQL example - MSSQLCreate proc proc1AsBegin Declare @x int If exists (select * from table2) Select @x = -1end
  • 40. Easy T-SQL example - ORACLECreate or replace procedure proc1As V_x number(10); V_temp number(1,0) := 0;Begin Select 1 into v_temp From dual where exists (select * from table2); If v_temp = 1 then V_x := -1; End if;End;
  • 41. T/SQL – Example - MSSQLUPDATE admin_role SET template = <?xml version="1.0" encoding="UTF-8"?> <templates> <package id="identity"> <action name="read"></action> </package> <package id="metadata"> <action name="read"></action> </package> <package id="ecommerce"> <action name="access"></action> </package> <package id="redirect"> <action name="read"></action> <action name="change"></action> <action name="create"></action> <action name="delete"></action> </package>…. **** Greater than 4000 Bytes<backstage action="adminBackstage-setPriority" area="6"></backstage> <backstage action="adminBackstage-changeSubjHeading" area="6"></backstage></templates> WHERE name = Publisher Super Admin
  • 42. T/SQL Conversion Example - Oracledeclaretemplate_lob2 clob;begintemplate_lob2 :=<?xml version="1.0" encoding="UTF-8"?><templates> <package id="identity"> <action name="read"></action> <action name="change"></action> <action name="create"></action> <action name="delete"></action> <action name="changepwd"></action> <action name="settings"></action> <action name="impersonate"/> </package>…….*** Greater than 4000 Bytes<backstage action="adminBackstage-changeSubjHeading" area="6"></backstage></templates>;UPDATE admin_role set template=template_lob2 WHERE name = Publisher Super Admin;
  • 43. Case example - MSSQLupdate PUBLICATIONset Area = (select CASE WHEN Area LIKE 00000000% THEN 0 WHEN Area LIKE 00000001% THEN 1 WHEN Area LIKE 00000010% THEN 2 WHEN Area LIKE 00000100% THEN 4 WHEN Area LIKE 00001000% THEN 8 WHEN Area LIKE 00010000% THEN 16 WHEN Area LIKE 00100000% THEN 32 WHEN Area LIKE 01000000% THEN 64 WHEN Area LIKE 10000000% THEN 128 END from PUB_AREA_STR_BACKUP where PUBLICATION.pubid = PUB_AREA_STR_BACKUP.pubid)where pubid in (select pubid from PUB_AREA_STR_BACKUP);
  • 44. Case example - Oracleupdate PUBLICATION set Area = (select decode(Area, 0000000000000000, 0, 0000000100000000, 1, 0000001000000000, 2, 0000100000000000, 8, 0001000000000000, 16, 0010000000000000, 32) from article_meta where article_meta.articleid = PUBLICATION.PubId)where exists (select articleId from article_meta where PUBLICATION.pubid = article_meta.articleid and area is not null and area <> 0000010000000000);
  • 45. Sequence Differences• MSSQL – No Database Sequences – Example – CREATE TABLE SEQ_OFFERID_SEQ ( idvalue bigint IDENTITY(1,1) )• T-SQL Example: declare @uid bigint exec nextval2 UserID_SEQ, @uid output insert into change_record (userid, createupdatedate, action, sessionid, userid) values (@uid, getdate(), 0, -1, -1)
  • 46. MiscellaneousMSSQL sp_rename function if exists(select * from sysobjects where name = SEQ_ECOMM2_CONTRACTTERM and uid=user_id()) exec sp_rename SEQ_ECOMM2_CONTRACTTERM, SEQ_ECOMM2_CONTRACTTERM_SEQ; exec sp_rename Publication.IsRegistered, IsDoiRegistered, COLUMN;ORACLE sp_rename equivalent no oracle “sp_rename” equivalent – must use PL/SQL, or alter table.VIEWS• MSSQL doesn’t have create or replace view – so they drop first than create
  • 47. CAST / Concatenation Diff• Oracle – UPDATE ad_data SET description = Ad || CAST(adId AS VARCHAR2(19)) WHERE description IS NULL;• MSSQL – UPDATE ad_data SET description = Ad + CAST(adId AS VARCHAR) WHERE description IS NULL
  • 48. References• Migrating Applications from Microsoft SQL Server to Oracle 9i Database – Oracle White Paper – November 2003• Microsoft SQL Server and Oracle Compared –• Microsoft SQLServer 2005 for the experienced Oracle Database Administrator – Microsoft Course 7033A
  • 49. Items Learned in this Session• Basic differences between Oracle and MSSQL – Database, Instance, Memory and Storage Architecture – Terminology• Database locks• Data Objects• Data Types• DML Examples
  • 50. Thank You for Attending Thank you, Questions? Michael.gangler@ithaka.orgPlease fill out your evaluation form. Migrating SQL Server 2005 Applications to Oracle Mike Gangler Paper # 2086