创建表空间: create tablespace xx logging datafile '/oracle/xx.dbf' size 500m autoextend on next 32m maxsize 2000m extent management local 查看一个实例下的所有表空间: SELECT F.TABLESPACE_NAME "表空间名", T.TOTAL_SPACE "空间总量", T.TOTAL_SPACE - F.FREE_SPACE "已使用空间", F.FREE_SPACE "可用空间", ROUND((F.FREE_SPACE/T.TOTAL_SPACE)*100)||'%' "可用比例" FROM (SELECT TABLESPACE_NAME,ROUND(SUM(BYTES)/1024/1024)FREE_SPACE FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME ) F, (SELECT TABLESPACE_NAME, ROUND (SUM(BYTES)/1024/1024) TOTAL_SPACE FROM DBA_DATA_FILES GROUP BY TABLESPACE_NAME ) T WHERE F.TABLESPACE_NAME = T.TABLESPACE_NAME order by 1 --察看当前系统的下面参数的情况 show parameter open_cursor; show parameter process; show parameter session; show parameter large_pool_size; show parameter java_pool_size; show parameter java_max_sessionspace_size; show parameter shared_pool_size; 删除表空间: drop tablespace xx including contents and datafiles 删除表空间,使用命令drop tablespace ‘表空间名’ 但是有3个选项需要注意: INCLUDING CONTENTS:指删除表空间中的segments; INCLUDING CONTENTS AND DATAFILES:指删除segments和datafiles; CASCADE CONSTRAINTS:删除所有与该空间相关的完整性约束条件。 例: Sql代码 DROP TABLESPACE FESCO INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS; 扩展表空间: ALTER TABLESPACE xx_data_test ADD DATAFILE 'E:\db\xx_data_test_extend_1221.dbf' SIZE 250M; --删除用户(有需要才执行此语句) drop user xx_090415 cascade; --创建用户(根据实际情况,调整用户名,默认表空间,临时表空间) create user xx_090415 identified by xx_090415 default tablespace xx_090415 temporary tablespace TEMP; -- Grant/Revoke role privileges grant dba to xx_090415 with admin option; grant connect to xx_090415 with admin option; grant resource to xx_090415 with admin option; -- Grant/Revoke system privileges grant select any table to xx_090415 with admin option; grant create any view to xx_090415 with admin option; grant select any dictionary to xx_090415 with admin option; grant create any table to xx_090415 with admin option; dba执行以下语句查看是否有死锁,有记录表示有死锁,没则没有死锁 select username,lockwait,staus,machine,program from v$session where sid in(select session_id from v$locked_object) 查看数据文件放置的路径 select tablespace_name,file_id,bytes/1024/1024,file_name from dba_data_files order by file_id; 1、查看当前所有对象 SQL> select * from tab; 2、建一个和a表结构一样的空表 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 文件ID, b.tablespace_name 表空间, b.file_name 物理文件名, b.bytes 总字节数, (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 --数据文件空间占用情况 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、显示当前连接用户 SQL> show user 7、把SQL*Plus当计算器 SQL> select 100*20 from dual; 8、连接字符串 SQL> select 列1||列2 from 表1; SQL> select concat(列1,列2) from 表1; 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 by,但可用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
ora常用
最新推荐文章于 2024-08-21 21:40:52 发布