oracle笔记整理6——常见函数、scott解锁、length与lengthb、char与varchar

来源:互联网 发布:软件架构图分类 编辑:程序博客网 时间:2024/06/06 09:32

1) 常见函数

a) 当月最后一天:last_day(sysdate)

b) trunc(sysdate,’yy’):当年第一天
trunc(sysdate,’mm’):当月第一天
trunc(sysdate,’dd’):当前时间,精确到日
trunc(sysdate,’d’):上周末
trunc(sysdate,’hh’):当前时间,精确到小时
trunc(sysdate,’mi’):当前时间,精确到分钟

c) to_char(sysdate,’d’):今天是本周第几天(周日算第一天)
to_char(sysdate,’dd’):今天是本月的第几天
to_char(sysdate,’ddd’):今天是本年的第几天

d) replace函数:replace(source_str,search_str,replace_str)

e) 生成随机数函数:round(系数*dbms_random.value(0.5,1.0))

2) 解锁scott用户

a) alter user scott account unlock;

b) alter user scott identified by tiger;

c) scott/tiger 登陆

3) length与lengthb

length :字符长度
lengthb:字节长度
判断是否为汉字:length(x)!=lengthb(x)

4)char与varchar,varchar2,nvarchar

char:固定长度的字符。
varchar2:一般情况下所有字符都按两个字节处理,兼容性最好。
varchar:只对汉字等两个字节,数字、英文字符等都是一个字节。
nvarchar2:计算长度时跟字符集相关。

0 0