1. top order by 轉換成 rownum order by 的問題 (子查詢實現)
同級情況下的優先處理順序:
sqlserver: 先order by 再top
oracle: 先rownum 再 order by
2. 已有數據的字段類型不匹配,通過下列語句修改。
alter table css_sed rename column action to myaction;
alter table css_sed add (action varchar2(20));
update css_sed set action = myaction;
alter table css_sed drop column myaction;
3. 多個cast問題
isnull(cast(cast(GR_WT as int) as varchar),'') sqlserver
nvl(cast(trunc(cntr_row.GR_WT) as varchar2),'') plsql
4. if exists問題
oracle 沒有這個語法
解決方法: 拿一個臨時變量儲存結果來判斷
begin
select count(*) into V_CNT from all_tables where table_name = 'CUST_BC_ONLINE';
if(V_CNT > 0)
then
execute immediate 'truncate table CUST_BC_ONLINE';
end if;
end;
5. SqlServer: with index()語法問題
Oracle: 使用index hints實現 eg: select /*+ index(t i_t) */ * from t where username='EYGLE';
6. nvl(date,0) 問題
isnull(MCS_SHPT_INFO.LAST_MOD_DT,0) < b.LAST_MOD_DT
nvl(MCS_SHPT_INFO.LAST_MOD_DT,to_date('1900-01-01','yyyy-mm-dd'))) < b.LAST_MOD_DT
7. top 賦值問題
select top(5) @param = column from table
sqlserver默認會把最後一條數據的字段賦值給指定參數,oracle會報錯,就是選擇出來的行數不匹配。
8. declare的變量只能跟在後面的begin end 語句塊使用
9. 字符串拼接問題
oracle: null跟字符串拼接,會把null當成空字符串處理
sqlserver: null跟字符串拼接,會把整個字符串設置爲一個空格
10. Oracle異常信息打印
dbms_output.put_line(dbms_utility.format_error_stack());
dbms_output.put_line('----------------------------------------------------------------');
dbms_output.put_line(dbms_utility.format_call_stack());
dbms_output.put_line('----------------------------------------------------------------');
dbms_output.put_line(dbms_utility.format_error_backtrace());
dbms_output.put_line('----------------------------------------------------------------');
dbms_output.put_line(sqlcode);
dbms_output.put_line(sqlerrm);
11. SqlServer:select into 語法問題
SqlServer:
select into table2 from table1
備註:table2可以不存在
Oracle:
insert into table2 select * from table1
備註:要求table2必須存在