90 likes | 308 Views
4. Oracle SQL. SQL. DDL Data Definition Language ( 資料定義語言 ) DML Data Manipulation Language ( 資料處ç†èªžè¨€ ). DDL. Example. SQL*Plus. SQL> connect teacher/oracle@210.240.223.171 SQL> create table b (colb char(1)); SQL> drop table b; SQL> create table state
E N D
SQL • DDL • Data Definition Language (資料定義語言) • DML • Data Manipulation Language (資料處理語言)
Example • SQL*Plus SQL> connect teacher/oracle@210.240.223.171 SQL> create table b (colb char(1)); SQL> drop table b; SQL> create table state 2 (state_cd char(2) not null, 3 state_name varchar2(20)); SQL> desc state; 連結資料庫 分號是命令的結束強迫執行 或者在新行用 / 分行會自動出現行數 Describe用來顯示資料表細節
Exercise (練習) • P.2-8~p.2-10 • HR範例
DML • Select • 檢索資料表 • Insert • 新增資料 • Update • 修改資料 • Delete • 刪除資料
Example • Insert • Delete • Update SQL> INSERT INTO employees (employee_id, last_name, email, hire_date, job_id, salary) VALUES (11, 'Doe', 'jane.doe', '31-AUG-05', 'SH_CLERK', 2400); SQL> DELETE FROM employees WHERE employee_id = 10 OR employee_id = 11; SQL> UPDATE employees SET salary = salary * 1.05 WHERE employee_id = 11;
Example • select SQL> SELECT * FROM employees; SQL> SELECT employee_id, last_name, first_name FROM employees; SQL> SELECT * FROM employees WHERE manager_id = 122; SQL> SELECT * FROM employees WHERE manager_id = 122 AND job_id = 'ST_CLERK‘; SQL> SELECT employee_id, last_name FROM employees WHERE last_name LIKE '%mar%‘; SQL> SELECT employee_id, last_name FROM employees WHERE commission_pct IS NOT NULL; SQL> SELECT employee_id, last_name, first_name FROM employees WHERE employee_id IN (125, 130, 135);