15.concat(str1,str2) 连接字符串
只能有两个参数,如果需要多个字符串连接必须函数嵌套
select concat(concat('abc','efg'),'hij')
from dual
select 'abc'||'efg'||'hij'
from dual
16.to_single_byte(str) 转半宽
17.to_multi_byte(str) 转全宽
select 'a',to_multi_byte('我'),to_single_byte('a')
from dual
一个全宽的英文字母占一个字符长度或两个字节长度
--日期函数
1.sysdate 当前系统时间
select sysdate
from dual
日期的运算规则
日期加减数字=日期加减天数
日期-日期=日期间相差的天数
日期+日期=错误
日期*日期=错误
日期/日期=错误
select date'2021-7-8'-date'2021-5-1',sysdate+1
from dual
--查询一天后,一个小时后,一分钟后,一秒后的日期
select sysdate+1,sysdate+1/24,sysdate+1/24/60,sysdate+1/24/60/60
from dual
天:加减数字
小时:小时数/24
分钟:分钟数/24/60
秒:秒数/24/60/60
--查询距离2022年元旦还有多少天
--查询今天是2021年的第几天
--查询10000天前的日期
select date'2022-1-1'-sysdate A,
sysdate-date'2021-1-1' B,
sysdate-10000
from dual
--转换函数 数据类型之间的相互转换
1.ascii(str) 将字符转为对应的阿斯克码 字符型→数值型
只会将字符串的第一个字符转为阿斯克码
select ascii('abc')
from dual
大写字母:65-90
小写字母:97-122
对应的小写字母比大写字母多32
2.chr(数) 将阿斯克码转为对应的字符 数值型→字符型
select chr(65)
from dual
--查询员工表S开头的员工姓名(请用四种方法)
1. select ename
from emp
where ename like 'S%'
2. select ename
from emp
where instr(ename,'S',1,1)=1
3. select ename
from emp
where substr(ename,1,1)='S'
4. select ename
from emp
where ascii(ename)=ascii('S')
3.to_number(str) 将纯数字的字符串转为数值型 字符型→数值型
select to_number('123456')
from dual
4.to_date(str,'格式') 按照日期格式把字符串转为日期 字符型→日期型
yyyy 年
mm 月
dd 日
hh|hh12 12小时制的小时
hh24 24小时制的小时
mi 分钟
ss 秒
select to_date('2020-3-2 12:24:32','yyyy-mm-dd hh24:mi:ss')
from dual
--如果日期格式只写一部分
yyyy 本月的第一天
mm 本年1号
dd 本年本月
hh/mi/ss 本月1号
select to_date('2020','yyyy'),to_date('3','mm'),to_date('15','dd')
from dual
--查询2019-1-2 12:00
select to_date('2019-1-2 12:00','yyyy-mm-dd hh24:mi')
from dual
--查询今年的5月2号 下午1:30
select to_date('2021-5-2 13:30','yyyy-mm-dd hh24:mi')
from dual
select to_date('5-2 13:30','mm-dd hh24:mi')
from dual
--查询本月1号 中午12:00:01
select to_date('12:00:01','hh24:mi:ss')
from dual
本文介绍了PLSQL中的字符串连接函数concat、转换函数如to_single_byte、to_multi_byte,以及日期函数sysdate的使用。还详细讲解了日期的运算规则和转换函数,包括ascii、chr、to_number和to_date的用法,并给出了实际操作示例。
518

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



