一数据库用户及表的创建
/*分为四步 */
/*第1步:创建临时表空间 */
create temporary tablespace user_temp
tempfile ‘D:\oracle\oradata\Oracle9i\user_temp.dbf’
size 500m
autoextend on
next 50m maxsize 20480m
extent management local;
/*第2步:创建数据表空间 */
create tablespace user_data
logging
datafile ‘D:\oracle\oradata\Oracle9i\user_data.dbf’
size 500m
autoextend on
next 50m maxsize 20480m
extent management local;
/*第3步:创建用户并指定表空间 */
create user username identified by password
default tablespace user_data
temporary tablespace user_temp;
/*第4步:给用户授予权限 */
grant connect,resource,dba to username;
/*第5步:去掉密码180天限期 */
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
/*去掉空表导出 */
alter system set deferred_segment_creation=false;
二、查看表空间大小及相关
----------------参看表空间以及表空间大小
SELECT SUM(bytes) / (1024 * 1024) AS free_space, tablespace_name
FROM dba_free_space
GROUP BY tablespace_name;
---------------查看表空间所占大小比
由于$符在编辑后展示出来的和原文不符,因此使用图片
----------------增加表空间
ALTER TABLESPACE GBDS_DATA ADD DATAFILE
‘F:\ORACLE\ORADATA\GBDS_DATA01.DBF’ SIZE 50M
AUTOEXTEND ON NEXT 5M MAXSIZE 100M;
-----------------扩大表空间大小
alter database datafile ‘F:\ORACLE\ORADATA\GBDS_DATA01.DBF’ resize 2000m ;
-------------查看表空间位置以及大小
select tablespace_name, file_id, file_name,round(bytes/(1024*1024),0) total_space from dba_data_files order by tablespace_name ;
–数据查询DBA用户、表空间、表空间路径
select username from dba_users ;
select tablespace_name from dba_tablespaces;
select file_name , tablespace_name from dba_data_files;
—查看数据库和表空间关系
select username,default_tablespace from dba_users;
三、查看锁表及解锁
-----查询锁表语句
select p.spid,
a.SID,
a.serial#,
c.object_name,
b.session_id,
b.oracle_username,
b.os_user_name
from v
p
r
o
c
e
s
s
p
,
v
process p, v
processp,vsession a, vKaTeX parse error: Expected 'EOF', got '#' at position 174: … b.sid,b.serial#̲ from vlocked_object a,v$session b
where a.session_id = b.sid group by b.sid,b.serial#;
begin
for cur in mycur
loop
execute immediate ( ‘alter system kill session ‘’’||cur.sid || ‘,’|| cur.SERIAL# ||’’’ ');
end loop;
end;
四、根据唯一约束查看表名及替换表名
----根据唯一约束查找表名
select constraint_name,constraint_type,table_name from all_constraints where CONSTRAINT_NAME=‘PK_ID’;
----替换表名称
ALTER TABLE table_old RENAME TO table_new;
五、数据库连接数
select count(*) from v
p
r
o
c
e
s
s
;
−
−
当
前
的
连
接
数
s
e
l
e
c
t
v
a
l
u
e
f
r
o
m
v
process; --当前的连接数 select value from v
process;−−当前的连接数selectvaluefromvparameter where name = ‘processes’; --数据库允许的最大连接数
alter system set processes = 2000 scope = spfile; --修改最大连接数:
六、查重
–查重语句
select id, name, memo
from A
where id in (select id from A group by id having count(1) >= 2);
–去重语句 --删除ENT_CNAME 重复的语句。
delete from T_table
where ENT_CNAME in (select ENT_CNAME from T_table group by ENT_CNAME having count(ENT_CNAME) > 1)
and rowid not in (select min(rowid) from T_table group by ENT_CNAME having count(ENT_CNAME )>1) ;
七、重启数据库
–重启数据库
(1) 以oracle身份登录数据库,命令:su -oracle
(2) 进入Sqlplus控制台,命令:sqlplus /nolog
(3) 以系统管理员登录,命令:connect / as sysdba
(4) 启动数据库,命令:startup
(5) 如果是关闭数据库,命令:shutdown immediate
(6) 退出sqlplus控制台,命令:exit
(7) 进入监听器控制台,命令:lsnrctl
(8) 启动监听器,命令:start
(9) 退出监听器控制台,命令:exit