oracle常用的SQL語句

2021-09-02 04:22:21 字數 1661 閱讀 7494

1.標準insert --單錶單行插入

insert into dep (dep_id,dep_name) values(1,'技術部');
2. 無條件 insert all --多表多行插入

insert all

into sal_history(emp_id,hire_date,salary) values (empid,hiredate,sal)

into mgr_history(emp_id,manager_id,salary) values (empid,hiredate,sal)

select employee_id empid,hire_date hiredate,salary sal,manager_id mgr

from employees

where employee_id>200;

3. 有條件的insert

備註:a.當使用all關鍵字時,oracle會從上至下判斷每乙個條件,當條件滿足時就執行後面的into語句

在上面的例子中,如果id=6 那麼將會在z_test1中插入一條記錄,同時也在z_test2中插入一條記錄

b.當使用first關鍵字時,oracle會從上至下判斷每乙個條件,當遇到第乙個滿足時就執行後面的into語句,

同時中斷判斷的條件判斷,在上面的例子中,如果id=6,僅僅會在z_test1中插入一條資料

insert all

when id>5 then into z_test1(id, name) values(id,name)

when id<>2 then into z_test2(id) values(id)

else into z_test3 values(name)

select id,name from z_test;

4. 旋轉insert (pivoting insert)

insert all

into sales_info values(employee_id,week_id,sales_mon)

into sales_info values(employee_id,week_id,sales_tue)

into sales_info values(employee_id,week_id,sales_wed)

into sales_info values(employee_id,week_id,sales_thur)

into sales_info values(employee_id,week_id,sales_fri)

select employee_id,week_id,sales_mon,sales_tue,

sales_wed,sales_thur,sales_fri

from sales_source_data;

5.常用查詢保留小數字數的函式

select round(100/3,4) from dual;

select trunc(100/3,4) from dual;

oracle常用sql語句

1.解鎖oracle使用者下某個使用者 以內建的scott使用者為例 sql conn as sysdba sql alter user scott account unlock identified by tiger 解釋 首先要切換到sysdba使用者下,否則會提示 許可權不足 error at...

oracle常用SQL語句

最近專案中用到,現記錄一下 新增主鍵 alter table shop spec detail add constraint spec detail id primary key id 新增索引 create index spec detail id on shop spec detail id 給...

Oracle常用SQL語句

今天接到乙個新任務 任務的主要內容簡單點說就是乙個下拉框,乙個查詢條件,乙個 table 顯示。當聽完的時候感覺真的是很簡單,這樣的事情也並非沒有做過。但是當靜下心來仔細分析需求,則會發現其與眾不同之處。1 下拉框中顯示的是我們整個模組的表名稱 2 查詢條件初步設想是根據時間查詢 3 table 第...