ORACLE基礎 3 操作表

2021-08-20 11:13:59 字數 1854 閱讀 6155

新增資料:insert into table_name(column1,column2,...) values(value1,value2,...);

表名和值必須對應,如果在所有欄位都新增值,表名可以省略 後面順序必須匹配

舉例:insert into userinfo values(1,'***','123','***@126.com',sysdate);

sysdata是獲取當前日期

檢視資料:select * from userinfo;

舉例:insert into userinfo(id,username,userpwd) values(2,'yyy','123');

select username,userpwd from userinfo;

如果某些字段不能為空,必須新增值

向表中新增預設值:

1.建立表時 create table userinfo1(id number(6,0),regdate date default sysdata);

insert into userinfo(id) values(1);

2.修改表時 alter table userinfo modify email default '無';

insert into userifno(id) values(3);

insert into userifno(id,email) values(4,'aaa');    不採用預設值

複製表資料:從其他表中把表資料放到表裡面

在建表時複製:create table table_new as select column1,...|*from table_old;

舉例:create table userinfo_new as select * from userinfo;

舉例:create table userinfo_new1 as select id,username from userinfo;

在新增時複製:insert into table_new [(column1,...)] select column1,...|* from table_old;

注意:插入的資料要與原來的匹配

舉例:insert into userinfo_new select * from userinfo;

舉例:insert into userinfo_new(id,username) select id,username from userinfo;

修改資料:

update table_name set column1=value1,...[where condition];

注意:where如果省略,表示全部資料

無條件跟新:updata userinfo set userpwd='111111';

updata userinfo set userpwd='111',email='[email protected]';

有條件跟新:updata userinfo set userpwd='123456' where username='***';

刪除資料:

刪除比我們新增和修改容易得多,不用考慮某乙個字段,因為在oracle資料庫中,是以行位單位進行刪除資料的,不能刪除某一列的資料

delete from table_name;

表示刪除表裡面的全部資料 和truncate結果一樣的

但是從刪除的角度來說,truncate是截斷表,刪除的速度比delete要快

如果我們不想把錶的資料都刪掉我們可以

delete from table_name[where condition];

舉例:delete from userinfo;

delete from userinfo where username='yyy';

Oracle基礎 管理表與操作表資料

約定 char n nchar n 不可變長度型別 nchar是按照unicode格式存放資料 char的n最大值為2000 nchar的n最大值為1000 varchar2 n nvarchar2 n 可變長度型別 varchar2的n最大值為4000 nvarchar2的n最大值為2000 nu...

mysql基礎 3 表的基本操作

show tables 建立乙個名為infor的表,注意id 約束是自增 主鍵 非空 性別用0,1表示。create table infor id int auto increment primary key not null,name varchar 10 not null,age int not...

oracle基礎操作

資料匯出 1 將資料庫test完全匯出,使用者名稱system 密碼manager 匯出到d daochu.dmp中 exp system manager test file d daochu.dmp full y 2 將資料庫中system使用者與sys使用者的表匯出 exp system man...