---
# System prepended metadata

title: oracle

---

啟動容器：sudo docker start oracle
進入容器：sudo docker exec -it oracle bash
切換使用者至oracle:su - oracle
以dba身份連接sqlplus:sqlplus / as sysdba
普通使用者登入：sqlplus username/password 
建立使用者：create user yuyu identified by password;
顯示資料庫所有使用者：SELECT username, account_status, created FROM dba_users ORDER BY created;
用戶授權：grant resource,connect,dba to yuyu;
**確認：commit;**
查看所有表空间:select TABLESPACE_NAME,STATUS from dba_tablespaces;
查看某表在何表空間：SELECT tablespace_name 
FROM dba_tables 
WHERE table_name = 'DIE_INFO';（dba）
创建表空间:CREATE TABLESPACE a3db 
DATAFILE '/u01/app/oracle/oradata/a3db.dbf' 
SIZE 50M 
AUTOEXTEND ON 
NEXT 10M 
MAXSIZE UNLIMITED
LOGGING;
將空間分配給使用者：ALTER USER yuyu DEFAULT TABLESPACE a3db;
CREATE TABLE MES_STRIP
    ( DEVICES_BONDED    INT
    , STATION  VARCHAR2(30)
    , IMPORT_DATE       DATE) ;
检查 Oracle 监听器配置：lsnrctl status
建立同義詞：CREATE PUBLIC SYNONYM MES_STRIP FOR SYS.MES_STRIP;
刪除同義詞：DROP PUBLIC SYNONYM MES_STRIP;
INSERT INTO DIE_INFO (
    LOT_NO, YEAR_CODE, EC_NO, EFF_DATE, ITEM_NO, 
    MFG_ID, DIE_SEQ, DIE_LEVEL, DIE_STATION, DIE_SIZE_X, 
    DIE_SIZE_Y, GRIND_THI_ASS, GRIND_THI_UCODE, STD_THICK_AVG_CHK, 
    GRIND_MIL_STRING, RECORD_ID_RAW, IMPORT_DATE, UPDATE_TIME
) VALUES (
    DBMS_RANDOM.STRING('U', 6),
    TO_CHAR(DBMS_RANDOM.VALUE(2020, 2025), 'FM9999'),
    DBMS_RANDOM.STRING('U', 20),
    TO_CHAR(SYSDATE + DBMS_RANDOM.VALUE(-365, 365), 'YYYYMMDD'),
    DBMS_RANDOM.STRING('U', 10),
    DBMS_RANDOM.STRING('U', 12),
    TO_CHAR(DBMS_RANDOM.VALUE(1, 10), 'FM999'),
    TO_CHAR(DBMS_RANDOM.VALUE(1, 10), 'FM9'),
    TO_CHAR(DBMS_RANDOM.VALUE(1000, 5000), 'FM9999'),
    ROUND(DBMS_RANDOM.VALUE(1000, 6000)),
    ROUND(DBMS_RANDOM.VALUE(1000, 8000)),
    DBMS_RANDOM.VALUE(0.5, 3.5),
    DBMS_RANDOM.STRING('U', 5),
    DBMS_RANDOM.STRING('U', 5),
    DBMS_RANDOM.STRING('U', 5),
    DBMS_RANDOM.STRING('X', 32),
    TO_CHAR(SYSDATE - DBMS_RANDOM.VALUE(0, 365), 'YYYY/MM/DD'),
    TO_CHAR(SYSDATE - DBMS_RANDOM.VALUE(0, 365), 'YYYY/MM/DD HH24:MI:SS')
);
確認欄位資料型態：SELECT data_type
FROM all_tab_columns
WHERE table_name = 'DIE_INFO' AND column_name = 'IMPORT_DATE';

