編號 |
類別 |
ORACLE |
MYSQL |
注釋 |
1 |
內串連的更改 |
1、 select a.*, b.*, c.*, d.* from a, b, c, d where a.id = b.id and a.name is not null and a.id = c.id(+) and a.id = d.id(+) "(+)"所在位置的另一側為串連的方向, 所以上面的例子1是左串連。 以下的例子2既是右串連。 2、 select a.*, b.*, c.*, d.* from a, b, c, d where a.id = b.id and a.name is not null and a.id(+) = c.id |
方法一 select a.*, c.*, d.* from a left join(c, d) on (a.id = c.id and a.id = d.id), b where a.id = b.id and a.name is not null 方法二 select a.*, c.*, d.* from a left join c on a.id = c.id left join d on a.id = d.id, b where a.id = b.id and a.name is not null |
oracle sql語句和mysql sql語句有一定的區別. 1. oracle左串連,右串連可以使用(+)來實現. Mysql只能使用left join ,right join等關鍵字. |
2 |
最後一句執行的sql statement所取得或 影響的條數 |
SQL%ROWCOUNT |
執行select語句後用: FOUND_ROWS() 執行update delete insert語句後用: ROW_COUNT(). |
oracle中: sql 表示最後一句執行的 SQL Statement, rowcount表示該 SQL 所取得或影響的條數. Mysql中: 執行select語句後查詢所影響的條數用: FOUND_ROWS() 執行update delete insert語句後查詢所影響的條數用: ROW_COUNT() |
3 |
查詢分頁 |
SELECT t1.* FROM (SELECT MSG_INT_KEY, MSG_TY, MSG_CD, ROWNUM ROW_NUM FROM SD_SYS_MSG WHERE (ii_msg_int_key IS NULL OR msg_int_key = ii_msg_int_key) ORDER BY MSG_CD ) t1 WHERE (in_page_no IS NULL) OR (t1.ROW_NUM > ((in_page_no -1)*li_per_page_amt) AND t1.ROW_NUM < (in_page_no*li_per_page_amt + 1) ); |
方法:使用迴圈變數替換oracle中ROWNUM set @mycnt = 0; SELECT (@mycnt := @mycnt + 1) as ROW_NUM,t1.* FROM (SELECT MSG_INT_KEY, MSG_TY, MSG_CD, ROWNUM ROW_NUM FROM SD_SYS_MSG WHERE (ii_msg_int_key IS NULL OR msg_int_key = ii_msg_int_key ) ORDER BY MSG_CD ) t1 WHERE (in_page_no IS NULL) OR (t1.ROW_NUM> ((in_page_no - 1) * li_per_page_amt) AND t1.ROW_NUM < (in_page_no * li_per_page_amt + 1) ); |
|
4 |
java null值 |
""作為參數傳入後,在oracle中將識別為null |
""作為參資料傳mysql還是"" |
現在java代碼需要修改: inPara.add(MSG_TY.equals("") ? null : MSG_TY); |
5 |
執行動態sql |
lv_sql := 'SELECT ' ||' distinct ' || iv_cd_field_name || ' FIELD1 '|| ' FROM ' || iv_table_name || ' WHERE ' || NVL(iv_where_cause,' 1=1 '); OPEN l_sys_cur FOR lv_sql; |
set @a = iv_cd_field_name; set @b = iv_table_name; set @c = IFNULL(iv_where_cause,' 1=1 '); SET @s = concat('SELECT distinct ', @a , ' FIELD1 FROM ' , @b , ' WHERE ' , IFNULL(@c,' 1=1 ')); PREPARE stmt3 FROM @s; EXECUTE stmt3; DEALLOCATE PREPARE stmt3; |
1. oracle可以將動態sql放在遊標中執行. mysql遊標聲明有一定的局限性: mysql遊標必須在聲明處理常式之前被聲明,並且變數和條件必須在聲明游標或處理常式之前被聲明。Mysql採用Prepared Statements實現動態sql. 例子如下: INT Emp_id_var = 56 PREPARE SQLSA FROM "DELETE FROM employee WHERE emp_id=?" ; EXECUTE SQLSA USING :Emp_id_var ; |
6 |
預存程序相互調用時傳遞數組 |
oracle使用數組步驟: 1. 將傳入的字串通過P_UNPACK_LIST方法轉換為數組.(lo_holiday_jan_upl即為數組) P_UNPACK_LIST(iv_jan__str, lv_delimiter, lo_holiday_jan_upl); 2. 傳數組到另一個預存程序. P_MOD_MONTH(iv_year, 1, lo_holiday_jan_upl, iv_user_cd); 3. P_MOD_MONTH中使用數組: (將數組中的各個元素取出來插入到SD_HOLIDAY表) FOR li_cnt IN 0 .. 9 LOOP IF iv_daystr(li_cnt) IS NOT NULL THEN INSERT INTO SD_HOLIDAY (HOLIDAY_INT_KEY, YEAR, MONTH, DAY, ENABLE_FLAG, CREATE_BY, CREATE_DATE, LAST_UPD_BY, LAST_UPD_DATE) VALUES (SEQ_HOLIDAY_INT_KEY.NEXTVAL, iv_year, iv_month, iv_daystr(li_cnt), 1, iv_user_cd, ld_sys_date, iv_user_cd, ld_sys_date); END IF; END LOOP; |
mysql中數用數組步驟: 1. 將需要處理的字串交給執行商務邏輯 的預存程序處理. CALL SD_HOLIDAY_P_MOD_MONTH(iv_year, 1, iv_jan__str, iv_user_cd); 2. SD_HOLIDAY_P_MOD_MONTH中處理字串. (將字串按自定格式分隔出來,在對每個小字串進行商務邏輯處理.) SET lv_inputstr = iv_inputstr; loopLable:LOOP IF li_cnt > 9 THEN LEAVE looplable; ELSE SET li_pos = INSTR(lv_inputstr, iv_delimiter); IF li_pos = 0 THEN leave looplable; ELSE set temp_str = SUBSTR(lv_inputstr, 1, li_pos - 1); /*插入temp_str到SD_HOLIDAY表*/ INSERT INTO SD_HOLIDAY(...) SET lv_inputstr = SUBSTRING(lv_inputstr, li_pos + LENGTH(iv_delimiter)); END IF; SET li_cnt = li_cnt+1; END IF; END LOOP loopLable; |
預存程序相互調用時傳遞數組解決方案: oracle中傳入12個字串到預存程序,然後將這12個字串轉換為12個數組,再調用其他預存程序並將這12個數組分別傳給預存程序,便利每個數組進行商務邏輯處理. mysql解決方案: 將預存程序中的數組去掉,兩個預存程序調用時直接傳遞字串,然後再需要處理商務邏輯的地方將字串分解,進行商務邏輯處理. 可以參考<<2009002-OTMPPS-Difficult Questions-0001.doc>> 中 2.4.2 逐層分解字串 |
7 |
Java無法以String來接取int |
select fac_unit_key FILED1在oracle可以 |
select fac_unit_key FILED1在mysql中要改 select CAST(fac_unit_key AS CHAR) FILED1 |
CAST(intvalue AS CHAR) |