单行函数:只有一个参数输入,只有一个结果输出 多行函数或分组函数:可有多个参数输入,只有一个结果输出
测试lower/upper/initcap函数,使用dual哑表
select lower('www.BAIdu.COM') from dual;
select upper('www.BAIdu.COM') from dual;
select initcap('www.BAIdu.COM') from dual;
测试concat/substr函数,从1开始,表示字符,不论中英文
select concat('hello','你好') from dual;正确
select concat('hello','你好','世界') from dual;错误
select 'hello' || '你好' || '世界' from dual;正确
select concat('hello',concat('你好','世界')) from dual;正确
select substr('hello你好',5,3) from dual;
5表示从第几个字符开始算,第一个字符为1,中英文统一处理
3表示连续取几个字符
测试length/lengthb函数,编码方式为UTF8/GBK,一个中文占3/2个字节长度,一个英文一个字节
select length('hello你好') from dual;
select lengthb('hello你好') from dual;
测试instr/lpad/rpad函数,从左向右找第一次出现的位置,从1开始
select instr('helloworld','o') from dual; 注意:找不到返回0,大小写敏感
select LPAD('hello',10,'#') from dual;
select RPAD('hello',10,'#') from dual;
测试trim/replace函数
select trim(' ' from ' he ll ') from dual;
select replace('hello','l','L') from dual;
测试round/trunc/mod函数作用于数值型
select round(3.1415,3) from dual;
select trunc(3.1415,3) from dual;
select mod(10,3) from dual;
当前日期:
select sysdate from dual;
测试round作用于日期型(month)
select round(sysdate,'month') from dual;
测试round作用于日期型(year)
select round(sysdate,'year') from dual;
测试trunc作用于日期型(month)
select trunc(sysdate,'month') from dual;
测试trunc作用于日期型(year)
select trunc(sysdate,'year') from dual;