针对此版一些ITPUB|友们提出的问题Q结合我自己常用的一些语句(关于DBA斚w的)QȝZ一
些语句如下:(以ؓ我也曄ȝq一些常用的SQL语句Q也是针Ҏ(gu)版中的),大家有兴的也可以找
?希望对大家有所帮助?br />1、查看当前数据库版本信息
select * from product_component_version;
select * from v$version;
2、授权与取消
grant 权限(如sysdba) to 用户?
revoke 权限(如sysdba) from 用户?
3、查看数据库中哪些用戯授予了sysdba?或sysoper权限
select * from v$pwfile_users;
4、更改用户密?br />alter user 用户?identified by 新密?
5、启动实例,装蝲q打开数据?br />startup
6、启动实例,不装载数据库
startup nomount
7、启动ƈ装蝲数据?br />startup mount
8、迫使实例启?br />startup force
9、打开一个关闭的数据?br />alter database open
10、以只读模式打开数据?br />alter database open read only
11、用d模式打开数据?br />alter database open read write
12、查看所有表
select * from user_all_tables;
13、查看实例名
select instance_name from v$instance;
14、查看数据库全名
select * from global_name;
15、查看表I间
select * from user_tablespaces;
16、查看某表创建的旉
select object_name,created from user_objects;
17、查看同义词
select * from user_synonyms;
18、查看当前数据库状?br />select open_mode from v$database;
19、更改ؓ只读
alter database open read only;
20、查看所有用户信?br />select username,profile,account_status from dba_users;
21、查看当前用L角色
select * from user_role_privs;
22、查看当前用Lpȝ权限
select * from user_sys_privs;
23、查看当前用L表权?br />select * from user_tab_privs;
24、设为禁?br />alter system quiesce restricted
1、查看当前所有对?
SQL> select * from tab;
2、徏一个和a表结构一LI
SQL> create table b as select * from a where 1=2;
SQL> create table b(b1,b2,b3) as select a1,a2,a3 from a where 1=2;
3、察看数据库的大,和空间用情?
SQL> col tablespace format a20
SQL> select b.file_id文gID,
b.tablespace_name 表空?
b.file_name 物理文g?
b.bytes d节数,
(b.bytes-sum(nvl(a.bytes,0))) 已?
sum(nvl(a.bytes,0)) 剩余,
sum(nvl(a.bytes,0))/(b.bytes)*100 剩余癑ֈ?
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.file_id,b.bytes
order by b.tablespace_name
/
dba_free_space --表空间剩余空间状?
dba_data_files --数据文gI间占用情况
4、查看现有回滚段及其状?
SQL> col segment format a30
SQL> SELECT SEGMENT_NAME,OWNER,TABLESPACE_NAME,SEGMENT_ID,FILE_ID,STATUS FROM DBA_ROLLBACK_SEGS;
5、查看数据文件放|的路径
SQL> col file_name format a50
SQL> select tablespace_name,file_id,bytes/1024/1024,file_name from dba_data_files order by file_id;
6、显C当前连接用?
SQL> show user
7、把SQL*Plus当计器
SQL> select 100*20 from dual;
8、连接字W串
SQL> select ?||? from ?;
SQL> select concat(?,?) from ?;
9、查询当前日?
SQL> select to_char(sysdate,'yyyy-mm-dd,hh24:mi:ss') from dual;
10、用户间复制数据
SQL> copy from user1 to user2 create table2 using select * from table1;
11、视图中不能使用order byQ但可用group by代替来达到排序目?
SQL> create view a as select b1,b2 from b group by b1,b2;
12、通过授权的方式来创徏用户
SQL> grant connect,resource to test identified by test;
SQL> conn test/test
ACCEPT | Get input from the user | |
DEFINE | Declare a variable (short: DEF) | |
DESCRIBE | Lists the attributes of tables and other objects (short: DESC) | |
EDIT | Places you in an editor so you can edit a SQL command (short: ED) | |
EXIT or QUIT | Disconnect from the database and terminate SQL*Plus | |
GET | Retrieves a SQL file and places it into the SQL buffer | |
HOST | Issue an operating system command (short: !) | |
LIST | Displays the last command executed/ command in the SQL buffer (short: L) | |
PROMPT | Display a text string on the screen. Eg prompt Hello World!!! | |
RUN | List and Run the command stored in the SQL buffer (short: /) | |
SAVE | Saves command in the SQL buffer to a file. Eg "save x" will create a script file called x.sql | |
SET | Modify the SQL*Plus environment eg. SET PAGESIZE 23 | |
SHOW | Show environment settings (short: SHO). Eg SHOW ALL, SHO PAGESIZE etc. | |
SPOOL | Send output to a file. Eg "spool x" will save STDOUT to a file called x.lst | |
START | Run a SQL script file (short: @) |