oracle語句使用經驗
阿新 • • 發佈:2018-04-25
OracleSELECT
FROM (SELECT A1. ,ROWNUM RN
FROM (SELECT H.*
FROM TBC_ADOWNBLK_HIST H
WHERE 1 = 1
ORDER BY adownblkid ASC) A1
WHERE ROWNUM <= 10)
WHERE RN >= 1
想排序必須按這種寫法 and record_state = ‘1‘
方法二
(select ‘0‘||CODE code,NAME from MSTB_BDS_DATA d where d.dict_code=‘YYPZ‘ and record_state = ‘1‘ ) union all (select ‘1‘||CODE code,NAME from MSTB_BDS_DATA d where d.dict_code=‘VOICEOTHERTYPE‘ and record_state = ‘1‘)
FROM (SELECT A1. ,ROWNUM RN
FROM (SELECT H.*
FROM TBC_ADOWNBLK_HIST H
WHERE 1 = 1
ORDER BY adownblkid ASC) A1
WHERE ROWNUM <= 10)
WHERE RN >= 1
想排序必須按這種寫法
--根據不同字典值去加‘前綴’
方法一
select CASE
WHEN dict_code = ‘YYPZ‘ THEN ‘0‘ || CODE
ELSE ‘1‘ || CODE end as code,
name as name
from MSTB_BDS_DATA
where (dict_code = ‘VOICEOTHERTYPE‘ or dict_code = ‘YYPZ‘)
方法二
(select ‘0‘||CODE code,NAME from MSTB_BDS_DATA d where d.dict_code=‘YYPZ‘ and record_state = ‘1‘ ) union all (select ‘1‘||CODE code,NAME from MSTB_BDS_DATA d where d.dict_code=‘VOICEOTHERTYPE‘ and record_state = ‘1‘)
oracle語句使用經驗