ORACLE MYSQL資料庫基礎知識備忘錄

2021-09-24 15:02:25 字數 2408 閱讀 4497

1、單引號包含的是char/varchar2字串,區分大小寫;另外,雙引號包含的是物件名,也區分大小寫(預設是大寫)

to_date('2005-01-01 13:14:20','yyyy-mm-dd hh24:mi:ss')不能用 to_date('2005-01-01 13:14:20','yyyy-mm-dd hh24:mm:ss')

原因是在to_date函式中mm不區分大小寫,會報ora 01810 格式**出現兩次

2、trunc() 用於擷取時間或者數值,返回指定的值

select  trunc(to_date('2018-07-01 1:00:00','yyyy-mm-dd hh:mi:ss'),'yyyy') from   dual ;--返回當年第一天

select trunc(to_date('2018-07-01 1:00:00','yyyy-mm-dd hh:mi:ss'),'mm') from dual ; --返回當月第一天

select trunc(to_date('2018-07-01 1:00:00','yyyy-mm-dd hh:mi:ss'),'dd') from dual ;--返回當前年月

select trunc(to_date('2018-07-01 1:00:00','yyyy-mm-dd hh:mi:ss'),'d') from dual ; --返回當前星期的第一天(星期日)

select trunc(to_date('2018-07-01 1:17:17','yyyy-mm-dd hh:mi:ss'),'hh') from dual ;--返回當前日期擷取到小時,分秒補0

select trunc(to_date('2018-07-01 1:17:17','yyyy-mm-dd hh:mi:ss'),'mi') from dual ;--返回當前日期擷取到分,秒補0

select  trunc(177.555) from  dual t; --預設取整 (177)

select trunc(177.555,2) from dual t; (177.55)

select trunc(177.555,-2) from dual t;--負數表示從小數點左邊開始擷取2位 (100)

3、oracle模糊查詢

select * from emp where instr(job, 'e') > 0;
1、查詢5月1號進件數量並用explain解析效能

type從最好到最差的連線型別為const、eq_reg、ref、range、index和all,一般來說,得保證查詢至少達到range級別,最好能達到ref。

extra列返回的描述的意義(using filesort ; using temporary: 看到這兩個的時候,查詢就需要優化了)

explain select count(1) from t_entry where create_time >= '2019-05-1' and create_time < '2019-05-2';
1、時間字段查詢比較

oracle: create_time > to_date('2005-01-01 13:14:20','yyyy-mm-dd hh24:mi:ss')

mysql: create_time > '2005-01-01 13:14:20'

原因是oracle對比較兩端的資料型別要求比較嚴格,一定要同型別,而mysql則自動幫我們轉成時間格式再比較

2、索引 index

--檢視索引

show index from t_entry;

-- 建立索引 (不寫內容預設普通索引,btree型別)

create [unique|fulltext|spatial] index index_name [using index_type] on table_name (index_col_name,...);

-- 刪除指定表中指定名稱的索引

alter table table_name drop index index_name;

-- 修改索引【先刪除,後建立】

3、找到離當前時間7天用

-- mysql找到離當前時間7天用

date_field_name > subdate(now(),interval 7 day);

-- oracle找到離當前時間7天用

date_field_name >sysdate - 7;

4、mysql中的concat函式可以連線多個字元,oracle使用concat只能連線兩個,oracle使用||連線多個字元,例如,select '1'||'2'||'3' from dual, 而mysql中的||則是或的意思,返回值是0或者1

oracle mysql資料庫分頁

mysql 分頁 groupunion.setpagestart pagestart groupunion.setpageend pageend selectunionlist groupunion selectunionlist resultmap baseresultmap parametert...

JDBC連線Oracle MySQL資料庫

在連線資料庫時,並不是所有的情況都適合使用hibernate等框架,比如單獨寫乙個報表服務,就需要使用簡單高效的jdbc來連線 1 資料庫連線jdbc原理 2 oracle class.forname class.forname oracle.jdbc.oracledriver string url...

ORACLE MYSQL資料庫的常用SQL命令

以下均是在建立乙個成功的連線後的操作。mysql資料庫在乙個連線下是通過不同的資料庫名稱來進行區分的,即乙個連線下可以有很多個庫 oracle資料庫連線時則是通過使用者名稱進行區分的,乙個使用者名稱下面只有乙個資料庫。1.返回某個資料庫 模式 中所有表的基本資訊 oracle資料庫 將yoursch...