2. Speaker and Company Information
• Database Specialist with JSTOR – www.jstor.org
• 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 Instance
Characteristic Oracle SQL Server
Minimum Block Size 2KB 8KB
Maximum Block Size 16KB 8KB
Maximum Blocks Per File 4 Million blocks 2 Million Blocks
Maximum File Size 64Gb 16TB
Maximum # of Files 65K 32K
Maximum DB Size 4PB 1EB
Instances Per Server Based on Server 50
Resources
Max # of tablespaces 65K 32K File Groups
Max log file size 64 Gb 32TB
Max # of tablespaces 65K 32K File Groups
9. Basic and Fundamental Differences –
Comparison of Core Objects
Oracle SQL Server
Table Table
Index Index
View View
Synonym Synonym
Sequence N/A
Procedure Stored Procedure
Function Function
Package N/A
Streams Service Broker Queue
XMLDB XML Schema Collection
Object Type Type
10. Basic and Fundamental Differences – Storage
Architecture
• 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 –Data
Blocks, 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 –Memory
Address 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 –Memory
Address 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 –Process
and 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 Processes
Oracle Oracle ID SQL Server required
Processes
Process PMON SQLOS Mandatory
monitor
System SMON Database Mandatory
Monitor Cleanups and
Shrinking
DB Writers DBWn Lazywriter Mandatory
Checkpoint CKPT Database Mandatory
Processes Checkpoint
Recoverer RECO MS DTC Optional
Logwriter 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 Objects
Oracle SQL Server
Heap-Organized Table Heap
Clustered Table N/A
Partitioned Table N/A
Nested Table N/A
Temporary Table Temporary Table
External Table ** Linked Server Feature
Object Table Table Variable
Indexed-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 MSSQL
B-tree Composite Yes (32 Cols) Yes (16 Cols)
B-Tree Reverse Yes No
B-Tree Key Compressed Yes No
B-Tree Function Based Yes No
B-Tree IOT Yes Yes (Clustered)
B-Tree Partition Yes No
Bitmap Yes No
Bitmap Join Yes No
22. Data Objects – Views (Diff)
View Type Oracle MSSQL
Object Views Yes No
Indexed 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 Based
Oracle Type Oracle Size SQL Type SQL Size
Char 1 – 2000 Char 1 - 8000
NChar 1 – 2000 NChar 1 – 4000
Varchar 1 – 4000 Varchar 1 - 8000
NVarchar 1 – 4000 NVarchar 1 - 8000
Varchar2 1 – 4000 Varchar 1 - 8000
NVarchar2 1 – 4000 Nvarchar 1 - 8000
LONG 1 – 2Gb Text 2GB
CLOB 4GB Text 2GB
NCLOB 4GB NText 2GB
BLOB 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.
– It's a unique value which is changed every time
the row is updated
27. Data Access – DML and Examples
MSSQL Oracle
GO Semi Colon (;)
Select sqrt(100) Select sqrt(100) from dual
Select ‘last Name’=lastname Select lastname “Last Name”
from …. from …. Or
Select lastname as ‘last name’
from ….
Select lastname +’,’+firstname Select lastname||’,’||firstname
from …. from …
Select top 5 from table Select * from table where
rownum <=5
28. Data Access – DML and examples
MSSQL Oracle
Left outer Join Where ta.col(+) = tb.col
Nullif(exp,exp) case
ISNULL(EXP,VAL) NVL(exp,val)
Select getdate() Select sysdate from dual
Case Case or decode
Select 3+5 (from not required) Select 3+5 from dual
Create procedure Create or replace procedure
Sp_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 = ‘ ‘
36. Operators
Operator MSSQL Oracle
Less than or equal to <= or !> <=
Greater than or equal >= or !< >=
to
Pattern matches Like ‘a%’ or LIKE’a[x-z]’ Like ‘a%’
or LIKE ‘a%’
Equal to a member of a IN or =ANY =SOME or IN
set
Less than or equal to <=ALL or !>all <=all
every member of the
set
Greater than or equal >=ALL or !<all >=all
to every member of the
set
37. Functions
MSSQL Oracle
Current_timestamp sysdate
Current_user user
Datalength Length
Host_id Userenv(‘terminal’)
Host_name Userenv(‘host’)
Isdate N/A
ISNULL NVL
NULLIF CASE
SESSION_USER USER
39. Easy T-SQL example - MSSQL
Create proc proc1
As
Begin
Declare @x int
If exists (select * from table2)
Select @x = -1
end
40. Easy T-SQL example - ORACLE
Create or replace procedure proc1
As
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 - MSSQL
UPDATE 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 - Oracle
declare
template_lob2 clob;
begin
template_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 - MSSQL
update PUBLICATION
set 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 - Oracle
update 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');
46. Miscellaneous
MSSQL 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
– Download.oracle.com/docs/
• 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.org
Please fill out your evaluation form.
Migrating SQL Server 2005 Applications to Oracle
Mike Gangler
Paper # 2086