資料庫關鍵字,函式及語句使用
一.資料庫關鍵字
union,unon all(重複也顯示)
select into
Constraint 幾種約束 (check index)
二.幾種函式關鍵字(因資料庫的不同,會不一樣)
AVG() //UCASE()轉換為大寫 //lcase()
mid(column_name,start,len)start起始從1開始 len() round(欄位名,保留小數的位數)
now() getdate()
(1) sqlserver資料庫
format(列明,格式)
(2) oracle資料庫
upper(大寫) lower(小寫) initcap concat substr(擷取) length(長度) replace(替換) round trunc mod
months_between() add_months() next_day() last_day()
to_char() to_number()
nvl(string1,replace_string) decode(value,if1.then1)
三.詳細使用(以oracle為例)
1.自增序列
//auto-increment:oracle中,使用sequence
//sequence
CREATE SEQUENCE seq_person
MINVALUE 1 START WITH 1 INCREMENT BY 1 CACHE 10
//在資料庫表中使用
INSERT INTO Persons (P_Id,FirstName,LastName) VALUES (seq_person.nextval,'Lars','Monsen')
2.更改表的列名
ALTER TABLE Persons ALTER COLUMN Birthday year
3.根據表名,查詢列名
SELECT rownum,t.* FROM user_tab_columns t where t.table_name ='TEST_SCORE';
4.查詢並修改資料庫使用者密碼失效時間
SELECT * FROM dba_profiles WHERE profile='DEFAULT' AND resource_name='PASSWORD_LIFE_TIME';
修改: ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
5.case when then使用
select case (select count(*) from table1 where __)
when 0 then (select "" from dual)
else (select count(*) from table2 where __)
end from dual;