当前位置:网站首页>Oracle built-in functions
Oracle built-in functions
2022-07-28 21:57:00 【Xiao Lei y】
Oracle Built in functions
1. Classification of built-in functions
- Built in functions :Oracle Self contained function , Just call it , No need to define
- Oracle The built-in functions are divided into the following categories :
- Conversion function ; Convert data types
- Date function ;
- Character functions ;
- Number function ;
- Set function ;
2. Conversion function
2.1 to_char();
- effect : Convert a non character type to a character type ;
-- Call the current system date
select sysdate from dual;
-- Date type to character type
-- Convert the current system time to string type , The time format is :xxxx-xx-xx xx:xx:xx
select to_char(sysdate,'yyyy-mm-dd hh:mi:ss') from dual;
-- Convert the current system time to string type , Only the date of the year is displayed , The time format is :xxxx-xx-xx
select to_char(sysdate,'yyyy-mm-dd')from dual;
-- Convert the current system time to string type , And the display is 24 hourly , The time format is :xxxx year xx month xx Japan xx:xx:xx
select to_char(sysdate,'yyyy" year "-mm" month "-dd" Japan " hh24:mi:ss') from dual
2.2 to_date();
- effect : Convert the time with large character type to date type ;
-- Put the character type time '2021-08-18' Convert to date type , The format is :xxxx/xx/xx;
select to_date('2021-08-18','yyyy/mm/dd') from dual
-- Put the character type time '2021-08-18 11:33:44' Convert to date type , The format is :xxxx/xx/xx xx:xx:xx;
select to_date('2021-08-18 11:33:44','yyyy/mm/dd hh:mi:ss') from dual
2.3 to_number();
- effect : Convert numbers of character type to numeric type ;
select 1+to_number('1') from dual;
3. Date function
3.1 add_months()
- effect : Add a specified number of months to the specified date , Find the current date ;
- Be careful : This can only work on date types ;
-- Find the current system time 100 The date after months ;
select add_months(sysdate,100) from dual;
-- seek 2020 year 8 month 8 Japan ,100 The date after months ;
select add_months(to_date('2020-8-8','yyyy-mm-dd'),-2) from dual;
-- seek 2020 year 8 month 8 Japan ,100 The date three months ago ;
select add_months(to_date('2020-08-08','yyyy-mm-dd'),-100)from dual;
3.2 extract()
- effect : Take the month, year and day in the date separately ;
- Be careful : It can only work with date type ;
-- Take the year of the current system time
select extract(year from sysdate)from dual;
-- Take the month of the current system
select extract(month from sysdate)from dual;
-- Take the current system time and date
select extract(day from sysdate)from dual;
-- seek emp table 2 Number of employees in the month
select count(*)from emp where extract(month from hiredate)=2;
-- seek emp The number of employees in each month in the table
select extract(month from hiredate),count(*)from emp group by extract(month from hiredate);
3.3 months_between()
- effect : Find the month of the difference between two times ;
- Be careful : Can only act on date types ;
-- seek 2020-2-2 The month that is different from the current system time ;
select months_between(sysdate,to_date('2017-02-02', 'yyyy/mm/dd')) from dual;
3.4 Last_day()
- effect : Ask for the last day of this month ;
-- Find the last day of the current month ;
select last_day(sysdate) from dual;
-- seek 2021 The last day of the year ;
select last_day(to_date('2021-12', 'yyyy-mm'))from dual;
3.5 Next_day()
- effect : Find the date of the next specified week ;
- Be careful : Can only act on date types ;
-- Find the date of next Saturday ;
select next_day(sysdate,' Saturday ')from dual;
4. Character functions
select upper('abcdAsdfa') from dual;
-- Capitalize all ;
select lower('abcdAsdfa') from dual;
-- All to lowercase ;
select trim('abcd','a') from dual;
-- Remove the left character ( The first character is a Then remove , On the contrary, do not remove );
select trim ('acccsdfdsccccbcd','c') from dual:
-- Remove the character on the right ( The first character is c Then remove , On the contrary, do not remove );
select initcap('adad') from dual;
-- Convert initials to uppercase ;
select substr('abcdefghi',3,4) from dual;
-- Cut from the third place , section 4 individual ;
select instr('abcdefg', 'c') from dual;
-- Judge c The location of , Subscript from 1 Start ;
select concat ('aa', 'bb') from dual;
-- This means splicing , Less use , Because we can use || Instead of ;
select ascii('a') from dual;
-- seek a Of ic code ;
select char(77) from dual;
-- take ic The code is converted into the corresponding value character ;
select length ('abcd Zhang ') from dual;
-- Find the number of characters , Not the number of bytes ;
select (pad ('abde' ,9,'x') from dual;
-- padding-left , Start from the left x’ fill , Until the length of bytes becomes 9 until ;
select rpad ('abde' ,9,'x') from dual;
-- Right fill , Start from the edge x fill , Until the length of bytes becomes 9 until ;
select decode('c', 'a',1,'b',2,'c',3) from dual;
-- The result is 3, It means to judge several results , If the preceding symbol is a It outputs 1, If it is b It outputs 2, If it is c It outputs 3;
5. Mathematical functions
select ceil (57.12) from dual;
-- Rounding up ;
select floor (57.98) from dual;
-- Don't round ;
select round (54.99) from dual;
-- The result is 55, rounding ;
select round (54.59,1) from dual;
-- Round to the nearest decimal point 1 digit ;
select power (3,2) from dual;
--3 Of 2 Power
select mod (6,7) from dual;
-- Remainder / model ;
select sqrt (4) from dual;
-- Square root ;
select sign (0) from dual;
-- If it is a positive number, the result is 1, If it is negative, the result is -1, If it is 0, The results for 0;
6. Comprehensive case
If the salary is less than 3500 It outputs “ Work hard ”, If it is equal to 3500 It outputs “ It is just fine ”, If it is greater than 3500 It outputs “ To pay taxes ”
select ename, decode(sign(sal-3500),1,' To pay taxes ',0,' It is just fine ',-1,' Work hard ')from emp;
7. Aggregate functions
7. Aggregate functions .
- sum, max, min, avg, count.
边栏推荐
- Vimtutor编辑
- 基于知识元的外文专利文献知识描述框架
- 世界肝炎日 | 基层也能享受三甲资源,智慧医疗系统如何解决“看病难”?
- How to search images efficiently and accurately? Look at the lightweight visual pre training model
- KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书
- Mesh data generation function meshgrid
- Leetcode linked list problem -- 142. circular linked list II (learn the linked list by one question and one article)
- Pytoch learning record (III): random gradient descent, neural network and full connection
- Which brand is the best and most cost-effective open headset
- Mysql的B+树高度计算
猜你喜欢
蚂蚁集团境外站点 Seata 实践与探索
HCIA综合实验(以华为eNSP为例)
No swagger, what do I use?
KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书
LeetCode·581.最短无序连续子数组·双指针
Talk about row storage and column storage of database
节省70%的显存,训练速度提高2倍!浙大&阿里提出在线卷积重新参数化OREPA,代码已开源!(CVPR 2022 )
凡尔赛天花板:“毕业两年月薪才35K,真是没出息啊~~”
管理区解耦架构见过吗?能帮客户搞定大难题的
Wechat applet development company, do you know how to choose?
随机推荐
这种动态规划你见过吗——状态机动态规划之股票问题(下)
基于对象的实时空间音频渲染丨Dev for Dev 专栏
Rhcsa first day
90. 子集 II
Miscellaneous records of powersploit, evaluation, weevery and other tools in Kali
中国农业工程学会农业水土工程专业委员会-第十二届-笔记
How does MySQL archive data?
How Oracle exports data (how Oracle backs up databases)
入行4年,跳槽2次,我摸透了软件测试这一行~
大学荒废三年,大四自学7个月测试,找到了12K的工作
Detailed explanation of JVM memory layout (glory collection version)
No swagger, what do I use?
[geek challenge 2019] secret file & file contains common pseudo protocols and gestures
Research on intangible cultural heritage image classification based on multimodal fusion
The Swedish court lifted the 5g spectrum auction ban on Huawei and ZTE
Log slimming operation: how to optimize from 5g to 1g! (glory Collection Edition)
MSI Bao'an factory is on fire! Official response: no one was injured, and the production line will not be affected!
Which brand is the best and most cost-effective open headset
Technology selection rust post analysis
MySQL