1. 程式人生 > >oracle之nvl、nvl2、decode函式整理

oracle之nvl、nvl2、decode函式整理

1. nvl(eExpression1, eExpression2)

若eExpression1 is null,則return(eExpression2),否則return(eExpression1);

nvl(表示式, 表示式為空設值)

select nvl(a.address, '不詳') as address from student a ;


2. nvl2(eExpression1, eExpression2, eExpression3)

若eExpression1 is null,則return(eExpression3),否則return(eExpression2);

nvl2(表示式, 表示式不為空設值, 表示式為空設值)

select nvl2(a.address, '確切地址:' || a.address, '不詳') as address from student a ;


3.decode(eExpression, value1, returnVal1,  value2, returnVal2,...valueN, returnValN, defaultVal)

若eExpression = value1,則return(returnVal1);
若eExpression = value2,則return(returnVal2);
...
若eExpression無匹配值,則return(defaultVal);

select id, username, age, decode(sex,0,'男',1,'女') from users;