Oracle
Oracle
日期
參考資料:(https://bbs.csdn.net/topics/70502638)
to_date('2005-08-01','yyyy-mm-dd')
狀況1
參考資料:(http://programdolt.iteye.com/blog/1186690)
select * from table where endDate>? and endDate<?sql修改成这样:
select * from table where endDate>to_date(?,’yyyymmddhh24miss’) and endDate<to_date(?,’yyyymmddhh24miss’);然后将传入参数格式化成对应格式的字符串在传入,这样由Oracle将字符串转成Date类型,就很顺利的走索引区间扫描,效率最高。
ORA-01818
可能同時用到 AM/PM 和 HH24 要擇一使用
ORA-01861
如何實作MSSQL中的TOP()
參考資料:(https://jackypan1989.wordpress.com/2012/08/08/sql-學習筆記-oracle-top-1-top-n-之語法/)
找出表格內的前100筆資料 TOP(100)
倘若想要搜尋結果(where) 後的100筆結果,就要外面再包一層
別名
Oracle 似乎表格的別名不能加 AS,但是欄位的名稱可以加AS
Primary Key vs Unique Index
參考資料:(https://tomkuo139.blogspot.com/2010/03/oracle-database-primary-key-unique.html)
Primary Key = Unique Index + Not null 若只有Unique Index 是可以為null。
Table 中,最多只能有一個 Primary Key, 但能擁有多個 Unique Index。
Primary Key 的字串不能有空格,Unique Index 的可以包含空格。
SQL語法
參考資料:(https://www.techonthenet.com/oracle/unique.php)
使用CREATE TABLE 創建 unique constraint
階層式查詢
參考資料:(https://dotblogs.com.tw/jeff-yeh/2009/05/20/8489) 參考資料:(https://www.cnblogs.com/ZHF/archive/2008/09/10/1288101.html)
如果where放在子查詢裡面,會中斷 (?,待實作)
Primary Keys
參考資料:(https://www.techonthenet.com/oracle/primary_keys.php)
注意
primary key 不能超過32 columns
可以在 create table 或 alter table 中定義primary key
CREATE
create table 的同時,建立primary key
如果Table 已經建出來了
使用 alter table 來建立 primary key
DROP
DISABLE
ENABLE
RENAME
INDEX
CREATE
一般建索引
基於函數的索引
參考資料:(https://bbs.csdn.net/topics/70502638)
RENAME
TABLE
RENAME
Column
add Column
新增一個型態為 varchar2 的欄位,而且要怎麼決定裡面的長度,是根據字元 & 位元
modify size 修改欄位長度
倘若要修改data type 則必須要用下列作法
(先搬走 > 更改 > 搬回來)
倘若是直接改大的話,就直接改就好
CLOB
CLOB 不能被拿來比較 UNION 和 MINUS 都不能用 UNION ALL 可以用
ALTER VIEW
(參考資料:https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_4004.htm)
Last updated
Was this helpful?