NVL(EXPR1,EXPR2) NVL2(EXPR1,EXPR2,EXPR3) NULLIF(EXPR1,EXPR2) COALESCE(EXPR1,,..,EXPRn) decode --------NVL nvl(COMMISSION_PCT,0) 如果第一个参数为null,则返回第二个参数 如果第一个参数为非null,则返回第一个参数 经典示例:计算年薪(工资提成
NVL(EXPR1,EXPR2)NVL2(EXPR1,EXPR2,EXPR3)
NULLIF(EXPR1,EXPR2)
COALESCE(EXPR1,,..,EXPRn)
decode
--------NVL
nvl(COMMISSION_PCT,0)
如果第一个参数为null,则返回第二个参数
如果第一个参数为非null,则返回第一个参数
经典示例:计算年薪(工资+提成)
SELECT LAST_NAME,SALARY,NVL(COMMISSION_PCT,0),
(SALARY*12)+(SALARY*12*NVL(COMMISSION_PCT,0)) ANNUAL_SALARY
FROM EMPLOYEES
WHERE LAST_NAME='Matos';
--------NVL2
NVL2(COMMISSION_PCT,'SAL_COMM','SAL')
如果第一个参数为null,则返回第三个参数
如果第一个参数为非null,则返回第二个参数
经典示例:
SELECT LAST_NAME,SALARY,COMMISSION_PCT,
NVL2(COMMISSION_PCT,'SAL+COMM','SAL') INCOME
FROM EMPLOYEES
WHERE DEPARTMENT_ID IN (50,80);
---------NULLIF
nullif(length(first_name),length(last_name))
如果两个参数值相等,则返回 null
如果两个参数不等,则返回第一个表达式值
SELECT FIRST_NAME ,LENGTH(FIRST_NAME) "EXPR1",
LAST_NAME, LENGTH(LAST_NAME) "expr2",
nullif(length(first_name),length(last_name)) result
FROM EMPLOYEES;
---------COALESCE
COALESCE(EXPR1,EXPR2,EXPR3...EXPRn)
从左往右数,遇到第一个非null值,则返回该非null值。
多层判断
SELECT LAST_NAME,EMPLOYEE_ID,
COALESCE(TO_CHAR(commission_pct),TO_CHAR(manager_id),
'No commission and no manager')
FROM EMPLOYEES;
---------------------------------
-----------条件表达式
IF-THEN-ELSE
CASE 语句(SQL标准,编写繁杂)
DECODE 函数
DECODE(COL|EXPRESSION,SERACH1,RESULT1
[,search2,result2,...,]
[,default])
如果 search1 = expression 则返回 result1
如果 search2 = expression 则返回 result2
---------CASE
示例:
SELECT LAST_NAME,JOB_ID,SALARY,
CASE JOB_ID WHEN 'IT_PROG' THEN 1.10*SALARY
WHEN 'ST_CLERK' THEN 1.15*SALARY
WHEN 'SA_REP' THEN 1.20*SALARY
ELSE SALARY END "REVISED SALARY"
FROM EMPLOYEES;
---------DECODE
示例:
DECODE函数的作用:它可以将输入数值与函数中的参数列表相比较,根据输入值返回一个对应值。函数的参数列表是由若干数值及其对应结果值组成的若干序偶形式。当然,如果未能与任何一个实参序偶匹配成功,则函数也有默认的返回值。
区别于SQL的其它函数,DECODE函数还能识别和操作空值。
语法如下:
DECODE(control_value,value1,result1[,value2,result2…][,default_result]);
control _value
试图处理的数值。DECODE函数将该数值与后面的一系列的偶序相比较,以决定返回值。
value1
是一组成序偶的数值。如果输入数值与之匹配成功,则相应的结果将被返回。对应一个空的返回值,可以使用关键字NULL于之对应
result1
是一组成序偶的结果值。
default_result 未能与任何一个值匹配时,函数返回的默认值。
示例如下:
select decode( x , 1 , ‘x is 1 ’, 2 , ‘x is 2 ’, ‘others’) from dual
http://blog.csdn.net/xiangsir/article/details/8601513

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
