select last_name, job_id, salary,
CASE job_id WHEN 'IT_PROG' THEN 1.10*salary
WHEN 'ST_CLERK' THEN 1.15*salary
WHEN 'SA_REP' THEN 1.20*salary
ELSE salary END "REVISED_SALARY"
FROM employees;
select last_name, job_id, salary,
case when job_id='IT_PROG' then 1.1*salary
when job_id='ST_CLERK' then 1.15*salary
when job_id='SA_REP' then 1.2*salary
else salary end "REVISED_SALARY"
from employees;
select last_name, salary,
(CASE WHEN salary<5000 THEN 'Low'
WHEN salary<10000 THEN 'Medium'
WHEN salary<20000 THEN 'Good'
ELSE 'Excellent'
END) qualified_salary
FROM employees;
select last_name, job_id, salary,
DECODE(job_id, 'IT_PROG', 1.10*salary,
'ST_CLERK', 1.15*salary,
'SA_REP', 1.20*salary,
salary)
REVISED_SALARY
FROM employees;
select last_name, salary,
DECODE (TRUNC (salary/2000, 0),
0, 0.00,
1, 0.09,
2, 0.20,
3, 0.30,
4, 0.40,
5, 0.42,
6, 0.44,
0.45) TAX_RATE
FROM employees
WHERE department_id = 80;
select job_id,
case job_id when 'AD_PRES' then 'A'
when 'ST_MAN' then 'B'
when 'IT_PROG' then 'C'
when 'SA_REP' then 'D'
when 'ST_CLERK' then 'E'
else '0' end "GRADE"
FROM employees;
select job_id,
decode(job_id,'AD_PRES', 'A',
'ST_MAN' , 'B',
'IT_PROG', 'C',
'SA_REP', 'D',
'ST_CLERK', 'E',
'0')
GRADE
FROM employees;
select count(*) TOTAL,
sum(decode(to_char(hire_date,'YYYY'),2002,1,0)) "2002",
sum(decode(to_char(hire_date,'YYYY'),2003,1,0)) "2003",
sum(decode(to_char(hire_date,'YYYY'),2004,1,0)) "2004",
sum(decode(to_char(hire_date,'YYYY'),2005,1,0)) "2005"
from employees;
(==)
select count(*) TOTAL,
count(decode(to_char(hire_date,'YYYY'),2002,1,null)) "2002",
count(decode(to_char(hire_date,'YYYY'),2003,1,null)) "2003",
count(decode(to_char(hire_date,'YYYY'),2004,1,null)) "2004",
count(decode(to_char(hire_date,'YYYY'),2005,1,null)) "2005"
from employees;
(==)
select count(*) TOTAL,
count(decode(to_char(hire_date,'YYYY'),2002,1)) "2002",
count(decode(to_char(hire_date,'YYYY'),2003,1)) "2003",
count(decode(to_char(hire_date,'YYYY'),2004,1)) "2004",
count(decode(to_char(hire_date,'YYYY'),2005,1)) "2005"
from employees;
select job_id Job, sum(decode(department_id, 20, salary)) "Dept20",
sum(decode(department_id, 50, salary)) "Dept50",
sum(decode(department_id, 80, salary)) "Dept80",
sum(decode(department_id, 90, salary)) "Dept90",
sum(salary) "Total"
from employees
group by job_id;
SQL> conn sys/oracle as sysdba
Connected.
SQL> show user
USER is "SYS"
SQL> create user test
2 identified by test01;
User created.
SQL> conn sys/oracle as sysdba
Connected.
SQL> show user
USER is "SYS"
create table -> table과 index를 생성/운영할 수 있는 권한
create view
create sequence
...
SQL> GRANT create session, create table
2 TO test;
Grant succeeded.
SQL> conn test/test01
Connected. => 접속 가능 여부 확인!!!
SQL> show user
USER is "TEST"
SQL> alter user test
2 identified by busan_123;
User altered.
SQL> conn sys/oracle as sysdba
Connected.
SQL> show user
USER is "SYS"
SQL> revoke create table
2 from test;
Revoke succeeded.
SQL> show user
USER is "TEST"
SQL> col last_name format a20
SQL> select employee_id, last_name, salary
2 from hr.employees;
from hr.employees
*
ERROR at line 2:
ORA-00942: table or view does not exist
=> error! (권한부족)
SQL> conn hr/hr
Connected.
SQL> show user
USER is "HR"
SQL> grant select, update
2 on employees
3 to test;
Grant succeeded.
=> 권한부여완료!!
SQL> conn test/busan_123
Connected.
SQL> select employee_id, last_name, salary
2 from hr.employees;
SQL> conn hr/hr
Connected.
SQL> revoke update
2 on employees
3 from test;
Revoke succeeded.
=> test에게 줬던 update 권한 회수!!