BayaiM__ oracle函数_01

时间:2022-04-01 08:50:40

BayaiM__ oracle函数_01

 
Oracle函数
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

行函数:
--ABS求绝对值
SELECT ABS(-1) FROM DUAL;

--SQRT求平方根
SELECT SQRT(361) FROM DUAL;

--POWER求m的n次幂
SELECT POWER(2,10), FROM DUAL;

--COS求弧度的余弦值
SELECT COS(3.1415) FROM DUAL;

--ARCCOS求弧度
SELECT ACOS(1) FROM DUAL;

--SIN求弧度的正弦值
SELECT SIN(3.1415) FROM DUAL;

--ARCSIN求弧度
SELECT ASIN(1) FROM DUAL;

--MOD求余数
SELECT MOD(100,90) FROM DUAL;

--CEIL进一圆整
SELECT CEIL(100.5) FROM DUAL;

--FLOOR去尾圆整
SELECT FLOOR(10.1) FROM DUAL;

--ROUND四舍五入取整
SELECT ROUND(10.1234,3) FROM DUAL;

--EXP求e的n次方
SELECT EXP(2) FROM DUAL;

--LN求e的对数
SELECT LN(20) FROM DUAL;

--LOG求对数
SELECT LOG(2,4) FROM DUAL;

--取当前日期
SELECT SYSDATE FROM DUAL;

--将ROWID转换为CHAR
SELECT ROWIDTOCHAR(ROWID) FROM SCOTT.EMP;

--将CHAR转换为ROWID
SELECT * FROM SCOTT.EMP WHERE ROWID=CHARTOROWID('AAAMfPAAEAAAAAgAAN');

--TRUNC截断取整
SELECT TRUNC(10.123456,5) FROM DUAL;

--求字符对应的ASCII码
SELECT ASCII('C') FROM DUAL;

--求ASCII码对应的字符
SELECT CHR(50) ROM DUAL;

--转换成小写
SELECT LOWER('ABCD') FROM DUAL;

--转换成大写
SELECT UPPER('abcd') FROM DUAL;

--将每个单词首字母大写
SELECT INITCAP('abcd efg') FROM DUAL;

--截取子串

SELECT SUBSTR('ABCDEFG',2,4) FROM DUAL;  --从左向右

SELECT SUBSTR('ABCDEFG',-1,3) FROM DUAL;  --从右向左

--求字符串长度

SELECT LENGTH('12345') FROM DUAL;

--求出现位置,给定母串,子串,起始位置,次数

SELECT INSTR('ABCDEFGE','E',4,1) FROM DUAL;

--向左补齐
SELECT LPAD('A',10,'B') FROM DUAL;

--向右补齐
SELECT RPAD('A',10,'B') FROM DUAL;

--去空格

SELECT TRIM(' ABC ') FROM DUAL;

SELECT LTRIM(' ABC ') FROM DUAL;

SELECT RTRIM(' ABC ') FROM DUAL;

--TO_DATE转换为日期

SELECT TO_DATE('2012-01-02','yyyy-MM-dd') FROM DUAL;

--求两个日期间的月份

SELECT MONTHS_BETWEEN(TO_DATE('2012-01-01','yyyy-MM-dd'),TO_DATE('2012-02-01','yyyy-MM-dd')) FROM DUAL;

--给日期加上一个自然月
SELECT ADD_MONTH(TO_DATE('2012-01-01','yyyy-MM-dd'),2) FROM DUAL;

--求下一天
SELECT NEXT_DAY(TO_DATE('2012-01-01','yyyy-MM-dd')) FROM DUAL;

--求指定日期所在月的最后一天
SELECT LAST_DAY(TO_DATE('2012-01-01','yyyy-MM-dd')) FROM DUAL;

--对日期四舍五入
SELECT ROUND(TO_DATE('2012-01-01','yyyy-MM-dd'),'YEAR') FROM DUAL;
SELECT ROUND(TO_DATE('2012-01-01','yyyy-MM-dd'),'MONTH') FROM DUAL;
SELECT ROUND(TO_DATE('2012-01-01','yyyy-MM-dd'),'DAY') FROM DUAL;

--对日期截断
SELECT TRUNC(TO_DATE('2012-01-01','yyyy-MM-dd'),'YEAR') FROM DUAL;
SELECT TRUNC(TO_DATE('2012-01-01','yyyy-MM-dd'),'MONTH') FROM DUAL;
SELECT TRUNC(TO_DATE('2012-01-01','yyyy-MM-dd'),'DAY') FROM DUAL;

--NVL空值转换,如果不是空就直接返回,如果是空就返回指定值
SELECT NVL(NULL,'A') FROM DUAL;

--DECODE条件输出转换
SELECT DECODE(1,1,'A',2,'B') FROM DUAL;

--TO_CHAR转换为字符串
SELECT TO_CHAR(SYSDATE,'yyyy-MM-dd hi24:mi:ss) FROM DUAL;

--TO_NUMBER字符转换为数字
SELECT TO_NUMBER('123') FROM DUAL;

--UID当前用户ID
SELECT USERNAME, USER_ID FROM DBA_USERS WHERE USER_ID = UID;

--分支
SELECT (CASE WHEN DUMMY='X' THEN 0 ELSE 1 END) FROM DUAL;

聚集函数:
--MAX 最大值

--MIN 最小值

--AVG 平均值

--STDDEV 标准差

--VARIANCE 协方差

--COUNT 计数