建表语句修改
序号 | 修改范围 | 修改方法 |
1 | int类型 | 改为number(10) |
2 | numeric类型 | 改为number类型 |
3 | smallint类型 | 改为number(5) |
4 | tinyint类型 | 改为number(3) |
5 | bigint类型 | 改为number(19) |
6 | bit类型 | 改为number(2) |
7 | datetime类型 | 改为date类型 |
8 | varchar类型 | 改为varchar2类型 |
9 | nchar类型 | 改为varchar2类型,长度上限设为原长度的二倍 |
10 | nvarchar类型 | 改为varchar2类型,长度上限设为原长度的二倍 |
11 | 默认值约束 | 在建表语句中添加default |
12 | drop index if exists | 使用存储过程实现create or replace procedure proc_dropindex (p_index in varchar2) as i_count number(10); begin select count(1) into i_count from user_indexes where index_name = upper(p_index); if i_count > 0 then execute immediate 'drop index '|| p_index ||''; end if; end; end; |
13 | drop table if exists | 使用存储过程实现create or replace procedure proc_droptable (p_table in varchar2) as t_count number(10); begin select count(1) into t_count from user_tables where table_name = upper(p_table); if t_count > 0 then execute immediate 'drop table '|| p_table ||' purge'; end if; end; |
14 | 有默认值字段是否可为空 | 设置默认值的字段取出是否可为空的定义 |
15 | unique clustered类型索引(聚簇索引) | 由于unique索引改为主键约束,而oracle自动在主键上建立索引,故不需要再单独建立索引,所以也改为主键约束即可 |
16 | unique索引 | 修改为表的主键约束 |
存储过程修改
序号 | 修改范围 | 修改方法 |
1 | 存在存储过程则删除 | 改为 create or replace procedure |
2 | 参数声明 | 去掉@符号,去掉未使用的参数 |
3 | errCode返回 | 声明err输出参数 |
4 | 结果集返回 | 返回游标,要求存储过程定义参数列表中含有该游标,使用时用open cursor for |
5 | 局部变量声明 | 去掉declare关键字,统一移动到begin关键字之前,且以分号隔开 |
6 | 赋值 | 将select xx = xx 改为:= |
7 | 若存储过程存在,则将执行该存储过程的权限授予另一用户 | 创建存储过程来完成此功能create or replace procedure proc_grant (proc_name in varchar2,user_name in varchar2) as p_count number(10); begin select count(1) into p_count from user_procedures where proc_name = upper(proc_name); if p_count > 0 then execute immediate 'grant execute on '|| proc_name ||' to '||user_name||''; end if; end; |
8 | 存储过程参数设置默认值 | 将=改为:= |
9 | select语句中为字段定义别名时,不可以使用单引号 | 删除单引号 |
10 | 临时表 | 建立oracle的事务级别的临时表 |
11 | 关键字禁止使用 | 重命名变量 |
12 | 返回查询的行数 | 使用select count 语句 |
13 | getdate()函数 | 改为sysdate |
14 | substring()函数 | substr() |
自定义函数修改
序号 | 修改范围 | 修改方法 |
1 | 存在则删除 | 改为create or replace function |
2 | 参数声明 | 去掉@符号 |
3 | returns | 改为return |
5 | select赋值 | oracle中一个select into只能为一个参数赋值,多个参数需要重复写select into语句 |
6 | 查询影响的行数 | rowcnt:=sql%rowcount; |
7 | convert函数 | 改为to_char函数 |
8 | dateadd(day)函数 | 改为+ |
9 | isnull函数 | 改为nvl函数 |
10 | ltrim和rtrim函数 | 改为trim函数 |
11 | isnumeric函数 | 利用regexp_like函数自定义udf_isnumeric函数 |
12 | 建立临时表并包含自增字段 | 将自增字段改为number(10)类型,插入时使用rownum |
13 | to_date函数的格式yyyy-mm-dd hh:mm:ss | 改为yyyy-mm-dd hh24:mi:ss(hh默认为12小时制,等同于hh12,若要24小时制,需要用hh24,分钟用mi) |