ORACLE PL/SQL 字符串函数、数学函数、日期函数

2020腾讯云双十一活动,全年最低!!!(领取3500元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1074

【阿里云】双十一活动,全年抄底价,限时3天!(老用户也有),
入口地址https://www.aliyun.com/1111/home

推荐:oracle pl/sql函数大全(转)(四)

[62.MIN(DISTINCT|ALL)求最小值,ALL表示对所有的值求最小值,DISTINCT表示对不同的值求最小值,相同的只取一次 SQL> select min(all sal) from gao.table3; MIN(ALLSAL) ----

--【字符串函数】
--字符串截取substr(字段名,起始点,个数)
select Name,substr(Name,2,4),substr(Name,0,3),substr(Name,-2,3),substr(Name,-2,1) from t1;

--字符串从前面取三个(0开始)
select Name,substr(Name,0,3) from t1;
--字符串从后面取三个
select Name,substr(Name,-3,3),length(Name) 串长度 from t1;


SELECT ASCII('A'),ASCII('B') from dual;

select CHR(100),CHR(80) from dual;

select CONCAT(CHR(65),CONCAT(CHR(67),CHR(98))) from dual;

select CHR(65)||CHR(66)||CHR(76) from dual;

--将每个单词的第一个字母大写其它字母小写返回。
select INITCAP('substr,abc,substring') from dual;
--返回i在MISSISSIPPI中第3次出现的位置,
select INSTR('Mississippi','i',5,3) from dual;
select INSTR('Mississippi','i',-2,3) from dual;
--返回的是字节
select INSTRB('Mississippi','i',5,3) from dual;
select INSTRB('Mississippi','i',-2,3) from dual;
--长度
select length('WHO ARE YOU') from dual;
select nvl(null,'空') from dual;
--小写
select lower('WHo are You') from dual;
--LPAD左侧用字符串补足到一定长度
select LPAD('DFSDf................',9,'WHO') from dual;
select LPAD('DFSD',9,'WHO') from dual;
select LPAD('DFSD',9,'') from dual;
select LPAD('DFSD',length('DFSD')+length('WHO......'),'WHO......') from dual;
--把最左边的字符去掉,使其第一个字符不在其中
select ltrim('Mississippi','Mis') from dual;
select ltrim('Mississippi','miD') from dual;
--RPAD右侧用字符串补足到一定长度
select RPAD('DFSDf................',9,'WHO') from dual;
select RPAD('DFSD',9,'WHO') from dual;
select RPAD('DFSD',9,'') from dual;
select RPAD('DFSD',length('DFSD')+length('WHO......'),'WHO......') from dual;
--把最右边的字符去掉,

推荐:oracle 字符串格式的日期类型格式化的SQL 函数

[eg: to_date('2004-09','yyyy-mm-dd') to_date('" + sunday+ " 23:59:59', 'yyyy-mm-dd hh24:mi:ss') ]

使其第一个字符不在其中
select Rtrim('Mississippi','Mis') from dual;
select Rtrim('Mississippi','miD') from dual;
--替换
select REPLACE('uptown','up','down') from dual;
--substr和substrb
select SUBSTR('Message',1,4) from dual;
select SUBSTR('ABCDEFG',5) from dual;
select substrb('国际劳动节国营农场',5) from dual;
select substrb('国际劳动节国营农场',2) from dual;
select substrb('国际劳动节国营农场',4,8) from dual;
select substrb('国际劳动节国营农场',3,8) from dual;
--发音
select SOUNDEX('dawes') Dawes,SOUNDEX('daws') Daws, SOUNDEX('dawson') from dual;
--translate
select TRANSLATE('ABCDefghijklmn','eg','替代') test from dual;

select TRIM(' Space padded   0..o0..  ') trim from dual;

select UPPER('abDCCfasdfsdafasdf') from dual;

--【数学函数】所有函数都有数字参数并返回数字值。所有三角函数的操作数和值都是弧度而不是角度,
--oracle没有提供内建的弧度和角度的转换函数。
select abs(-10.234) from dual;
select acos(-1),acos(1) from dual;
select asin(1),asin(0) from dual;
select atan(1),atan(-1) from dual;
select ceil(-2),ceil(5.1) from dual;
select cos(-1) from dual;
select cosh(1) from dual;
select exp(3),exp(2),exp(1) from dual;
select Floor(-3.2),floor(5.91) from dual;
select LN(2) from dual;
select Log(10,2),log(2,10),log(10,1000) from dual;
select MOD(19,3),MOD(20,3),MOD(21,3) from dual;
select POWER(3,4),POWER(4,2) from dual;
select ROUND(12345,-2),ROUND(12345.54321,2),ROUND(-234234.9800234) FROM dual;
select SIGN(-10),SIGN(0),SIGN(1000) from dual;
select sin(1.57) from dual;
select sinh(2.34) from dual;
select SQRT(2),sqrt(3) from dual;
select TAN(1.2) from dual;
select TANH(2.32) from dual;
select trunc(2.2342342,5),trunc(2.3234234) from dual;

--【日期函数】操作DATE数据类型,绝大多数都有DATE数据类型的参数
--增加月
select sysdate,Add_MONTHS(sysdate,1),
Add_MONTHS(TO_Date('2008-05-31 18:18:18','yyyy-MM-dd HH24:MI:SS'),1),
Add_MONTHS(TO_Date('2008-05-31 18:18:18','yyyy-MM-dd HH24:MI:SS'),2)
from dual;
--每月最后一天 只区别了日期, 时间没有区别
select Last_day(sysdate) from dual;
--如果d1和d2的日的日期都相同,或者都使该月的最后一天,那么将返回一个整数,否则会返回的结果将

包含一个分数。
select MONTHS_BETWEEN(sysdate,To_Date('2008-05-31 14:40:00','yyyy-MM-dd HH24:MI:SS')) from

dual;

select NEW_TIME(sysdate,'GMT','PST') from dual;

select NEXT_DAY(To_Date('2007-06-04','yyyy-MM-dd'),'Monday') "1st Monday"
from dual;

select ROUND(sysDate,'yyyy'),ROUND(sysDate,'mm'),ROUND(sysdate,'dd'),
        ROUND(sysdate,'HH24'),ROUND(sysDate,'MI')
from dual;
select sysdate from dual;

select trunc(sysdate),trunc(sysdate,'HH24'),trunc(sysdate,'MI') from dual;

推荐:oracle pl/sql函数大全(转)(一)

[SQL中的单记录函数1.ASCII 返回与指定的字符对应的十进制数; SQL> select ascii('A') A,ascii('a') a,ascii('0') zero,ascii(' ') space from dual; A         A      ZER

相关推荐