oracle練習筆記

2021-06-23 05:34:33 字數 2008 閱讀 5803



描述乙個錶用 desc employees

過濾重複的部門 select distinct department_id from employees

別名的三種方式: 1、空格 2、加as 3、" "(多個單詞組成的別名必須加空格,要麼用下劃線分開)

條件匹配日期的: where to_char(date,'yyyy-mm-dd')='1997-06-07'

預設格式: where date = '7-6月-1997'

like: where name like '%\_%' escape '\' (%:0個或者多個字元,_表示任意乙個字元,escape表示轉義關鍵字)

order by salary asc(公升序) desc(降序)

多層排序: order by salary asc,name asc (在工資相同的情況下按照名字公升序排列)

刪除表中字段重複的記錄:

delete from job_grades j1

where rowid <> (select min(rowid) from job_grades j2 where j1.grade_level = j2.grade_level);

如果刪除表中自然順序的第15行,下面語句可實現。

(rowid是資料庫的乙個偽列,建立表的時候資料庫會自動為每個表建立rowid列

用來唯一標識一行記錄。rowid是儲存每條記錄的實際實體地址,對記錄的訪問是基於rowid。)

delete from tab where rowid=(

select ii from (select rownum nn,rowid ii from tab where rownum<=15) where nn=15);

等值連線:

select employee_id,e.department_id,department_name,city

from employees e,departments d,locations l

where e.department_id = d.department_id and d.location_id = l.location_id

或者select employee_id,e.department_id,department_name,city

from employees e

join departments d on e.department_id = d.department_id

join locations l on d.location_id = l.location_id

等值連線另外方式:

select last_name,department_id,department_name

from employees join departments

--using (department_id) (前提是兩表的列名以及列的資料型別要一樣)

非等值連線

select employee_id,last_name,salary,grade_level

from employees e,job_grades j

where e.salary between j.lowest_sal and j.highest_sal

左外連線(哪邊空就把「+」號放在哪個表上)

select e.employee_id,e.last_name,d.department_name

from employees e,departments d

where e.department_id = d.department_id(+)

左外(右外、滿)連線

select employee_id,e.department_id,department_name

from employees e

left outer

--right outer

--full

join departments d on e.department_id = d.department_id

自連線

oracle上機練習

oracle上機練習 安裝oracle9i,pl sql developer圖形介面工具 全域性資料庫名稱 pp 系統識別符號 pp sys口令 change on install system口令 manager 1.建立使用者和授權 開啟工具 oracle sql plus 使用system和口...

Oracle語句練習

oracle語句練習 1切換到 oracle的 hr使用者下面練習 1.查詢工資大於12000的員工姓名和工資 select first name,last name,salary from employees where salary 12000 2.查詢員工號為176的員工的姓名和部門號 sel...

oracle 建立使用者練習

create the user create user ygwstu default tablespace ygwstu temporary tablespace temp profile default password expire grant revoke object privileges ...