Data application master's SQL basic tutorial sharing 11-Scalar function

Scalar function

4. Scalar function

1. What is Scalar function

【Introduction to knowledge points】

Scalar function, Chinese can be called scalar function, this type of function also returns only one value, but the function is only oriented to a single value, and the returned value is also based on the change or processing of the single value.
Based on usage, we divide Scalar functions into three categories:
one is text processing functions: functions that operate on text and characters.
The second is numerical processing functions: functions that operate on numerical values.
The third is the time processing function: a function that operates on time.
Next, let's take a closer look at what common functions they have.

2. Text processing functions

【Introduction to knowledge points】

Text processing functions, as the name suggests, are functions that return a value by manipulating text. for example:

 

Text processing function Description
UCASE( )\UPPER( )     Convert to uppercase string
LCASE( )\LOWER( )             Convert to lowercase string
LENGTH( )     Calculate the length of a string
LEFT( )     Returns the character to the left of the string
RIGHT( )     Returns the character to the right of the string

 

【Example】

Output student IDs whose names begin with K, and uppercase names.
Select the ID and SName columns in the table and use the UCASE or UPPER function on the SName column.

SELECT ID,UCASE(SName) FROM Student
WHERE SName LIKE 'K%';

 

3. Numerical processing functions

【Introduction to knowledge points】

The numerical processing functions in Scalar are similar to the functions of the mathematical modules of other computer languages. They are mainly used in some algebraic and geometric operations in SQL, and are relatively less commonly used in databases.
The more common numerical processing functions are:

 

Numerical Processing Function Description
ABS( )         Returns the absolute value of the number
PI( )         return pi
COS( )         Returns the cosine of an angle
WITHOUT( )         Returns the sine of an angle
SQRT( )         Returns the square root of a number
EXP( )         Returns the exponent value of the number

 

4. Time processing function

【Introduction to knowledge points】

The time processing function is a time-based processing function, and the returned value is generally time.
The most common time-handling function is NOW( ), which returns the current time of the system. (If you want to know more about time processing functions, you may wish to search for information online)

【Example】

Try the NOW( ) function in action.

SELECT ID,SName,NOW() FROM Student
WHERE Credit > 28;

 

To be continued below. . . . . .

 

Welcome to visit our official website:

http://www.datanew.com/datanew/homepage

http://www.lechuangzhe.com/homepage

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326228224&siteId=291194637