oracle 資料庫插入 更新 刪除 資料比較

2021-09-27 01:46:11 字數 1530 閱讀 3108

create table stu_user (id varchar2(36),name varchar2(36),sale number(10,3));

create table testfunc (id varchar2(36),name varchar2(36),sale number(10,3));

insert into testfunc (id,name,sale) values ('1','jack',3400);

insert into testfunc (id,name,sale) values ('2','jack',2400);

insert into testfunc (id,name,sale) values ('3','jack',1400);

select * from stu_user;

select * from testfunc;

-- 新增字段

alter table testfunc add (add1 varchar2(10));

-- 更新字段

update testfunc set add1 = null;

-- 修改字段

alter table testfunc modify(add1 varchar(2));

-- 重新命名字段

alter table testfunc rename column add1 to add2;

-- 刪除字段

alter table testfunc drop column add2

-- 刪除表

drop table stu_user;

-- 刪除表資料

truncate table stu_user;

-- 刪除指定記錄

delete stu_user where id = '3';

-- insert into 從一張表匯入到另一張表

insert into stu_user select * from testfunc;

-- update select 

update stu_user s set sale = (select sale from testfunc t where t.id = s.id);

-- minus 兩個查詢進行資料比較,欄位名要一致

select * from testfunc 

minus 

select * from stu_user;

-- merge into  要保證後乙個查詢有資料 ,

merge into stu_user t1

using (select * from testfunc) t2 on (t1.id=t2.id)-- 是否滿足on的條件,若滿足,則執行1,不滿足則執行2

when matched then update set t1.name=t2.name --1.更新、刪

when not matched then insert (t1.id, t1.name,t1.sale) values (t2.id,t2.name,t2.sale);--2.更新、刪除、插入

資料庫插入 更新 刪除操作

1.插入資料 1 為表中的所有的字段插入資料 insert into 表名稱 欄位1,欄位2,欄位3.vaues 值1,值2,值3.括號內為根據所建立的字段型別逐一進行插入,逐一在給字元型別資料插入的時候,使用單引號 2 為表的指定指端插入資料 insert into 表名稱 指定欄位1,指定欄位2...

MYSQL資料庫學習 插入 更新 刪除

一 插入資料 1 為表的所有字段插入資料 insert into 表名 值1,值2,值3.2 為表的指定字段插入資料 insert into 表名 欄位1,欄位2,values 值1,值2,3 為表同時插入多條記錄 insert into 表名 欄位1,欄位2,values 值1,值2,值1,值2,...

資料庫操縱語言(更新 插入 刪除)

資料庫操縱語言 更新 插入 刪除 sql alter table a add age number 9 table altered.刪表sql drop table a table dropped.建表sql create table a 2 id number 10 3 name varchar2...