(●'◡'●)
CREATE USER USER210 IDENTIFIED BY "1111";
GRANT CONNECT, RESOURCE, DBA TO USER210;
DROP USER USER210 CASCADE;
CREATE TABLE DEPT01(
DEPTNO NUMBER,
DEPTNAME VARCHAR2(12)
);
ALTER TABLE DEPT01 ADD DEPTAREA VARCHAR2(15);
ALTER TABLE DEPT01 ADD CONSTRAINT PK_DEPT01_NO PRIMARY KEY(DEPTNO);
ALTER TABLE DEPT01 MODIFY DEPTNAME NOT NULL;
ALTER TABLE DEPT01 ADD CONSTRAINT UQ_DEPT01_NAME UNIQUE(DEPTNAME);
CREATE TABLE EMP01 (
NO NUMBER PRIMARY KEY,
NAME VARCHAR2(20),
DEPTNO NUMBER,
PEMPNO NUMBER,
POSITION VARCHAR2(10),
PAY NUMBER,
REGDATE DATE,
CONSTRAINT CK_EMP01_POSITION CHECK (POSITION IN ('대리', '과장', '부장', '차장')),
CONSTRAINT FK_EMP01_DEPTNO FOREIGN KEY(DEPTNO) REFERENCES DEPT01(DEPTNO)
);
ALTER TABLE EMP01 ADD CONSTRAINT
FK_EMP01_DEPTNO FOREIGN KEY(DEPTNO) REFERENCES DEPT01(DEPTNO);
CREATE INDEX IDX_EMP01_NAME ON EMP01(NAME);
CREATE SEQUENCE SEQ_EMP01_NO START WITH 1 INCREMENT BY 1 NOMAXVALUE NOCACHE;
INSERT INTO DEPT01(DEPTNO, DEPTNAME, DEPTAREA) VALUES(101, '영업부', '');
INSERT INTO DEPT01(DEPTNO, DEPTNAME, DEPTAREA) VALUES(102, '총무부', '');
INSERT INTO DEPT01(DEPTNO, DEPTNAME, DEPTAREA) VALUES(103, '기획부', '');
INSERT INTO DEPT01(DEPTNO, DEPTNAME, DEPTAREA) VALUES(104, '홍보부', '');
INSERT INTO EMP01(NO, NAME, DEPTNO, PEMPNO, POSITION, PAY, REGDATE)
VALUES(SEQ_EMP01_NO.NEXTVAL, '김개똥', 101, 1001, '부장', 2600000, CURRENT_DATE);
INSERT INTO EMP01(NO, NAME, DEPTNO, PEMPNO, POSITION, PAY, REGDATE)
VALUES(SEQ_EMP01_NO.NEXTVAL, '김용기', 102, 1002, '차장', 2200000, CURRENT_DATE);
INSERT INTO EMP01(NO, NAME, DEPTNO, PEMPNO, POSITION, PAY, REGDATE)
VALUES(SEQ_EMP01_NO.NEXTVAL, '김희망', 103, 1003, '부장', 3100000, CURRENT_DATE);
INSERT INTO EMP01(NO, NAME, DEPTNO, PEMPNO, POSITION, PAY, REGDATE)
VALUES(SEQ_EMP01_NO.NEXTVAL, '김긍지', 104, 1004, '과장', 2900000, CURRENT_DATE);
UPDATE DEPT01 SET DEPTAREA =
CASE
WHEN (NO=101) THEN '대전'
WHEN (NO=102) THEN '서울'
ELSE '부산'
END;
COMMIT;
SELECT NO 번호, NAME 이름, POSITION 직급 FROM EMP01 ORDER BY NO DESC;
SELECT NO 번호, NAME 이름, PAY 급여,
CASE
WHEN (PAY >=0 AND PAY<=200) THEN PAY*0.05
WHEN (PAY >=201 AND PAY<=300) THEN PAY*0.1
ELSE PAY*0.15
END 세금
FROM EMP01;
SELECT * FROM EMP01 WHERE DEPTNO IN (101, 102) ORDER BY NAME ASC;
SELECT E.NO 번호, E.NAME 이름, E.PAY 급여, D.DEPTNAME 부서명, D.DEPTAREA 지역
FROM DEPT01 D, EMP01 E WHERE D.NO = E.DEPTNO;
SELECT
NO 번호, NAME 이름,
PAY 급여, TO_CHAR(PAY, '999,999,999') 급여1,
REGDATE 날짜,
TO_CHAR(REGDATE, 'YYYY"년"MM-DD HH24:MI:SS')날짜1
FROM
EMP01;
SELECT
D.DEPTNAME 부서명, AVG(E.PAY) 급여평균
FROM DEPT01 D, EMP01 E WHERE D.DEPTNO=E.DEPTNO GROUP BY D.DEPTNAME;
SELECT DEPTNO, COUNT(*) FROM DEPT01 GROUP BY(DEPTNO);
SELECT
D.DEPTNO 부서명, AVG(E.PAY) 급여평균
FROM DEPT01 D, EMP01 E
WHERE D.DEPTNO=E.DEPTNO GROUP BY D.DEPTNO HAVING AVG(E.PAY) >= 200;
CREATE OR REPLACE FUNCTION FUNC_BOARD3_SEQ RETURN NUMBER
IS
V_SEQ NUMBER := 0;
BEGIN
-- 시퀀스의 다음 숫자 가져오기
SELECT SEQ_BOARD3_NO.NEXTVAL INTO V_SEQ FROM DUAL;
RETURN V_SEQ;
END;
/
SELECT FUNC_BOARD3_SEQ FROM DUAL;
CREATE OR REPLACE VIEW BOARD33 AS
SELECT
NO, TITLE, WRITER, HIT, REGDATE,
ROW_NUMBER() OVER (ORDER BY NO DESC) ROWN
FROM
BOARD3;