Java notes (1) - sql commonly used functions

A character function

Get the number of bytes 1.LENGTH-- parameter value

SELECT LENGTH('LALA');

Results: 4

2.CONCAT-- string concatenation

SELECT CONCAT('I','am','OK');

The results: IamOK

3.UPPER-- parameter capitalized

SELECT UPPER('abc');

The results: ABC

4.LOWER-- parameter lowercase

SELECT LOWER('ABC');

The results: abc

5.SUBSTR-- index starting from 1, and then returns the string specified position

SELECT SUBSTR('ABC',2);

The results: BC

SUBSTR-- taken starting at the specified index (second parameter), and after obtaining a string index position of the specified character length

SELECT SUBSTR('ABC',1,2);

The results: AB

6.INSTR-- returns the second parameter in the first parameter of the first occurrence of a position, if not occurred, it returns 0

SELECT INSTR('ABCD','CD');

Results: 3

7.TRIM-- removal of specified character from beginning to end, if not specified, then the removal of a space

SELECT SUBSTR('#','###ASD##123####');

Results: ASD ## 123

8.LPAD-- realization left to fill the specified length with the specified character, but also the result of the final length

SELECT LPAD('ABC',4,'#');

The results: #ABC

9.RPAD-- right padding to achieve a specified length with the specified characters, but also the results of the final length

SELECT LPAD('ABC',4,'#');

The results: ABC #

10.REPLACE-- replace all the specified string to another string

SELECT REPLACE('ABCABC','B','#');

The results: A # CA # C

 

Second, mathematical functions

1.ROUND-- rounding

SELECT ROUND(1.56);

Results: 2

ROUND-- preserve the specified number of decimal places

SELECT ROUND(3.1415926,2);

Results: 3.14

2.CEIL-- rounded up, returns greater than or equal to the smallest integer parameter

SELECT CEIL(-1.7836);

Result: -1

3.FLOOR-- rounded down, returns less than or equal to the greatest integer parameter

SELECT FLOOR(3.897);

Results: 3

4.TRUNCATE-- cut

SELECCT RUNCATE ( 1.668675 );

Results: 1.66

Modulo 5.MOD--

SELECT MOD(10,3);

Results: 1

 

Third, the date function

1.NOW-- returns the current date + time

SELECT NOW();

2.CURDATE-- Returns the current system date and time is not included

SELECT CURDATE();

3.CURTIME-- returns the current time, no date

SELECT CURTIME ();

4.MONTHNAME, DAYDATE etc. - return date English name

SELECT DAYDATE(NOW());

5.STR_TO_DATE-- string into a format specified by date

SELECT STR_TO_DATE('4-3#1998','%m-%d#%Y');

Results: 1998-04-03

6.DATE_FORMAT-- date into the specified format string

SELECT DATE_FORMAT(NOW(),'%m#%d#%Y');

Results: 09 # 04 # 2019

 

Third, other functions

The SELECT VERSION (); - obtaining sql version number
The SELECT  DATABASE (); - get the current location database name
The SELECT  the USER (); - for login user name

 

Fourth, the flow control function

……

 

Guess you like

Origin www.cnblogs.com/jaci/p/11462600.html