oracle語法轉mysql語法

2021-09-26 08:14:54 字數 2091 閱讀 7430

連線字串 || --> concat

decode --> case when else end

行轉列 wm_concat -->group_concat

nvl --> ifnull --> 通用 coalesce(字段,指定值)(返回括號裡第乙個不為null的資料,且字段值和指定值型別必須一樣)

nvl2 --> if ( isnull(欄位名) , 0 , 1 ) --> 通用case 字段 when null then 值2 when '' then 值2 else 值1 end as 別名;

sum,max --> 函式後面不能有空格

mysql不插入id,設定主鍵自增    (mysql主鍵自增,插入的時候不需要寫id.)

mysql設定主鍵自增

alter table  表名 change id id int auto_increment

full outer join   全連線mysql不支援   修改為  left  outer join + right  outer  join

update 語句的時候 set 不能帶括號

select distinct(concat(concat(t.sysno,'|'),t.parakey)) from pub_para t

str_to_date(date_format(date_sub(20190101,interval 60 day),'%y%m%d'),'%y-%m-%d')

改為 date_format(date_sub(sysdate(),interval 10 day),'%y%m%d')

minus --> not exists( ) 要求查詢出來的資料字段數量要一致.

update tablea set (a,b,b) = (select a,b,b from tableb where ...) where ...

mysql不支援這種寫法,改為

update tablea  left join tableb on ... set a=a,b=b,c=c where ...

to_date(『19000101000000『,『yyyymmddhh24miss『)改為select str_to_date(『1900-01-01 00:00:00『,『%y-%m-%d %h:%i:%s『),寫法略有差異:

date_format(date,『%y-%m-%d『) -------------->oracle中的to_char();

str_to_date(date,『%y-%m-%d『) -------------->oracle中的to_date();

說明:%y:代表4位的年份

%y:代表2為的年份

%m:代表月, 格式為(01……12)

%c:代表月, 格式為(1……12)

%d:代表月份中的天數,格式為(00……31)

%e:代表月份中的天數, 格式為(0……31)

%h:代表小時,格式為(00……23)

%k:代表 小時,格式為(0……23)

%h: 代表小時,格式為(01……12)

%i: 代表小時,格式為(01……12)

%l :代表小時,格式為(1……12)

%i: 代表分鐘, 格式為(00……59)

%r:代表 時間,格式為12 小時(hh:mm:ss [ap]m)

%t:代表 時間,格式為24 小時(hh:mm:ss)

%s:代表 秒,格式為(00……59)

%s:代表 秒,格式為(00……59)

to_number(varchar2 or char,』format model』)-->cast(11 as unsigned int) /*整型*/,cast(11 as decimal(10,2)) /*浮點型*/,cast("123" as signed integer),帶符號整型;

sysdate-->now() / sysdate()

注釋oracle -- mysql --空格.

oracle擷取字串的函式為:substr(欄位名,起始位置,字串長度) 起始位置可從0開始,擷取結果和從1開始一樣;

mysql擷取字串的函式為:substring(欄位名,起始位置,字串長度) 起始位置必須從1開始,0開始不能獲取到資料

怎麼查詢mysql的語法 MySQL查詢語法

select distinct productname from custom where product price between 5 and 10 order by product price desc product name limit 3 offset 1 limit 限定從1行開始選出...

mysql 索引語法 MySQL索引的基本語法

索引是排好序的資料結構!可以用在 where 條件查詢的字段,和order by 排序的字段,有了索引,便可以快速地定位資料所在的實體地址並找出來。索引的分類 1.普通索引 normal 沒有任何約束,主要用於提高查詢效率 2.唯一索引 unique 在普通索引的基礎上增加了資料唯一性的約束,可以有...

mysql索引語法 MySQL建立索引的語法

建立表時建立索引 語法 create table 表名 屬性名 資料型別 完整性約束條件 unique fulltext spatial index key 別名 屬性名 1 長度 asc desc 1 建立普通索引 create table index1 id int,name varchar 2...