当前位置:网站首页>Study notes 22/1/11
Study notes 22/1/11
2022-06-28 07:44:00 【Zeiyalo】
Function learning
1.trim() function
(1)trim()
grammar 1:trim([LEADING | TRAILING | BOTH [ str1] from] str2)
effect : Delete the space around the string
Parameters :
leading | trailing | both from : These prefixes specify the deletion part ,leading from The prefix is to delete the previous part ,trailing from Is to delete the following part ,both from Is to delete both before and after ;
str1: Characters to be deleted , Do not write default delete space
str2: Target string
notes :trim The specified characters can be deleted , But only a single character can be specified , Cannot specify string ;
eg: Delete the corresponding string ‘ WUHUQIFEI ’ Spaces at both ends
SELECT TRIM(' WUHUQIFEI ') "TRIM EG"
FROM DUAL;
eg: Delete the corresponding string ‘ AAAAWUHUQIFEIAAAA’ The one in front of the middle A
SELECT TRIM(leading 'A' FROM 'AAAAWUHUQIFEIAAAA') "TRIM EG"
FROM DUAL;
(2)ltrim() And rtrim() function
grammar :ltrim | rtrim(str1 , str2)
effect : Delete str1 The left or right exists in the character set str2 The characters in
Parameters :
str1: Target string
str2: Character set
Return value : Returns a string after deletion ( Character type )
eg: Delete string ’xyxxDWEYExyyx’ The one on the right in the middle x And y
select rtrim('xyxxDWEYExyyx','xy') "e.g." from dual;
notes : Pay attention to ltrim() Function and rtrim The second argument to the function is the character set , It is a character set regardless of order ;
2.ROUND() Function and trunc() function
(1) When used with numeric data types :
a.round() function
grammar :round(num1 [,num2])
effect : Yes num1 according to num2 To round ,num2 If it is not written, it will be rounded to decimal by default
Parameters :
num1: Target parameters
num2: How many digits to round
When it is greater than zero , Count from the right of the decimal point
When it's zero , Round to an integer
When it's less than zero , Count from the left of the decimal point
Do not write default to zero
Return value : Returns the number after rounding ( Numeric type )
b.trunc() function
grammar :trunc(num1 , num2 )
effect : Yes num1 Intercept the specified num2 The number of
Parameters :
num1: Target parameters
num2: Intercepts the specified location
If it's a positive number , Intercept from the decimal point ( Such as 1.5555 3 Is intercepted as 1.555)
If it is zero or not written , Is truncated to an integer
If negative , Then intercept the positive part ( Such as 1136.8418 -2 The result is 1100)
Return value : Return the intercepted data (number type )
(2) When used with date types :
a.round() Use of functions
grammar :round(date,’ Format ’)
effect : Round off in the following format date date
Parameters :
date: Date of operation
Format : The format is shown in the note below , Different formats correspond to different latest target dates
Return value : Returns the most recent date (date type )
eg: If “YEAR” Round to the year's 1 month 1 Japan , The first half of the year , The second half of the year is the next year
SELECT ROUND(TO_DATE('20210719','YYYYMMDD'),'YEAR') second half of a year
,ROUND(TO_DATE('20210425','YYYYMMDD'),'YEAR') The first half of the year
FROM DUAL;
notes : The keyword correspondence used to define the format in the following single quotation marks :
‘YEAR’– Returns the most recent year , In the first half of the year, it returns to January 1 at the beginning of this year , The second half of the year returns to January 1 of the following year ;
‘MONTH’– Returns the most recent month , The first half of the month returns to the first day of the month , The latter half of the month returns to January 1 of the next month ;
‘DDD’– Return to the last day
‘DAY’– Return to the most recent Sunday
‘W’– Returns the most recent and operation date The first day of the month has the same number of weeks
‘IW’– Return to the most recent Monday
SELECT ROUND(TO_DATE('20210719','YYYYMMDD'),'YEAR') year
,ROUND(TO_DATE('20210425','YYYYMMDD'),'MONTH') month
,ROUND(TO_DATE('20210425','YYYYMMDD'),'Q') quarter
,ROUND(TO_DATE('20210425','YYYYMMDD'),'DD') Japan --DDD It is also the abbreviation of day
,ROUND(TO_DATE('20210425','YYYYMMDD'),'DDD') Japan
,ROUND(TO_DATE('20210425','YYYYMMDD'),'DAY') Sunday
,ROUND(TO_DATE('20210425','YYYYMMDD'),'W') Thursday
,ROUND(TO_DATE('20210425','YYYYMMDD'),'IW') Monday
FROM DUAL;
b.trunc() function
grammar :trunc(date,‘ Format ’)
effect : Intercept the date
Parameters :
date: Operated date data
Format : Format and round Basic generality of
When the year is intercepted , Intercepted to January 1 of this year
When the quarter is intercepted , Intercept to the first day of this quarter
When the month is intercepted , Intercept to the first day of this month
Be careful :
Talk about interception
3.replace() Function and translate() function
grammar :replace( Field , str1 , str2)
effect : Put the... Contained in the field str1 Replace the part of with str2 character
4. Fill function
(1)lpad() function
(2)rpad() function
5.ASCII() Function and CHR() function
(1)ASCII() function
grammar :ASCII(str)
effect : Read str Of ASCII Code value
Parameters :
str: Target character or string
Return value : Returns the of the objective function ASCII Code value ( Integer types )
eg:ASCII(x) Return character x Of ASCII code .
SELECT ASCII('C') FROM DUAL;
SELECT ASCII('a') FROM DUAL;
eg: When str When it's a string , The first letter is returned ASCII code
SELECT ASCII('AB') FROM DUAL;
SELECT ASCII('CBA') FROM DUAL;
(2)CHR() function
grammar :CHR(int)
effect : Output ASCII The code value is equal to int The characters of
Parameters :
int: An integer
Return value : return ASCII Code for int A character of ( Character type )
eg: Output ASCII The code value is equal to 65 The characters of
SELECT CHR(65) FROM DUAL;
notes :ASCII The code table has only 128 position , When int Greater than 127 when ,
Due to the expansion of character coding system , At this time, the corresponding display is GBK code (《 Code extension specification for Chinese characters 》), So it won't overflow , It shows GBK Some characters in the code ;
eg: Show GBK Code for 777 The characters of ;
SELECT CHR(777) FROM DUAL;
6.instr() function
grammar :instr( Field name ,str1[,pos] [,nth])
effect : Find... In the corresponding field str1 String location
Parameters :
Field name : Target field
str1: Specified to match characters or strings
pos: Where to start matching , Do not write default is 1, When pos When it is equal to a negative number, it is from the penultimate pos Bits count from back to front
nth: Refers to the number of times the specified matching string needs to appear
Return value : Returns the position of the matched character or string
eg: stay "helloworld" The last of 1(d) No. 1 position starts , Look back for the second time “l” The location of
select instr('helloworld','l',-1,2) from dual;
7.substr() function
grammar :substr(str,pos[,len ])
effect : stay str In the from pos Characters start to be intercepted backwards len A character long string ;
Parameters :
str: Intercepted string
pos: Where to start intercepting , When it's negative , Number from last string , Such as -3 Is to intercept from the penultimate position
len: How long is the interception , Do not write default intercept to the end
Return value : Return from str The string intercepted in the middle ( Character type )
notes :substr() When the function intercepts a string, it always intercepts it from front to back , Even in the middle pos The argument is negative , It is also intercepted from front to back ;
Another way ,substr() The execution of a function is , Get the target string first str, And then according to pos Starting number ( Negative numbers are counted from the back to the front ), After the reservation, start from pos Start from front to back ;
eg: Find out that the first letter of the name is A The employees'
SELECT *
FROM EMP E
WHERE SUBSTR(E.ENAME,1,1) = 'A' ;
eg: Use one sql Statement to extract the city information of each person
CREATE TABLE zone (
name VARCHAR2(20),
address VARCHAR2(50)
);
INSERT INTO zone VALUES(' Zhang San ',' hubei - yichang - Five peaks ');
INSERT INTO zone VALUES(' Li Si ',' Inner Mongolia - Hohhot, - Qingshuihe ');
INSERT INTO zone VALUES(' Xiao Ming ',' guangdong - Shenzhen - Bao'an ');
COMMIT;
SELECT A.NAME,
SUBSTR(SUBSTR(A.ADDRESS,INSTR(A.ADDRESS,'-')+1),1,
INSTR(SUBSTR(A.ADDRESS,INSTR(A.ADDRESS,'-')+1),'-')-1) CITY
FROM ZONE A;
Subquery review
边栏推荐
猜你喜欢

ACM笔记

Section 8: DMA of zynq

Section VI UART of zynq

Introduction and several months' experience of extending the solution thanos of Prometheus

剑指Offer||:链表(简单)

Mysql57 zip file installation

Application and Optimization Practice of redis in vivo push platform

In idea, the get and set methods may be popular because the Lombok plug-in is not installed

异或的应用。(提取出数字中最右侧的1,面试中经常用的到)

推荐系统系列精讲(第五讲): 排序模型的调优实践
随机推荐
kubernetes部署thanos ruler的发送重复告警的一个隐秘的坑
Section VII starting principle and configuration of zynq
DBeaver 22.1.1 发布,可视化数据库管理平台
Understanding of OPC protocol
卸载重装最新版mysql数据库亲测有效
The solution of "user account control to continue, please enter administrator user name and password" appears in win10 Professional Edition
At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
逆波兰表达式求值<难度系数>
Disposition Flex
asp. Net to search products and realize paging function
linux下修改mysql用户名root
一个小工具可以更快的写爬虫
Drawing animated bubble chart with R language
pip 更新到最新的版本
R language ggmap
Mysql8.0 and mysql5.0 accessing JDBC connections
Is it safe for flush to open an account online
HJ成绩排序
安全培训是员工最大的福利!2022新员工入职安全培训全员篇
kubernetes集群命令行工具kubectl