default ν
μ΄λΈ μ€νμ΄μ€λ κ³μ λ§λ€ λ€λ₯΄λ€! (보μλλ¬Έμ)
SID : μμ€ν
μλ³μ / μ¬λ¬ μ€λΌν΄μ΄ port 1521 μ°Ύμμ€λλ‘ κ΅¬λΆν΄μ£Όλ κ² (XE)
1. λͺ¨λ μ¬μ©μ κ³μ μ‘°ν(κ²μ) : DQL ( select )
[select λ¬Έ μ¬μ© ]
1) μ‘°ν λμ( subquery, νλ μ΄μμ ν
μ΄λΈ, λ·°(materialized view) )μΌλ‘ λΆν° λ°μ΄ν° κ°μ Έμ€λλ° μ¬μ©νλ λ¬Έ.
2) μ‘°ν λμμ μμ μ, μ‘°ν λμμ SELECT κΆν
3) SELECT ANY TABLE μμ€ν
κΆνμ κ°μ§κ³ μμΌλ©΄ λͺ¨λ ν
μ΄λΈ, λ·°λ₯Ό μ‘°ν κ°λ₯
4) select νμ)
γνμγ
[subquery_factoring_clause] subquery [for_update_clause];
γsubquery νμγ
{query_block ¦
subquery {UNION [ALL] ¦ INTERSECT ¦ MINUS }... ¦ (subquery)}
[order_by_clause]
γquery_block νμγ
SELECT [hint] [DISTINCT ¦ UNIQUE ¦ ALL] select_list
FROM {table_reference ¦ join_clause ¦ (join_clause)},...
[where_clause]
[hierarchical_query_clause]
[group_by_clause]
[HAVING condition]
[model_clause]
γsubquery factoring_clauseνμγ
WITH {query AS (subquery),...}
5)(μκΈ°) SELECT λ¬Έ = μ +μ +μ +μ ... 7μ
μ²λ¦¬ μμλ₯Ό μ μΌμΈμ.
1 [WITH] μλ΅ κ°λ₯
6 SELECT μ‘°ν컬λΌ,,,,, *
2 FROM μ‘°ν λμ(μλΈμΏΌλ¦¬,ν
μ΄λΈ,λ·°)
3 [WHERE]
4 [GROUP BY]
5 [HAVING]
7 [ORDER BY]
5. SELECT λ¬Έ μ¬μ©λλ ν€μλ : DISTINCT, ALL , AS
--[ Ora_Help ]
;
SELECT *
FROM user_users; -- νμ¬ μ μν μ¬μ©μ μ 보 + Access μ¬μ©μ μ 보
FROM View;
FROM dba_users; -- SYS( DBA )
USERNAME USER_ID PASSWORD ACCOUNT_STATUS μΆκ° μ»¬λΌ μ 보
SYS 0 OPEN 21/02/05 SYSTEM TEMP
SYSTEM 5 OPEN 21/02/05 SYSTEM TEMP
ANONYMOUS 35 OPEN 14/11/25 SYSAUX TEMP
FROM all_users; -- ν
μ΄λΈ, λ·°
USERNAME USER_ID CREATED 컬λΌλͺ
XS$NULL 2147483638 14/05/29
SCOTT 51 22/09/26
APEX_040000 47 14/05/29
APEX_PUBLIC_USER 45 14/05/29
-- NLS λ μ§νμ RR YY μ°¨μ΄μ (λ
λ)/MM(μ)/DD(μΌ)
-- SCOTT 51 22/09/23
PRIVILEGE == κΆν
ROLE ( λ‘€, μν ) == PRIVILEGE GROUP κΆνμ κ·Έλ£Ή(μ§ν©)
DATABASE SCHEMA ( μ€ν€λ§ ) ==
1. SCOTT κ³μ μ μμ±νλ©΄ μλμΌλ‘ SCOTTμ΄λΌλ μ΄λ¦μ μ€ν€λ§κ° μμ±λλ€.
μμ±κ³μ λͺ
== μ€ν€λ§λͺ
( λμΌ )
2. μ€ν€λ§λ μμ±λ κ³μ κ³Ό κ΄λ ¨λ λͺ¨λ κ°μ²΄λ€μ μ€ν€λ§λΌνλ€.
USER μμ±
λ€μκ³Ό κ°μ νμμΌλ‘ USERλ₯Ό μμ±νλ€.
γνμγ
CREATE USER μ¬μ©μλͺ
IDENTIFIED BY λΉλ°λ²νΈ λλ IDENTIFIED EXTERNALLY
[DEFAULT TABLESPACE ν
μ΄λΈμ€νμ΄μ€λͺ
]
[TEMPORARY TABLESPACE ν
μ΄λΈμ€νμ΄μ€λͺ
]
[PROFILE νλ‘νμΌλͺ
]
[QUOTA ν λΉλ ON ν
μ΄λΈμ€νμ΄μ€λͺ
λλ UNLIMITED ON ν
μ΄λΈμ€νμ΄μ€λͺ
]
[PASSWORD EXPIRE]
[ACCOUNT LOCK λλ UNLOCK];
[ **** κ³μ μμ *** ]
λ³κ²½ν μ μλ USER μμ±
• ALTER USER λ¬Έμ μ¬μ©νμ¬ userμμ±μ λ³κ²½ν μ μλ€.
• USERμ λ³κ²½μ¬νμ νμ¬μ SESSIONμλ μν₯μ μ£Όμ§ μκ³ λ€μμ μ μν SESSIONλΆν° μν₯μ λ°λλ€.
• ALTER USER λ¬Έμ μ¬μ©νμ¬ userμμ±μ λ³κ²½ν μ μλ μμ±μ λ€μκ³Ό κ°λ€.
νλͺ© μλ―Έ
password USERμ passwordλ₯Ό λ³κ²½ν μ μμ
OS μΈμ¦ USERλ₯Ό OSμΈμ¦/Oracle Server μΈμ¦μΌλ‘ λ³κ²½ν μ μμ
DEFAULT TABLESPACE DEFAULT TABLESPACEλ₯Ό λ³κ²½ν μ μμ
TEMPORARY TABLESPACE TEMPORARY TABLESPACEλ₯Ό λ³κ²½ν μ μμ
TABLESPACEλΉ QUOTA TABLESPACEλΉ ν λΉλμ λ³κ²½ν μ μμ
λ§μ½, ν λΉλμ 0μΌλ‘ νλ©΄ κΈ°μ‘΄ objectμ λν μμ λ κ°λ₯νμ§λ§
μ°¨ν μΆκ° ν λΉμ λ°μ§ λͺ»ν¨
PROFILE DBAκ° RESOURCEλ₯Ό λ³κ²½νκ³ μΆμ λ USERμ PROFILEμ λ³κ²½ν¨
DEFAULT ROLE USERμ μ
λ¬΄κ° λ°λ κ²½μ°μλ κ·Έμ ν΄λΉνλ DEFAULT ROLEλ‘ λ³κ²½ν¨
-- SYS μ μ ( λΉ¨κ° ν
λ리 )
USER μμ
γνμγ
DROP USER μ¬μ©μλͺ
[CASCADE]; μ¬μ μ μλ―Έ : μμ νν¬, νν¬μ²λΌ νλ₯΄λ€. **** [Cascade]SS
ν΄λΉ κ³μ μ μμ ν λͺ¨λ κ°μ²΄(μ€ν€λ§) κ°μ΄ μμ .
DROP USER scott CASCADE;
-- ORA-01940: cannot drop a user that is currently connected
-- ORA-01922: CASCADE must be specified to drop 'SCOTT'
-- User SCOTTμ΄(κ°) μμ λμμ΅λλ€.
• userμμ μ νμ¬ DBμ μ μμ€μΈ μ¬μ©μλ μμ ν μ μλ€.
νμ¬ μ μμ€μΈ μ¬μ©μλ κ·Έ μ¬μ©μμ SESSIONμ΄ λλμΌ νλ€.
# sqlplus / as sysdba
SQL> DROP USER kim cascade;
User dropped.
-- SCOTT κ³μ μμ±
CREATE USER scott IDENTIFIED BY tiger;
-- User SCOTTμ΄(κ°) μμ±λμμ΅λλ€.
μν: μ€ν¨ -ν
μ€νΈ μ€ν¨:
ORA-01045: user SCOTT lacks CREATE SESSION privilege; logon denied
-- CREATE SESSION κΆν λΆμ¬. DCL( grant )
κΆν( privilege )μ 2κ°μ§ μ’
λ₯
1) μμ€ν
κΆν : κ°μ²΄ μμ±,μμ , μμ νλ κΆν
2) κ°μ²΄ κΆν : κ°μ²΄μ λ΄μ©μ μΆκ°,μμ ,μμ κ²μ κΆν
Grant κΆν( Create Session ) TO λͺ¨λ μ¬μ©μ κ³μ ; λμ( μ¬μ©μ, λ‘€ )
λ‘€( Role ) PUBLIC
GRANT CREATE SESSION TO scott;
--0 λͺ¨λ μμ€ν
κΆν λͺ©λ‘μ νμΈ(μ‘°ν) - view
SELECT *
FROM system_privilege_map;
FROM dba_sys_privs; (dba λΆμ건 κ΄λ¦¬μλ§ μ¬μ©κ°λ₯!)
-- μ€λ₯λ°μ : ORA-00942: table or view does not exist
SELECT *
FROM user_users;
FROM dba_users; --dba_users μ‘΄μ¬X μΌλ°κ³μ μΈ SCOTTμ dba_XXX μ¬μ©ν μ μλ€.
[ scott.sql νμΌ ]
Rem μ£Όμμ²λ¦¬
-- μ£Όμμ²λ¦¬
SET λͺ
λ Ήμ΄ : μμ€ν
μ νκ²½ μ€μ νλ λͺ
λ Ήμ΄
SET TERMOUT OFF : μ€ν κ²°κ³Όλ₯Ό νλ©΄μ μΆλ ₯μ¬λΆ
SET ECHO OFF : μ€νλ μ€ν¬λ¦½νΈ νλ©΄ O, X
SET TERMOUT ON
SET ECHO ON
GRANT CONNECT,RESOURCE,UNLIMITED TABLESPACE -- λ‘€
TO SCOTT
IDENTIFIED BY tiger;
-- DB μ°κ²°(μ μ) O
-- (μν) SCOTT κ³μ μ 보 νμΈ( μ‘°ν )νλ 쿼리~
SELECT *
FROM user_users;
-- SCOTT --
-- (μν) SCOTTμ΄ μμ ν ν
μ΄λΈ(table) λͺ©λ‘ μ‘°ν. - X
SELECT *
FROM tabs;
-- [ DCL λ¬Έ ]
CREATE TABLE ν
μ΄λΈλͺ
;
ALTER TABLE ν
μ΄λΈλͺ
;
DROP TABLE DEPT;
-- ORA-00942: table or view does not exist
-- λΆμ(dept)ν
μ΄λΈ μμ±
CREATE TABLE DEPT
(
DEPTNO NUMBER(2) CONSTRAINT PK_DEPT PRIMARY KEY, -- λΆμλ²νΈ PK 컬λΌ( κ³ μ ν μ»¬λΌ )
DNAME VARCHAR2(14) , -- λΆμλͺ
컬λΌ
LOC VARCHAR2(13) -- μ§μλͺ
컬λΌ
) ;
-- Table DEPTμ΄(κ°) μμ±λμμ΅λλ€.
-- λΆμ μ 보 μΆκ°( DML : insert ) λ°λμ commit, rollback ν΄μΌ λλ€. ( μκΈ° )
-- INSERTλ¬Έ νμμ μΌμΈμ.)
INSERT INTO ν
μ΄λΈλͺ
[( 컬λΌλͺ
... )] VALUES ( 컬λΌκ°... );
COMMIT;
--
INSERT INTO DEPT ( DEPTNO, DNAME, LOC ) VALUES (10,'ACCOUNTING','NEW YORK');
INSERT INTO DEPT VALUES (20,'RESEARCH','DALLAS');
INSERT INTO DEPT VALUES (30,'SALES','CHICAGO');
INSERT INTO DEPT VALUES (40,'OPERATIONS','BOSTON');
1 ν μ΄(κ°) μ½μ
λμμ΅λλ€.
1 ν μ΄(κ°) μ½μ
λμμ΅λλ€.
1 ν μ΄(κ°) μ½μ
λμμ΅λλ€.
1 ν μ΄(κ°) μ½μ
λμμ΅λλ€.
COMMIT;
μ»€λ° μλ£.
--( μν ) dept ν
μ΄λΈμ ꡬ쑰λ₯Ό νμΈνλ 쿼리 μμ±νμΈμ..
DESC ν
μ΄λΈλͺ
;
DESC dept;
DESC[RIBE] dept;
μ΄λ¦ λ? μ ν
------ -------- ------------
DEPTNO NOT NULL NUMBER(2)
DNAME VARCHAR2(14)
LOC VARCHAR2(13)
-- ( μν ) dept ν
μ΄λΈμ λΆμ μ 보λ₯Ό μ‘°ν(κ²μ)νλ 쿼리λ₯Ό μμ±νμΈμ.
SELECT * -- λͺ¨λ 컬λΌ
FROM dept; ν
μ΄λΈλͺ
, λ·°λͺ
, μλΈμΏΌλ¦¬
-- ( μν ) dept ν
μ΄λΈμ λΆμ μ 보λ₯Ό μ‘°ν(κ²μ)νλ 쿼리λ₯Ό μμ±νμΈμ. ( λΆμλ²νΈ, λΆμλͺ
λ§ μ‘°ν )
SELECT deptno, dname -- 컬λΌλͺ
, 컬λΌλͺ
,..
FROM dept;
SELECT dname -- 컬λΌλͺ
, 컬λΌλͺ
,..
FROM dept;
-- κ΄κ³
-- μ¬μ(emp) ν
μ΄λΈ
CREATE TABLE EMP
(
EMPNO NUMBER(4) CONSTRAINT PK_EMP PRIMARY KEY, -- μ¬μλ²νΈ PK (κ³ μ ν 컬λΌ)
ENAME VARCHAR2(10), -- μ¬μλͺ
JOB VARCHAR2(9), -- μ‘
MGR NUMBER(4), -- μ¬μ(κ΄λ¦¬μ), μ§μμμ¬
HIREDATE DATE, -- μ
μ¬μΌμ
SAL NUMBER(7,2), -- κΈ°λ³ΈκΈ
COMM NUMBER(7,2), -- μλΉ
DEPTNO NUMBER(2) CONSTRAINT FK_DEPTNO REFERENCES DEPT -- λΆμλ²νΈ DEPT(deptno) μ°Έμ‘° FK, μ°Έμ‘°ν€
);
-- Table EMPμ΄(κ°) μμ±λμμ΅λλ€.
INSERT INTO EMP VALUES
(7369,'SMITH','CLERK',7902,to_date('17-12-1980','dd-mm-yyyy'),800,NULL,20);
INSERT INTO EMP VALUES
(7499,'ALLEN','SALESMAN',7698,to_date('20-2-1981','dd-mm-yyyy'),1600,300,30);
INSERT INTO EMP VALUES
(7521,'WARD','SALESMAN',7698,to_date('22-2-1981','dd-mm-yyyy'),1250,500,30);
INSERT INTO EMP VALUES
(7566,'JONES','MANAGER',7839,to_date('2-4-1981','dd-mm-yyyy'),2975,NULL,20);
INSERT INTO EMP VALUES
(7654,'MARTIN','SALESMAN',7698,to_date('28-9-1981','dd-mm-yyyy'),1250,1400,30);
INSERT INTO EMP VALUES
(7698,'BLAKE','MANAGER',7839,to_date('1-5-1981','dd-mm-yyyy'),2850,NULL,30);
INSERT INTO EMP VALUES
(7782,'CLARK','MANAGER',7839,to_date('9-6-1981','dd-mm-yyyy'),2450,NULL,10);
-- μ€λ₯ : ORA-01858: a non-numeric character was found where a numeric was expected
-- μ«μλ₯Ό κΈ°λνλ κ³³μ μ«μκ° μλ λ¬Έμλ₯Ό μ°Ύμλ€.
INSERT INTO EMP VALUES
(7788,'SCOTT','ANALYST',7566,to_date('13-7-87','dd-mm-yyyy' )-85,3000,NULL,20);
μ«μ 7788
λ¬Έμ, λ¬Έμμ΄, λ μ§ ''
INSERT INTO EMP VALUES
(7839,'KING','PRESIDENT',NULL,to_date('17-11-1981','dd-mm-yyyy'),5000,NULL,10);
INSERT INTO EMP VALUES
(7844,'TURNER','SALESMAN',7698,to_date('8-9-1981','dd-mm-yyyy'),1500,0,30);
INSERT INTO EMP VALUES
(7876,'ADAMS','CLERK',7788,to_date('13-7-87','dd-mm-yyyy')-51,1100,NULL,20);
INSERT INTO EMP VALUES
(7900,'JAMES','CLERK',7698,to_date('3-12-1981','dd-mm-yyyy'),950,NULL,30);
INSERT INTO EMP VALUES
(7902,'FORD','ANALYST',7566,to_date('3-12-1981','dd-mm-yyyy'),3000,NULL,20);
INSERT INTO EMP VALUES
(7934,'MILLER','CLERK',7782,to_date('23-1-1982','dd-mm-yyyy'),1300,NULL,10);
COMMIT;
--
INSERT INTO EMP VALUES
(7876,'ADAMS','CLERK',7788,to_date('13-JUL-87')-51,1100,NULL,20)
μ€λ₯ λ³΄κ³ -
ORA-01858: a non-numeric character was found where a numeric was expected
--
ROLLBACK; -- DML( INSERT ) λͺ¨λ μ·¨μ
DELETE FROM emp;
-- (μν) λͺ¨λ μ¬μ μ 보 μ‘°ν.
SELECT *
FROM emp;
CREATE TABLE BONUS
(
ENAME VARCHAR2(10) ,
JOB VARCHAR2(9) ,
SAL NUMBER,
COMM NUMBER
) ;
-- Table BONUSμ΄(κ°) μμ±λμμ΅λλ€.
-- κΈμ¬λ±κΈ ν
μ΄λΈ
CREATE TABLE SALGRADE
(
GRADE NUMBER, -- λ±κΈ 1~5
LOSAL NUMBER,
HISAL NUMBER
);
INSERT INTO SALGRADE VALUES (1,700,1200);
INSERT INTO SALGRADE VALUES (2,1201,1400);
INSERT INTO SALGRADE VALUES (3,1401,2000);
INSERT INTO SALGRADE VALUES (4,2001,3000);
INSERT INTO SALGRADE VALUES (5,3001,9999);
COMMIT;
-- ( μν ) κΈ°λ³ΈκΈμ λ±κΈν
μ΄λΈ μ‘°ννλ 쿼리 μμ±νμΈμ.
SELECT *
FROM salgrade;
-- ( μν ) SCOTTμ΄ μμ ν λͺ¨λ ν
μ΄λΈ λͺ©λ‘ μ‘°ννλ 쿼리( DQL ) μμ±νμΈμ.
SELECT *
FROM tabs;
-- SCOTT : DEPT, EMP, BONUS, SALGRADE 4κ°μ ν
μ΄λΈ μμ± + λ°μ΄ν° μΆκ°
-- 1) λͺ¨λ μ¬μμ μ 보λ₯Ό μ‘°ν
-- (쑰건: μ¬μλ²νΈ, μ¬μλͺ
, μ
μ¬μΌμ μ‘°ν )
DESC emp;
-- 컬λΌλͺ
νμΈ : EMPNO, ENAME, HIREDATE
SELECT empno, ename, hiredate
FROM emp;
-- 2) λͺ¨λ μ¬μμ μ 보λ₯Ό μ‘°ν
-- (쑰건: μ¬μλ²νΈ, μ¬μλͺ
, μ
μ¬μΌμ, κΈ°λ³ΈκΈ, 컀미μ
μ‘°ν )
SELECT empno, ename, hiredate, sal, comm
FROM emp;
-- 3) λͺ¨λ μ¬μμ μ 보λ₯Ό μ‘°ν ( μν )
-- (쑰건 : μ¬μλ²νΈ, μ¬μλͺ
, μ
μ¬μΌμ, κΈ°λ³ΈκΈ, 컀미μ
μ‘°ν )
-- (쑰건 : μκΈ = κΈ°λ³ΈκΈ + 컀미μ
)
-- SELECT ν€μλ : distinct, all, as
SELECT empno, ename, hiredate, sal AS κΈ°λ³ΈκΈ, comm μλΉ
, NVL2( comm, comm, 0 )
, sal + NVL2( comm, comm, 0 ) AS pay
, NVL2( sal + comm, sal + comm, sal ) AS "λ³ μΉ"
FROM emp;
-- 3-2) null μλ―Έ ? null μλ€ X, λ―Έμ
-- μ£Όμ§μ λͺΈλ¬΄κ² μΌλ§μμ ? λͺΈλ¬΄κ² μΈ‘μ X, λͺΈλ¬΄κ²κ° μΌλ§μΈμ§ λͺ°λΌμ.
-- μ€λΌν΄μμ NULLμ μλ΅λ, μλ €μ§μ§ μμ, νΉμ μ μ©ν μ μλ κ°μ μλ―Ένλ μμ½μ΄
-- 3-3) null μ°μ° κ° = null
-- 3-4) null μ²λ¦¬ λ°©λ² ? 컀미μ
μ΄ λ―Έμ (null) -> 0 λΌκ³ μ²λ¦¬
-- null μ²λ¦¬νλ ν¨μ( function ) :
-- 1) NVL
-- 2) NVL2 ***
NVL2(a, b, c)
a κ°μ΄ null μ΄ μλλ©΄ b
a κ°μ΄ null μ΄λ©΄ c
-- 3) NULLIF
-- 4) COALESCE
-- λͺ¨λ μ¬μ©μ κ³μ μ 보λ₯Ό νμΈ
SELECT *
FROM dba_users;
-- ORA-00942: table or view does not exist
-- SCOTT ( νλ )--
-- λͺ¨λ ν
μ΄λΈ λͺ©λ‘ μ‘°ν 쿼리 μμ±
SELECT *
FROM user_tables; -- == FROM tabs; λ·°( View )
-- ( μν ) emp ν
μ΄λΈμμ
-- λͺ¨λ μ¬μ μ 보λ₯Ό μ‘°ν(κ²μ)
-- μ¬μλ²νΈ, μ¬μλͺ
, μ
μ¬μΌμ, κΈμ¬( κΈ°λ³ΈκΈ + 컀미μ
)
--- (μΆκ° λ¬Έμ ) μ λ ¬ - μ€λ¦μ°¨μ, λ΄λ¦Όμ°¨μ μ λ ¬
-- 1,2,3,4
-- a,b,c,d
-- γ±,γ΄,γ·,γΉ
-- pay(κΈμ¬)λ₯Ό λ§μ΄ λ°λ μ¬μλΆν° μΆλ ₯.(μ‘°ν) : κΈμ¬ λ΄λ¦Όμ°¨μ μ λ ¬
-- sal(κΈ°λ³ΈκΈ) "
SELECT empno, ename, hiredate , sal, comm
, sal + NVL2( comm, comm, 0 ) pay
-- , NVL2( sal + comm, sal+comm, sal ) pay
-- -- , NVL() comm null μ²λ¦¬
-- , sal + NVL( comm, 0 ) pay
-- , NVL( sal+comm, sal ) pay
FROM emp
ORDER BY sal ; -- ASC κΈ°λ³Έμ μ€λ¦μ°¨μ μ λ ¬.
-- ORDER BY sal ASC;
-- ORDER BY sal DESC; -- λ΄λ¦Όμ°¨μμΌλ‘ μ λ ¬
-- FROM scott.emp; --μ€ν€λ§.κ°μ²΄λͺ
-- ( μν ) emp ν
μ΄λΈμμ
-- κ° λΆμλ²νΈλ‘ μ€λ¦μ°¨μ μ λ ¬μ νμΈμ.
-- λΆμλ²νΈ , μ¬μλͺ
, μ
μ¬μΌμ, μκΈ(pay) μΆλ ₯.
SELECT deptno, ename, hiredate, sal + NVL(comm, 0) pay
FROM scott.emp
ORDER BY deptno ASC, hiredate DESC;
ORDER BY 1 ASC;
ORDER BY deptno ASC;
-- 첫 λ²μ§Έ μ λ ¬ : λΆμλ²νΈ μ€λ¦μ°¨μ μ λ ¬ (1μ°¨ μ λ ¬)
-- λ λ²μ§Έ μ λ ¬ : κ°μ λΆμλ²νΈ λ΄μμ μ
μ¬μΌμλ₯Ό λ΄λ¦Όμ°¨μ μ λ ¬ ( 2μ°¨ μ λ ¬ )
-- (λ¬Έμ ) emp ν
μ΄λΈμμ
-- λΆμλ²νΈλ‘ μ€λ¦μ°¨μ μ λ ¬μ ν ν μκΈ(pay) κΈ°μ€μΌλ‘ λ΄λ¦Όμ°¨μ μ λ ¬μ νμΈμ.
-- ( deptno, ename, hiredate, pay μ»¬λΌ )
SELECT deptno, ename, hiredate, sal + NVL(comm, 0) pay
FROM emp
ORDER BY deptno , pay DESC;
-- SELECT DISTINCT, AS , ALL
SELECT ALL job --λ³κ°μ λΆλͺ
ν, ꡬλ³λλ
FROM emp;
-- μ¬μλ€μ΄ μν΄μλ [ job μ’
λ₯ ] μ‘°ν μΆλ ₯. + μ€λ¦μ°¨μ μ λ ¬
-- μ€λ³΅ μ κ±° ν΄μ 1λ² μΆλ ₯
SELECT DISTINCT job --λ³κ°μ λΆλͺ
ν, ꡬλ³λλ
FROM emp
ORDER BY job ASC;
-- X
SELECT DISTINCT job , ename --λ³κ°μ λΆλͺ
ν, ꡬλ³λλ
FROM emp;
-- ( μν ) emp ν
μ΄λΈμμ
-- 10λ² λΆμμλ€λ§ μ‘°ν(μΆλ ₯) -- 쑰건μ
SELECT deptno, ename, hiredate, mgr
FROM emp
WHERE deptno = 10; -- μ€λΌν΄ κ°λ€ = μ°μ°μ
WHERE deptno == 10; -- 304ν, 15μ΄μμ μ€λ₯ λ°μ, ORA-00936: missing expression
WHERE 쑰건μ ;
-- SYS -
GRANT CONNECT,RESOURCE,UNLIMITED TABLESPACE -- λ‘€
TO SCOTT
IDENTIFIED BY tiger;
-- Grantμ(λ₯Ό) μ±κ³΅νμ΅λλ€.
CREATE USER
DROP USER
ALTER USER SCOTT DEFAULT TABLESPACE USERS;
-- User SCOTTμ΄(κ°) λ³κ²½λμμ΅λλ€.
ALTER USER SCOTT TEMPORARY TABLESPACE TEMP;
-- SYS --
SELECT *
FROM dba_users;
-- ( μν ) HR κ³μ μμ - λΉλ°λ²νΈ lion μμ
CREATE USER;
DROP USER ;
ALTER USER hr IDENTIFIED BY lion;
-- User HRμ΄(κ°) λ³κ²½λμμ΅λλ€.
-- ACCOUNT_STATUS : LOCKED (μ κΈ) -> hr κ³μ μ μ κΈ ν΄μ
-- ORA-28000: the account is locked
ALTER USER hr ACCOUNT UNLOCK;
ALTER USER hr IDENTIFIED BY lion ACCOUNT UNLOCK;
**Rem : μ£Όμμ²λ¦¬
μ΅κ·ΌλκΈ