Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在sql查询中使用decode_Sql_Oracle_Decode - Fatal编程技术网

在sql查询中使用decode

在sql查询中使用decode,sql,oracle,decode,Sql,Oracle,Decode,专家们 我正在尝试修复下面的简单查询,以包含null条件 我可以在where子句中使用“IS NOT NULL”并忽略记录,但这不是最好的方法。希望以正确的方式解决此问题 在当前解码过程下面列出所有过程并替换“1234@xzy", "1234@abc“使用JDBC。当列表中有空值时,此解码在脚本中无法正常工作 问题: 1.是否可以修改当前解码以将null替换为NA Query in oracle: SELECT osuser, machine, DECODE (process,

专家们

我正在尝试修复下面的简单查询,以包含null条件

我可以在where子句中使用“IS NOT NULL”并忽略记录,但这不是最好的方法。希望以正确的方式解决此问题

在当前解码过程下面列出所有过程并替换“1234@xzy", "1234@abc“使用JDBC。当列表中有空值时,此解码在脚本中无法正常工作

问题: 1.是否可以修改当前解码以将null替换为NA

Query in oracle:

SELECT osuser, machine,
       DECODE (process, '1234', 'JDBC', substr(process, 1, instr(process || '@','@')-1)) "PID"
FROM v$session
WHERE username IS NOT NULL;

Expected Result:
=============== 
4567    
78960    
4575    
JDBC    
JDBC    
NA    
9658

Process list:
=============
4567    
78960    
4575    
1234@abc    
1234@xyz    
   (null)
9658

您可以使用
nvl
表达式包装
decode
表达式:

SELECT osuser, machine,
       NVL(DECODE (process, 
                   '1234', 'JDBC', 
                    substr(process, 1, instr(process || '@','@')-1)), 
           'NA') "PID"
FROM   v$session
WHERE  username IS NOT NULL;

效果很好,我对响应时间印象深刻。。。非常感谢。我在玩nvl/nvl2,但没有想到加入解码。。。