---
# System prepended metadata

title: ORACLE CHAPTER.4
tags: [Ming, ORACLE]

---

# ORACLE CHAPTER.4
###### tags: `Ming` `ORACLE` 

{%hackmd BJrTq20hE %}

Question.4-1

--先設立序號產生器
    CREATE SEQUENCE SEQ_EMPLOYEE_ID;
--設定目標Table要輸入的欄位
    INSERT INTO EMPLOYEE(EMPLOYEE_ID, NAME)
--輸入序號產生器函式和其他欄位的值
    VALUES(SEQ_EMPLOYEE_ID.NEXTVAL, 'MING');
    COMMIT;

CREATE SEQUENCE SEQ_CUSTOMER_ID;
INSERT INTO CUSTOMER(CUSTOMER_ID, CUSTOMER_NAME, PHONE, ADDRESS)
VALUES(SEQ_CUSTOMER_ID.NEXTVAL, 'Anderson', '0919195xxx', '中壢區五興路xxx巷'); 
COMMIT;

CREATE SEQUENCE SEQ_ORDER_ID;
INSERT INTO ORDER_MASTER(ORDER_ID, CUSTOMER_ID)
VALUES(SEQ_ORDER_ID.NEXTVAL, '23');
COMMIT;

INSERT INTO ORDER_DETAIL(ORDER_ID, ISBN, QUANTITY)
VALUES('102', '9780596009205' , '2');
COMMIT;

Question.4-2

--直接下指令對資料更改
    UPDATE CUSTOMER SET CUSTOMER_NAME = 'Ken', PHONE = '03-456789', ADDRESS =     'Taoyuan'
    WHERE CUSTOMER_ID = '23';
    ROLLBACK;
    COMMIT;

UPDATE ORDER_DETAIL SET QUANTITY = '10'

--設定複合條件
WHERE (ORDER_ID = '102' AND ISBN = '9780596009205');
-----------------------------------------------------------------------------
ROLLBACK;
COMMIT;

Question.4-3
--刪除資料
    DELETE FROM PUBLISHER WHERE PUBLISHER_ID = 'P00X';
    DELETE FROM ORDER_DETAIL WHERE ORDER_ID = '102';
    DELETE FROM ORDER_MASTER WHERE ORDER_ID = '102';
    DELETE FROM CUSTOMER WHERE CUSTOMER_ID = '23';
    ROLLBACK;
    COMMIT;
