반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- androidstudio
- Android
- Chrome
- linux
- jest
- avds
- react
- localserver
- PYTHON
- build
- 개발
- IOS
- TensorFlow
- VirtualBox
- MAC
- node
- 맥
- 네트워크
- 센토스
- webpack
- vsCode
- unittest
- ReactNative
- xcode
- qunit
- MachineLearning
- picker
- 리눅스
- centos
Archives
- Today
- Total
로메오의 블로그
[SQL] Oracle SQL - NVL, NVL2, DECADE 본문
반응형
[ORACLE] DOCKER에 ORACLE 11G 설치하기
[POSTGRESQL] DOCKER에 POSTGRESQL 설치하기
SELECT
COMPANY
, PRODUCT
, MOBILE
FROM (
SELECT 'Google' COMPANY, 'Android' PRODUCT, 'Y' MOBILE FROM DUAL
UNION ALL
SELECT 'Google' COMPANY, 'Chrome' PRODUCT, '' MOBILE FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'Macbook' PRODUCT, '' MOBILE FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'iPhone' PRODUCT, 'Y' MOBILE FROM DUAL
UNION ALL
SELECT 'Sony' COMPANY, 'walkman' PRODUCT, '' MOBILE FROM DUAL
UNION ALL
SELECT 'Samsung' COMPANY, 'Gallexy' PRODUCT, 'Y' MOBILE FROM DUAL
);
COMPANY PRODUCT M
------- ------- -
Google Android Y
Google Chrome
Apple Macbook
Apple iPhone Y
Sony walkman
Samsung Gallexy Y
6 rows selected.
NVL 함수
MOBILE 컬럼에 Y만 들어있습니다.
NVL함수로 Y, N을 채워봅니다.
SELECT
COMPANY
, PRODUCT
, MOBILE
, NVL(MOBILE, 'N') AS MOBILE_YN -- MOBILE이 null이면 N
FROM (
SELECT 'Google' COMPANY, 'Android' PRODUCT, 'Y' MOBILE FROM DUAL
UNION ALL
SELECT 'Google' COMPANY, 'Chrome' PRODUCT, '' MOBILE FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'Macbook' PRODUCT, '' MOBILE FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'iPhone' PRODUCT, 'Y' MOBILE FROM DUAL
UNION ALL
SELECT 'Sony' COMPANY, 'walkman' PRODUCT, '' MOBILE FROM DUAL
UNION ALL
SELECT 'Samsung' COMPANY, 'Gallexy' PRODUCT, 'Y' MOBILE FROM DUAL
);
COMPANY PRODUCT M M
------- ------- - -
Google Android Y Y
Google Chrome N
Apple Macbook N
Apple iPhone Y Y
Sony walkman N
Samsung Gallexy Y Y
6 rows selected.
NVL2함수
Y와 N을 YES와 NO로 치환합니다.
SELECT
COMPANY
, PRODUCT
, MOBILE
, NVL(MOBILE, 'N') AS MOBILE_YN -- MOBILE이 null이면 N
, NVL2(MOBILE, 'YES', 'NO') AS MOBILE_YES_NO -- MOBILE이 있으면 YES, 없으면 NO
FROM (
SELECT 'Google' COMPANY, 'Android' PRODUCT, 'Y' MOBILE FROM DUAL
UNION ALL
SELECT 'Google' COMPANY, 'Chrome' PRODUCT, '' MOBILE FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'Macbook' PRODUCT, '' MOBILE FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'iPhone' PRODUCT, 'Y' MOBILE FROM DUAL
UNION ALL
SELECT 'Sony' COMPANY, 'walkman' PRODUCT, '' MOBILE FROM DUAL
UNION ALL
SELECT 'Samsung' COMPANY, 'Gallexy' PRODUCT, 'Y' MOBILE FROM DUAL
);
COMPANY PRODUCT M M MOB
------- ------- - - ---
Google Android Y Y YES
Google Chrome N NO
Apple Macbook N NO
Apple iPhone Y Y YES
Sony walkman N NO
Samsung Gallexy Y Y YES
6 rows selected.
DECADE함수
SELECT
COMPANY
, PRODUCT
, MOBILE
, NVL(MOBILE, 'N') AS MOBILE_YN -- MOBILE이 null이면 N
, NVL2(MOBILE, 'YES', 'NO') AS MOBILE_YES_NO -- MOBILE이 있으면 YES, 없으면 NO
, DECODE(COMPANY, 'Sony', 'NO_ABE', 'Friend') AS FRIEND -- COMPANY가 Sony 이면 NO_ABE 아니면 Friend
FROM (
SELECT 'Google' COMPANY, 'Android' PRODUCT, 'Y' MOBILE FROM DUAL
UNION ALL
SELECT 'Google' COMPANY, 'Chrome' PRODUCT, '' MOBILE FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'Macbook' PRODUCT, '' MOBILE FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'iPhone' PRODUCT, 'Y' MOBILE FROM DUAL
UNION ALL
SELECT 'Sony' COMPANY, 'walkman' PRODUCT, '' MOBILE FROM DUAL
UNION ALL
SELECT 'Samsung' COMPANY, 'Gallexy' PRODUCT, 'Y' MOBILE FROM DUAL
);
COMPANY PRODUCT M M MOB FRIEND
------- ------- - - --- ------
Google Android Y Y YES Friend
Google Chrome N NO Friend
Apple Macbook N NO Friend
Apple iPhone Y Y YES Friend
Sony walkman N NO NO_ABE
Samsung Gallexy Y Y YES Friend
6 rows selected.
반응형
'Backend > Oracle & SQL' 카테고리의 다른 글
[SQL Developer] Oracle 서버 접속시 무한로딩 해결방법 (1) | 2019.09.19 |
---|---|
[Oracle] 사용자 생성하기 - User / Tablespace / Table 생성하기 (0) | 2019.09.19 |
[SQL] Oracle SQL Query - CASE WHEN ELSE (0) | 2019.09.02 |
[SQLDeveloper] locale not recognized 오류 (0) | 2019.09.02 |
[SQL] distinct 중복제거 예제 (1) | 2019.08.29 |
Comments