Recently, a project has changed the original Sybase Database to an Oracle database. Therefore, I want to change the Sybase script to an oracle script, such as a table structure, stored procedure, and view script. this script change may take a long time before it can be encountered. Put it in the blog, and you need to check it again later.
(The Sybase version is 11.9.2 and the Oracle version is 10 Gb)
1. If exists
Use the regular expression where id = object_id/(/'[A-Z _] + /'/)
Determine whether the table exists. Drop the table directly.
2. Go (Be sure to use full-word match)
Replace/
3. varchar (this should be changed in advance)
Replace with varchar2
4. Text
Replace it with varchar2 (4000). If it is not enough, use clob instead.
5. datetime
Replace it with date or timestamp, Which is accurate to milliseconds.
6. Do not create empty rows in the table creation script. Otherwise, an error will occur during the command window import.
Replace the regular expression ^ [/T] */n with a space in editplus to cancel empty rows (^ starts with the line header and/N is a linefeed)
Click the replace button several times and check again.
7. DBO.
Replace with space or user name
8. Create a primary key
Constraint pk_bdg_sdc_prj_zp primary key clustered (ID)
Remove clustered from
9. Remove lock allpages.
10. getdate ()
Replace with sysdate
11. isnull ()
Replace with nvl ()
11. If duplicate table creation occurs
Comment on the table /*********//****************
/**/Change **
/*********/*****************/
It was not very clear at the beginning, but it is usually because the name of the table to be created below is too long.
12. Stored Procedure
A. Parameter: After the stored procedure name (P1, P2 ,.....)
The name cannot start @;
Specify in and out;
The parameter type cannot contain parentheses;
B. Variable: Do not use the keyword declare, directly "t_time varchar2 (20); t_seq int;" (note that ";");
Defined between AS and begin;
Assign the variable "Vara: = value ;"
And "select Keya into Vara from tablea ;";
C. Add ";" after each complete statement ";";
There is no direct "return 1;", but "return;" can be used to directly interrupt the stored procedure;
No "begin transaction", but you can use "commit;" and "rollback;" (I don't know if every execution creates a hidden transaction );
To return the select result set, you must use a cursor, but you must create a packet A. In this package a, define a cursor such as "type cursortype is ref cursor ;".
Type, and then add an output parameter "p_cursor out A. cursortype". The content contains "Open p_cursor for select ......;";
DDL statements must use dynamic SQL, such as "v_ SQL: = 'drop table tmp_xmz_report '; execute immediate v_ SQL ;";
D. Control Structure
If... else
SYBASE: If (condition) Begin code block end (if there is only one sentence of code, you do not need to use BEGIN end)
Else begin code block end (if there is only one sentence of code, you do not need to use BEGIN end)
ORACLE: If (condition) then code block
Else code block end if;
E. cursor
In Sybase, you can directly "declare cur1 cursor for select...". This does not seem to work in Oracle,
However, you can use "for curtailrecord in (Select...) loop code block end loop ;";