MySQL与Oracle 差异比较之七 其它
其它
编号 | 类别 | oracle | mysql | 注释 |
1 | 内连接的更改 |
1、 2、 |
方法一 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使用数组步骤: 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) |