select lower('www.BAIDU.com') from dual
select upper('www.baidu.com') from dual
select initcap('www.BAIdu.COM') from dual -- initcap(a) 单词首字母大写函数
select concat('hello','你好') from dual
select 'hello' || '你好' || '世界' from dual
select substr('hello你好',5,3) from dual;
--5表示从第几个字符开始算,第一个字符为1,中英文统一处理
--3表示连续取几个字符
select substr('abcde',3,2) from dual --针对字符 从1开始 不区分中英文
select length('hello你好') from dual; -- length(a) 返回a字符串字符的个数
select length('hello赵军') from dual
select lengthb('hello你好') from dual --lengthb(a) 返回a字符串字节的个数(一个汉字三个字节)
select instr('helloworld','ll') from dual --从左向右找第一次出现的位置,从1开始
--注意:找不到返回0 大小写敏感
--作用 用来判断某个字符或字符串在另一个字符串是否存在
select LPAD('hello',10,'#') from dual; --lpad(a,10,'#') 在a字符串左边追加多个 #
select lpad('6640',11,'*') from dual --应用: 隐藏手机号前多少位,隐藏密码
select RPAD('hello',10,'#') from dual;
select trim(' ' from ' he ll ') from dual; -- 去掉字符串两边空格
select trim(' hel l o ') from dual
SELECT TRIM (0 FROM 000987002348900) FROM DUAL; --去掉0 在 000xxx00 左右两边的字符 且自能截取一个字符
select trim('a' from 'acworaaldaaac') from dual
select replace('hello','l','L') from dual;
select replace('-9998','-9998','-') from dual --需求 亏损金额用 '-' 在前台展示
select round(3.1415,3) from dual; -- 四舍五入
select round(228.23458,4) from dual
select trunc(3.1415,3) from dual; --截取字符串
select mod(10,3) from dual; --取余数(取摩)
select mod(23,5) from dual
select sysdate from dual --2017-04-23 12:36:27
select round(sysdate,'month') from dual;
select round(sysdate,'year') from dual;
select trunc(sysdate,'month') from dual;
select trunc(sysdate,'year') from dual;
select sysdate-1 "昨天",sysdate "今天",sysdate+1 "明天" from dual;
select months_between('31-12月-17',sysdate) from dual;
select add_months(sysdate,1) from dual;
select add_months(sysdate,-1) from dual;
select next_day(sysdate,'星期三') from dual;
select next_day(next_day(sysdate,'星期三'),'星期三') from dual;
select next_day(next_day(sysdate,'星期三'),'星期日') from dual;
select last_day(sysdate) from dual;
select last_day(sysdate)-1 from dual;
select last_day(add_months(sysdate,1)) from dual;
select last_day(add_months(sysdate,-1)) from dual;
--1)日期-日期=天数
--2)日期+-天数=日期
select to_char(sysdate,'yyyy" 年 "mm" 月 "dd" 日 "day') from dual;
select to_char(sysdate,'yyyy"年"mm"月"dd"日" day') from dual
select to_char(sysdate,'yyyy-mm-dd"今天是"day hh24:mi:ss') from dual;
select to_char(sysdate,'yyyy-mm-dd"今天是"day HH12:MI:SS AM') from dual;
select to_char(1234,'$9,999') from dual;
select to_char(55555,'99,999') from dual
select to_char(1234,'L9,999') from dual;
select * from emp where hiredate = to_date('1980年12月17日','yyyy"年"mm"月"dd"日"');
或
select * from emp where hiredate = to_date('1980#12#17','yyyy"#"mm"#"dd');
或
select * from emp where hiredate = to_date('1980-12-17','yyyy-mm-dd');
select to_number('123') from dual; --字符串 转换成 数值型
/* case 字段
when 条件 then 表达式1
when 条件 then 表达式2
else 表达式n
end
*/
-- decode()函数
-- decode(字段,条件1,表达式1,条件2,表达式2,...表达式n)
-- 方式一:
select ename "姓名",job "职位",sal "涨前工资",
case job
when 'ANALYST' then sal+1000
when 'MANAGER' then sal+800
else sal+400
end "涨后工资"
from emp;
-- 方式二:
select ename "姓名",job "职位",sal "涨前工资",
decode(job,'ANALYST',sal+1000,'MANAGER',sal+800,sal+400) "涨后工资"
from emp;
select upper('www.baidu.com') from dual
select initcap('www.BAIdu.COM') from dual -- initcap(a) 单词首字母大写函数
select concat('hello','你好') from dual
select 'hello' || '你好' || '世界' from dual
select substr('hello你好',5,3) from dual;
--5表示从第几个字符开始算,第一个字符为1,中英文统一处理
--3表示连续取几个字符
select substr('abcde',3,2) from dual --针对字符 从1开始 不区分中英文
select length('hello你好') from dual; -- length(a) 返回a字符串字符的个数
select length('hello赵军') from dual
select lengthb('hello你好') from dual --lengthb(a) 返回a字符串字节的个数(一个汉字三个字节)
select instr('helloworld','ll') from dual --从左向右找第一次出现的位置,从1开始
--注意:找不到返回0 大小写敏感
--作用 用来判断某个字符或字符串在另一个字符串是否存在
select LPAD('hello',10,'#') from dual; --lpad(a,10,'#') 在a字符串左边追加多个 #
select lpad('6640',11,'*') from dual --应用: 隐藏手机号前多少位,隐藏密码
select RPAD('hello',10,'#') from dual;
select trim(' ' from ' he ll ') from dual; -- 去掉字符串两边空格
select trim(' hel l o ') from dual
SELECT TRIM (0 FROM 000987002348900) FROM DUAL; --去掉0 在 000xxx00 左右两边的字符 且自能截取一个字符
select trim('a' from 'acworaaldaaac') from dual
select replace('hello','l','L') from dual;
select replace('-9998','-9998','-') from dual --需求 亏损金额用 '-' 在前台展示
select round(3.1415,3) from dual; -- 四舍五入
select round(228.23458,4) from dual
select trunc(3.1415,3) from dual; --截取字符串
select mod(10,3) from dual; --取余数(取摩)
select mod(23,5) from dual
select sysdate from dual --2017-04-23 12:36:27
select round(sysdate,'month') from dual;
select round(sysdate,'year') from dual;
select trunc(sysdate,'month') from dual;
select trunc(sysdate,'year') from dual;
select sysdate-1 "昨天",sysdate "今天",sysdate+1 "明天" from dual;
select months_between('31-12月-17',sysdate) from dual;
select add_months(sysdate,1) from dual;
select add_months(sysdate,-1) from dual;
select next_day(sysdate,'星期三') from dual;
select next_day(next_day(sysdate,'星期三'),'星期三') from dual;
select next_day(next_day(sysdate,'星期三'),'星期日') from dual;
select last_day(sysdate) from dual;
select last_day(sysdate)-1 from dual;
select last_day(add_months(sysdate,1)) from dual;
select last_day(add_months(sysdate,-1)) from dual;
--1)日期-日期=天数
--2)日期+-天数=日期
select to_char(sysdate,'yyyy" 年 "mm" 月 "dd" 日 "day') from dual;
select to_char(sysdate,'yyyy"年"mm"月"dd"日" day') from dual
select to_char(sysdate,'yyyy-mm-dd"今天是"day hh24:mi:ss') from dual;
select to_char(sysdate,'yyyy-mm-dd"今天是"day HH12:MI:SS AM') from dual;
select to_char(1234,'$9,999') from dual;
select to_char(55555,'99,999') from dual
select to_char(1234,'L9,999') from dual;
select * from emp where hiredate = to_date('1980年12月17日','yyyy"年"mm"月"dd"日"');
或
select * from emp where hiredate = to_date('1980#12#17','yyyy"#"mm"#"dd');
或
select * from emp where hiredate = to_date('1980-12-17','yyyy-mm-dd');
select to_number('123') from dual; --字符串 转换成 数值型
/* case 字段
when 条件 then 表达式1
when 条件 then 表达式2
else 表达式n
end
*/
-- decode()函数
-- decode(字段,条件1,表达式1,条件2,表达式2,...表达式n)
-- 方式一:
select ename "姓名",job "职位",sal "涨前工资",
case job
when 'ANALYST' then sal+1000
when 'MANAGER' then sal+800
else sal+400
end "涨后工资"
from emp;
-- 方式二:
select ename "姓名",job "职位",sal "涨前工资",
decode(job,'ANALYST',sal+1000,'MANAGER',sal+800,sal+400) "涨后工资"
from emp;
276

被折叠的 条评论
为什么被折叠?



