12.07.2015 Views

Solution Guide for Migrating Oracle on UNIX to SQL Server - Willy .Net

Solution Guide for Migrating Oracle on UNIX to SQL Server - Willy .Net

Solution Guide for Migrating Oracle on UNIX to SQL Server - Willy .Net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

206 Developing: Applicati<strong>on</strong>s — <str<strong>on</strong>g>Migrating</str<strong>on</strong>g> <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> <strong>SQL</strong> and PL/<strong>SQL</strong>row fetched is fetched. If n is 0, the same row is fetched again. It also allowsretrieving <strong>on</strong>e row or block of rows from the current positi<strong>on</strong> in the result set.It supports data modificati<strong>on</strong>s <strong>to</strong> the rows at the current positi<strong>on</strong> in the result set.Step 4: Subprograms C<strong>on</strong>versi<strong>on</strong>The next step is <strong>to</strong> migrate the procedures, functi<strong>on</strong>s, and triggers. This secti<strong>on</strong>discusses how each comp<strong>on</strong>ent can be c<strong>on</strong>verted <str<strong>on</strong>g>for</str<strong>on</strong>g> use with <strong>SQL</strong> <strong>Server</strong>.<str<strong>on</strong>g>Migrating</str<strong>on</strong>g> ProceduresA s<strong>to</strong>red procedure is a precompiled object. This means that a procedure is compiledbe<str<strong>on</strong>g>for</str<strong>on</strong>g>ehand and is readily available <str<strong>on</strong>g>for</str<strong>on</strong>g> the various applicati<strong>on</strong>s <strong>to</strong> execute. As a result,time is not wasted parsing and compiling the procedure again. However, the procedurewill be compiled every time if it c<strong>on</strong>tains dynamic <strong>SQL</strong>. S<strong>to</strong>red procedures in <strong>SQL</strong> <strong>Server</strong>are very similar <strong>to</strong> procedures in <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> PL/<strong>SQL</strong>. Some similarities include:● Both can accept parameters and return multiple values in the <str<strong>on</strong>g>for</str<strong>on</strong>g>m of outputparameters (OUT parameter) <strong>to</strong> the calling procedure.● Both c<strong>on</strong>tain programming statements that per<str<strong>on</strong>g>for</str<strong>on</strong>g>m operati<strong>on</strong>s in the database,including calling other procedures.● Both can overwrite existing procedures. <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> uses the keyword REPLACE, while<strong>SQL</strong> <strong>Server</strong> uses ALTER.The syntax between <str<strong>on</strong>g>Oracle</str<strong>on</strong>g> and <strong>SQL</strong> <strong>Server</strong> procedures differs. The differences areshown in the following examples:● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>●CREATE OR REPLACE PROCEDURE (PARAMETER1 DATATYPE [IN OUT],PARAMETER2 DATATYPE [IN OUT],)ISVARIABLE1 DATATYPE;VARIABLE2 DATATYPE;BEGINEXECUTABLE STATEMENTS;EXCEPTIONEXECUTABLE STATEMENTS;END;<strong>SQL</strong> <strong>Server</strong>CREATE PROCEDURE [ ; number ][ { @PARAMETER DATATYPE }[ VARYING ] [ = default ] [ OUTPUT ]] [ ,...n ] ASEXECUTABLE STATEMENTSIn the following example, a s<strong>to</strong>red procedure calculates the number of m<strong>on</strong>ths remaininguntil retirement <str<strong>on</strong>g>for</str<strong>on</strong>g> each employee. Retirement age is passed as a parameter <strong>to</strong> theprocedure. The output needs <strong>to</strong> be written in<strong>to</strong> a table named RETIRE. The RETIREtable has two columns. The columns are EMPLOYEEID and MONTHS_REMAINING.The number of m<strong>on</strong>ths remaining is calculated and inserted in<strong>to</strong> this table. Be<str<strong>on</strong>g>for</str<strong>on</strong>g>e startingthe operati<strong>on</strong>, the table needs <strong>to</strong> be flushed.● <str<strong>on</strong>g>Oracle</str<strong>on</strong>g>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!