ORACLE子查詢的多種用法

2021-09-17 01:52:04 字數 865 閱讀 3043

一、用於查詢

第乙個是最普通的子查詢,子查詢 (內查詢) 在主查詢之前一次執行完成。子查詢的結果被主查詢(外查詢)使用。子查詢一般是返回單行,要是返回多行,就要用到使用多行比較操作符(in,all,any)

二、使用子查詢建立表

這就是把子查詢查詢出來的資料,建立成乙個表,表中的列的資料型別、約束和原來的一樣

例子:create table adele

asselect employee_id , last_name

from employees

三、在 update 語句中使用子查詢

在 update 中使用子查詢,使更新基於另乙個表中的資料

例子:updste employees

set    job_id = (select job_id

from   employees

where  employee_id = 150),

salary = (select salary

from   employees

where  employee_id = 150)

where employee_id = 111

四、使用子查詢建立檢視

其實這個用法和第二個用法差不多,只是乙個是建立表,乙個是建立檢視

例子:create or replace view empview

asselect employee_id , last_name

from employees

Oracle子查詢的用法

在執行資料庫操作 包括查詢 新增 修改 刪除等操作 的過程中,如果某個操作需要依賴另乙個select語句的查詢結果,那麼就可以把select語句嵌入到該操作語句中,這樣就形成了乙個子查詢。實際上,在關係型資料庫中,各表之間的資料關係非常密切,它們相互關聯,相互依存,這樣就可以根據資料之間的關係使用相...

子查詢IN的用法

今天我們要介紹的是子查詢 子查詢大家應該都不陌生啦,在很多地方可以使用到的 首先我們來總結一下 sql子查詢可以用在哪些地方 子查詢的位置 select 子查詢 from 子查詢 where 子查詢 insert table columns 子查詢 delete table from 子查詢 whe...

Oracle的查詢 子查詢

子查詢 子查詢返回乙個值 查詢出工資和scott一樣的員工資訊 select from emp where sal in select sal from emp where ename scott 子查詢返回乙個集合 查詢出工資和10號部門任意員工一樣的員工資訊 select from emp wh...