用戶登陸
Connect
查看當(dāng)前用戶
Show user;
查看所有用戶
Select username from dba_users;
創(chuàng)建用戶
Create user 'Name' identified by 'Password';
授BDA最高權(quán)限
Grant DBA to 'Name';
授所有普通權(quán)限
Grant connect,reource to 'Name';
授權(quán)登陸
Grant create session to 'Name';
授權(quán)建表
Grant create table BMW();
授權(quán)無限表空間
Grant create umlimited tablespace to 'Name';
授查詢權(quán)限
Grant select on BMW to 'Name';
撤消查詢權(quán)限
Revoke select on BMW to 'Name';
修改自己的密碼(登陸自己的用戶)
Alter user 'name' identified by 'password';
修改別人的密碼(登陸超級(jí)用戶)
Alter user 'name' identified by 'password';
不輸入密碼登陸(*只能登陸SYS用戶)
Connect / as sysdba
數(shù)據(jù)庫(kù)操作部分
建表
create table BMW(
2 SN number(10) constraint zph1 primary key,
3 Model varchar2(20) constraint zph2 not null,
4 Color varchar2(10) constraint zph3 references BMW(Color),
5 Barcode number(30) constraint zph4 unique,
6 Price number(7) constraint zph5 check(Price between 10 and 90));
添加字段
Alter table 'Apellation' add('fieldname' 'fieldtype');
刪除字段
Alter table 'Apellation' drop column 'fieldname';
修改字段長(zhǎng)度
Alter table 'Apellation' modify('fieldname' 'fieldtype');
修改字段類型
Alter table 'Apellation' modify('fieldname' 'fieldtype');
向表中插入一條記錄(所有字段)
Insert into 'Apellation' values('data','data',data,);
向表中插入一條記錄(部分字段)
Insert into 'Apellation'('fieldname') values('data');
修改表中一個(gè)字段
Updata 'Apellation' set 'fieldname'='xxx' where 'fieldname'='id';
刪除表中所有記錄
Delete from 'Apellation';
刪除表的結(jié)構(gòu)和記錄
Drop table 'Apellation';
查看某個(gè)表所有記錄
Select * from 'Apellation';
查看某個(gè)表指定記錄
Select 'fieldname','fieldname' from 'Apellation';
查看別人的表的記錄(在別人先授查表權(quán)情況下)
Select * from 'name'.'Apellation';
查看當(dāng)前用戶下所有表
Select * from tab;
查看表結(jié)構(gòu)
desc 'Apellation';
控制不換行顯示
Set linesize 'Parameter'
控制每頁(yè)顯示行數(shù)
Set pagesize 'Parameter'
升序排列顯示
Select * from 'Apellation';
交互式插入記錄
Insert into 'Apellation' values('&data','&data',&data,);
轉(zhuǎn)義字符
set escape on
Insert into 'Apellation' values('data','data',da\&ta,);
特殊命令部分
清除屏幕
Clear screen
文件日志命令
Spool F:\zph.txt
Spool off
提交命令
Commit
回滾命令
Rollback
設(shè)置保存點(diǎn)
Savepoint 'zph1'
查當(dāng)前日期格式
select * from nls_session_parameters;
更改日期格式
Alter session set nls_date_format='yyyy-mm-dd';
更改數(shù)字顯示格式
Column barcode format 999999999999999999999999999999;
調(diào)整行寬
Set linesize 200
調(diào)整顯示字?jǐn)?shù)
Set pagesize 100