-
刪除數(shù)據(jù)
DELETE語句
操作實(shí)例
DELETE FROM TABLE_NAME
[WHERE conditions];
刪除表的全部數(shù)據(jù)
無條件刪除
--復(fù)制一張表
CREATE TABLE TESTDE1
AS
SELECT * FROM USERINFO;
刪除復(fù)制的那張表
DELETE? FROM TESTDEL;
有條件刪除
DELETE FROM USERINFO
WHERE USERNAME='YYY';
查看全部 -
修改數(shù)據(jù)
UPDATE語句
操作實(shí)例
UPDATE table_name
SET column1=value1,...
[where conditions]
無條件更新
修改一個(gè)值
update userinfo
set userpwd='11111';
查詢
select userpwd from userinfo;
修改多個(gè)值
update userinfo
set userpwd='111',email='111@126.com';
查詢
select userpwd,email from userinfo;
有條件更新
update userinfo
set userpwd='123456'
where username='xxx';
select username,userpwd from userinfo;
查看全部 -
復(fù)制表數(shù)據(jù)
在建表時(shí)復(fù)制
在添加時(shí)復(fù)制
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
select * from userinfo_new1;
在添加時(shí)復(fù)制
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;
select id,usernmae from userinfo_new;
查看全部 -
操作數(shù)據(jù)
添加數(shù)據(jù)
修改數(shù)據(jù)
刪除數(shù)據(jù)
添加數(shù)據(jù)
INSERT語句
操作實(shí)例
復(fù)制表數(shù)據(jù)
INSERT語句
INSERT INTO table_name
(column1,column2,...)
VALUES(value1,value2,...)
向表中所有字段添加值
insert into userinfo
values(1,'xxx','123','xxx@.com',sysdate);
--查看插入的字段
select * from userinfo;
向表中指定的字段添加值
insert into userinfo(id,username,userpwd)
vaues(2,'yyy','123');
查看數(shù)據(jù)
select username,userpwd from userinfo
向表中添加默認(rèn)值
create table userinfo1
(id number(6,0),
regdate date default sysdate);
insert into userinfo1
values(1);?
報(bào)錯(cuò),沒有把值和字段進(jìn)行一一對(duì)應(yīng)
insert into userinfo1(id)
values(1);
--修改表
alter table userinfo
modify email default '無';
insert into userinfo(id)
values(3);
select id,email from userinfo;
insert into userinfo(id,email)
values(4,'aaa');
查看全部 -
decode函數(shù)的使用
select username,decode(username,'aaa','計(jì)算機(jī)部門','bbb','市場(chǎng)部門','其他') as 部門
from users
查看全部 -
case...when 語句的使用
?
select username ,case username when 'aaa' then '計(jì)算機(jī)部門'
when 'bbb' then '市場(chǎng)部門' esle '其他部門'? end as 部門
from users;
select username ,case? when 'aaa' then '計(jì)算機(jī)部門'
when username = 'bbb' then '市場(chǎng)部' else '其他部門' end as 部門
from users;
select username,case when salary <800 then '工資低'
when salary > '5000' then '工資高' end as 工資水平
from users;
查看全部 -
對(duì)查詢的結(jié)果排序
SELECT ... FROM ... [WHERE...]
ORDER BY column1 DESC/ASC,
select * from users order by od desc;
select * from order by id desc.salary asc;
insert into users values(4,'aaa' ,1000);
select * from order by usernmae desc ,salary asc;
查看全部 -
范圍查詢
between...and
select * from users where salary between 800 and 2000;
select * from users where salary? not between 800 and 2000;
in/not in?
select * from users where username in ('aaa','bbb');
select * from users where username in? not ('aaa','bbb');
查看全部 -
模糊查詢
username = 'aaa'
select * from users where username like 'a%';
select * from users where username like 'a_';
select username from users where username like '_a%';
select username from users where username like '%a%'
查看全部 -
帶條件的查詢
單一條件的查詢
select salary from users where username = 'aaa';
select username ,salary from users where id = 3;
多條件的查詢
查詢員工姓名是aaa,或者工資大于2000的員工信息
select * from users where username = 'aaa' or salary >2000;
select * from users where username='aaa' or ( salary>800 and salary <=2000);
select * from users where username='aaa' or salary>800 and salary <=2000;
邏輯運(yùn)算符的優(yōu)先級(jí) not ,and ,or的順序依次遞進(jìn)
比較運(yùn)算符
select * from users where not (username='aaa');
查看全部 -
select id,username,salary+200 from users;是在查詢結(jié)果中顯示,不是修改數(shù)據(jù)
使用比較運(yùn)算符
select username from users where salary>800;
使用邏輯運(yùn)算符
select username from users where salary>800 and salary <> 1800.5;
select username from users where salary>800 or salary<> 1800.5;
查看全部 -
運(yùn)算付和表達(dá)式
表達(dá)式 = 操作數(shù) * 運(yùn)算符
算數(shù)運(yùn)算符
比較運(yùn)算付
查看全部 -
給字段設(shè)置別名
顯示在查詢結(jié)果當(dāng)中,
SELECT COLUMN_NAME AS new_name from table_name;
select id as 編號(hào),username as 用戶名,salary as 工資
from users;
select distinct username as 用戶名 from user;
查看全部 -
查詢表中的所有字段及指定的字段
查詢表中的所有字段
select *?
desc users;
col id heading 編號(hào);
col username heading 用戶名;
col salary heading 工資;
查詢指定的字段
select username ,salary from users;
查看全部 -
在SQL*PLUS中設(shè)置格式
COLUMN column_name HEADING new_name
注意: column 可以簡(jiǎn)寫成col
COLUMN column_name FORMAT dataformat
注意:字符類型只能設(shè)置顯示的長度
col username format a10;
col salary format 9999.9;
col salary format $9999.9
COLUMN column_name CLEAR
col username clear;
col salary clear;
select * from user;
查看全部 -
基本查詢語句
SELECT [DISTINCT] column_name1,.....|*
FROM table_name
[WHERE conditions]
查看全部 -
查詢
基本查詢語句
在SQL*PLUS中的設(shè)置格式
查詢表里所有的字段和指定的字段
給字段設(shè)置別名 (顯示字段的查詢結(jié)果,不是給字段更改名字)
運(yùn)算符和表達(dá)式
在SELECT中使用運(yùn)算符
帶條件的查詢
模糊查詢
范圍查詢
對(duì)查詢結(jié)果排序
CASE...WHEN 語句的使用
decode函數(shù)的使用
?
查看全部 -
修改數(shù)據(jù)文件
增加數(shù)據(jù)文件
刪除數(shù)據(jù)文件
ALTER TABLESPACE tablespace_name
ADD DATAFILE 'xx.dbf' SIZE xx;
select file_name from dba_data_files where tablespace_name = 'test1_tablespace';
刪除數(shù)據(jù)文件
ALTER TABLESPACE tablespace_name
DROP DATAFILE 'test2_file.dbf;
查看全部 -
修改表空間
修改表空間的狀態(tài)
設(shè)置聯(lián)機(jī)或脫機(jī)=狀態(tài)
ALTER TABLESPACE tablespace_name offline;
desc dba_tablespaces
select status from dba_tablespaces wherespace_name = 'test1_tablespace';
ALTER TABLESPACE tablespace_name online;
設(shè)置只讀或可讀寫轉(zhuǎn)態(tài)
ALTER TABLESPACE tablespace_name
READ ONLY;
select status from dba_tablespaces wherespace_name = 'test1_tablespace';
ALTER TABLESPACE tablespace_name
READ write;
查看全部 -
查看用戶的表空間
dba_tablespaces
user_tablespaces 數(shù)據(jù)字典
select tablespace_name from dba_tablespaces;
desc user_tablespaces;
dba_users 數(shù)據(jù)字典
user_users數(shù)據(jù)字典
select default_tablespace,temporary_tablespace from dba_users where username = 'SYSTEM'
ALTER USER username
DEFAULT|TEMPORARY
TABLESPACE tablespace_name
查看全部 -
表空間
表空間概述
查看用戶的表空間
創(chuàng)建,修改,刪除表空間
表空間概述
理解表空間
表空間分類
理解表空間
數(shù)據(jù)庫與表空間
表空間與數(shù)據(jù)文件
表空間的分類
永久表空間
臨時(shí)表空間
UNDO表空間
查看全部 -
啟用scott用戶
啟用用戶的語句
alter user username account unlock
alter user scott account unlock
使用scott用戶登錄SQL plus
查看全部 -
show user 查看用戶
desc dba_users 查看數(shù)據(jù)字段
select username from dba_users;
查看全部 -
用戶與表空間
用戶
表空間
用戶
登錄SQL PLUS
查看登錄用戶
啟用scott
登錄sql plus
系統(tǒng)用戶
使用系統(tǒng)用戶登錄
系統(tǒng)用戶
sys,system (權(quán)限比較高) 密碼可以自己設(shè)定 統(tǒng)一的密碼
[username/password] [@servier] [as sysba|sysoper] 注:如果是在本地,則不需要@serve
如果數(shù)據(jù)庫不在本機(jī)
system/root? @orcl? as sysdba
orcl就是自己設(shè)置的服務(wù)名
sysman (操作管理器)? 密碼可以自己設(shè)定 統(tǒng)一的密碼
scott? ?默認(rèn)的密碼是tiger?
查看全部
舉報(bào)