오라클

오라클 조건문

chantleman 2024. 7. 12. 15:46
decode if문과 같은 기능을 함
(expr {[,search, result]} [,defaul])
case when 연속적인 조건문
case when ~ then ~else ~ end

 

 

decode

select decode(9,
        10,'A',
        9,'B',
        8,'C',
        'D') from dual;

 

 

 

 

앞 두글자가 p1이면 판매가 10%이상, p2이면 판매가 15%인상, 나머지는 동일 판매가로 검색

select prod_name 상품명, prod_sale 판매가,
    decode(substr(prod_lgu,1,2),
    'p1', prod_sale+(prod_sale*0.1),
    'p2',prod_sale+(prod_sale*0.15),
    prod_sale)변경판매가 from prod;

 

 

 

 

 

 

case when

10만원 초과 상품 검색

select prod_name 상품, prod_price 판매가, 
    case when(100000 - prod_price) >=0 then '10만원 미만'
        when(200000 - prod_price)>=0 then '10만원대'
        when(300000 - prod_price)>=0 then '20만원대'
        when(400000 - prod_price)>=0 then '30만원대'
        when(500000 - prod_price)>=0 then '40만원대'
        when(600000 - prod_price)>=0 then '50만원대'
        when(700000 - prod_price)>=0 then '60만원대'
        when(800000 - prod_price)>=0 then '70만원대'
        when(900000 - prod_price)>=0 then '80만원대'
        when(1000000 - prod_price)>=0 then '90만원대'
        else '100만원이상'
    end "가격대"
from prod
where prod_price>100000;

 

 

 

 

주민등록번호로 성별 구분

select mem_name 회원명, 
    mem_regno1||'-'||mem_regno2 "주민등록번호(주민1-주민2)",
    case when substr(mem_regno2,1,1)='1' or  substr(mem_regno2,1,1)='3'  then '남자'
        when substr(mem_regno2,1,1)='2' or  substr(mem_regno2,1,1)='4'  then '여자'
        else '오류'
    end 성별
from member;

 

'오라클' 카테고리의 다른 글

rownum  (0) 2024.07.12
오라클 REGEXP 함수  (0) 2024.07.12
오라클 NULL, NVL, NULLIF, COALESCE  (0) 2024.07.12
LAST_DAY(), TO_DATE  (0) 2024.07.10
오라클 시간 설정  (0) 2024.07.10