当前位置:网站首页>SQL greatest() function instance detailed example
SQL greatest() function instance detailed example
2022-07-04 10:57:00 【ths512】
SQL GREATEST() Function example detailed example https://www.cnblogs.com/pocketbook/p/6929676.html
1、 grammar
GREATEST(expr_1, expr_2, ...expr_n) Function from expression ( Column 、 Constant 、 Calculated value )expr_1, expr_2, ... expr_n Find out the largest number in and return . In comparison ,OracIe The data type of the expression is automatically compared , With expr_1 The data type of .
2、 Use location
Procedural statements and SQL sentence
3、 Example
Example 1 :
The number ——expr_1 It's numerical . Compare by size .
All values , Take the maximum 16:
SQL> SELECT GREATEST(2, 5, 12, 3, 16, 8, 9) A FROM DUAL;
A
----------
16
Part is numerical , But the string can be based on expr_1 The data type of is converted to numeric type by implicit type conversion :
SQL> SELECT GREATEST(2, '5', 12, 3, 16, 8, 9) A FROM DUAL;
A
----------
16
Part is numerical , However, if the string cannot be implicitly converted to a numeric type, an error will be reported , Because strings A Cannot be converted to numeric :
SQL> SQL>SELECT GREATEST(2, 'A', 12, 3, 16, 8, 9) A FROM DUAL;
SQL>SELECT GREATEST(2, 'A', 12, 3, 16, 8, 9) A FROM DUAL
ORA-00900: Invalid SQL sentence
Example 2 :
Character creation ——expr_1 It's character type . Compare by initials ( If equal, compare down )
All characters , Take the maximum G:
SQL> SELECT GREATEST('A', 'B', 'C', 'D', 'E', 'F','G') A FROM DUAL;
A
-
G
All characters , The initials are equal :
SQL> SELECT GREATEST('A', 'B', 'C', 'D', 'E','GA', 'GAB') A FROM DUAL;
A
---
GAB
Part is character type , Can convert characters to non characters :
SQL> SELECT GREATEST('A', 6, 7, 5000, 'E', 'F','G') A FROM DUAL;
A
-
G
Example 3 :
Time ——expr_1 Time type .
All time types :
SQL> SELECT GREATEST(TO_DATE('2014-08-01','YYYY-MM-DD'),TO_DATE('2017-08-01','YYYY-MM-DD')) A FROM DUAL;
A
-----------
2017/8/1
Part is time type , Implicit type conversion is not allowed :
SQL> SELECT GREATEST(TO_DATE('2014-08-01','YYYY-MM-DD'),'2017-08-01') A FROM DUAL;
SELECT GREATEST(TO_DATE('2014-08-01','YYYY-MM-DD'),'2017-08-01') A FROM DUAL
ORA-01861: Text does not match format string
Example 4 :
Null value —— When expr When it's a function , Inevitably, null values will be generated
expr_1 by NULL when :
SQL> SELECT GREATEST(NULL, 'B', 'C', 'D', 'E','GA', 'GAB') A FROM DUAL;
A
-
expr_1 Not for NULL when , The rest of the expr by NULL when :
SQL> SELECT GREATEST('A', 'B', 'C', 'D', 'E',NULL, 'GAB') A FROM DUAL;
A
-
From above, we can find , as long as GREATEST Of expr There is one for NULL, Will return to NULL.
边栏推荐
- Dictionaries and collections
- 守护进程Xinted和日志记录Syslogd
- Hidden C2 tunnel -- use of icmpsh of ICMP
- Swagger and OpenAPI
- [advantages and disadvantages of outsourcing software development in 2022]
- Locust installation
- Student achievement management system (C language)
- C language structure to realize simple address book
- /*Write a loop to output the elements of the list container in reverse order*/
- [Galaxy Kirin V10] [desktop] can't be started or the screen is black
猜你喜欢
Appscan installation steps
Introduction to Lichuang EDA
Unittest+airtest+beatiulreport combine the three to make a beautiful test report
C language structure to realize simple address book
How to use diff and patch to update the source code
[Galaxy Kirin V10] [server] KVM create Bridge
Elevator dispatching (pairing project) ②
Jianzhi offer 04 (implemented in C language)
JMeter Foundation
[Galaxy Kirin V10] [server] set time synchronization of intranet server
随机推荐
Canoe - the third simulation project - bus simulation - 3-1 project implementation
[Galaxy Kirin V10] [server] set time synchronization of intranet server
The bamboo shadow sweeps the steps, the dust does not move, and the moon passes through the marsh without trace -- in-depth understanding of the pointer
Digital simulation beauty match preparation -matlab basic operation No. 6
Function introduction of canbedded component
[untitled]
[Galaxy Kirin V10] [desktop] FTP common scene setup
2022 AAAI fellow release! Yan Shuicheng, chief scientist of sail, and Feng Yan, Professor of Hong Kong University of science and technology, were selected
Performance test method
Read a piece of text into the vector object, and each word is stored as an element in the vector. Convert each word in the vector object to uppercase letters. Output the converted elements in the vect
/*Write a function to open the file for input, read the contents of the file into the vector container of string class 8.9: type, and store each line as an element of the container object*/
[Galaxy Kirin V10] [desktop] cannot add printer
Network connection (II) three handshakes, four waves, socket essence, packaging of network packets, TCP header, IP header, ACK confirmation, sliding window, results of network packets, working mode of
Dichotomy search (C language)
Strings and characters
[Galaxy Kirin V10] [server] NUMA Technology
[testing theory] thinking about testing profession
Performance test overview
[Galaxy Kirin V10] [desktop] login system flash back
51 data analysis post