一条有用的sql文(ORACLE)
昨天在试图取某个字段时,发现在现有数据的情况下,没有该字段的值,而程序又要求必须选出一个数来,也就是说,该sql文在任何情况下都必须选出一条数据来。想了一会,得到如下一条语句,自己觉得比较有用,拿来大家讨论讨论。
SELECT NVL(A.USERRATE, 1) AS USERRATE
FROM
(
SELECT USERRATE , 1 AS TTT
FROM ORD_MONTH
WHERE ADDRESSCODE = 'L'
AND LASTID = 'C13006'
) A
,(SELECT 1 AS TTT FROM DUAL) B
WHERE 1 = 1
AND B.TTT = A.TTT(+)
B表始终有一条数据,通过外连结就会在任何情况下都选出一条数据来。
SELECT NVL(A.USERRATE, 1) AS USERRATE
FROM
(
SELECT USERRATE , 1 AS TTT
FROM ORD_MONTH
WHERE ADDRESSCODE = 'L'
AND LASTID = 'C13006'
) A
,(SELECT 1 AS TTT FROM DUAL) B
WHERE 1 = 1
AND B.TTT = A.TTT(+)
B表始终有一条数据,通过外连结就会在任何情况下都选出一条数据来。