数据库关键字,函数及语句使用

一.数据库关键字

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;

 

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值