如何使用oracle的decode函数进行多值判断

硪商尛冲

硪商尛冲

2016-02-19 15:40

下面是个简单易学的如何使用oracle的decode函数进行多值判断教程,图老师小编详细图解介绍包你轻松学会,喜欢的朋友赶紧get起来吧!

Decode函数的语法结构如下:
decode (expression, search_1, result_1)decode (expression, search_1, result_1, search_2, result_2)decode (expression, search_1, result_1, search_2, result_2, ...., search_n, result_n)decode (expression, search_1, result_1, default)decode (expression, search_1, result_1, search_2, result_2, default)decode (expression, search_1, result_1, search_2, result_2, ...., search_n, result_n, default)
 
decode函数比较表达式和搜索字,如果匹配,返回结果;如果不匹配,返回default值;如果未定义default值,则返回空值。
以下是一个简单测试,用于说明Decode函数的用法:

 SQL create table t as select username,default_tablespace,lock_date from dba_users;

Table created

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)

SQL select * from t;

USERNAME                       DEFAULT_TABLESPACE             LOCK_DATE
------------------------------ ------------------------------ -----------
SYS                            SYSTEM                        
SYSTEM                         SYSTEM                        
DBSNMP                         SYSTEM                        
SCOTT                          SYSTEM                        
OUTLN                          SYSTEM                         2007-7-30 1
WMSYS                          SYSTEM                         2007-7-30 1
ORDSYS                         SYSTEM                         2007-7-30 1
ORDPLUGINS                     SYSTEM                         2007-7-30 1
MDSYS                          SYSTEM                         2007-7-30 1
CTXSYS                         DRSYS                          2007-7-30 1
XDB                            XDB                            2007-7-30 1
ANONYMOUS                      XDB                            2007-7-30 1
WKSYS                          DRSYS                          2007-7-30 1
WKPROXY                        DRSYS                          2007-7-30 1
ODM                            ODM                            2007-7-30 1
ODM_MTR                        ODM                            2007-7-30 1
OLAPSYS                        CWMLITE                        2007-7-30 1
RMAN                           TOOLS                          2007-7-30 1
HR                             EXAMPLE                        2007-7-30 1
OE                             EXAMPLE                        2007-7-30 1

USERNAME                       DEFAULT_TABLESPACE             LOCK_DATE
------------------------------ ------------------------------ -----------
PM                             EXAMPLE                        2007-7-30 1
SH                             EXAMPLE                        2007-7-30 1
QS_ADM                         EXAMPLE                        2007-7-30 1
QS                             EXAMPLE                        2007-7-30 1
QS_WS                          EXAMPLE                        2007-7-30 1
QS_ES                          EXAMPLE                        2007-7-30 1
QS_OS                          EXAMPLE                        2007-7-30 1
QS_CBADM                       EXAMPLE                        2007-7-30 1
QS_CB                          EXAMPLE                        2007-7-30 1
QS_CS                          EXAMPLE                        2007-7-30 1

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)

30 rows selected

SQL select username,decode(lock_date,null,'unlocked') status from t;

USERNAME                       STATUS
------------------------------ --------
SYS                            unlocked
SYSTEM                         unlocked
DBSNMP                         unlocked
SCOTT                          unlocked
OUTLN                         
WMSYS                         
ORDSYS                        
ORDPLUGINS                    
MDSYS                         
CTXSYS                        
XDB                           
ANONYMOUS                     
WKSYS                         
WKPROXY                       
ODM                           
ODM_MTR                       
OLAPSYS                       
RMAN                          
HR                            
OE                            

USERNAME                       STATUS
------------------------------ --------
PM                            
SH                            
QS_ADM                        
QS                            
QS_WS                         
QS_ES                         
QS_OS                         
QS_CBADM                      
QS_CB                         
QS_CS                         

30 rows selected

展开更多 50%)
分享

猜你喜欢

如何使用oracle的decode函数进行多值判断

编程语言 网络编程
如何使用oracle的decode函数进行多值判断

Oracle-Decode()函数和CASE语句的比较

编程语言 网络编程
Oracle-Decode()函数和CASE语句的比较

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

Oracle 分析函数的使用

编程语言 网络编程
Oracle 分析函数的使用

使用Instr()与decode()进行多条件组合查询

电脑网络
使用Instr()与decode()进行多条件组合查询

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

oracle 函数

编程语言 网络编程
oracle 函数

Oracle 8 的函数介绍

SQLServer
Oracle 8 的函数介绍

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

windows7下如何使用系统还原与镜像备份

windows7下如何使用系统还原与镜像备份

Javascript实现的自动验证函数

Javascript实现的自动验证函数
下拉加载更多内容 ↓