--管理语句
--当前用户权限
select * from user_role_privs;
--当前用户表空间
select username,default_tablespace from user_users;
--查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限)s
select * from V$PWFILE_USERS;
--查询语句
SELECT TO_CHAR(SYSDATE,'yyyy-MM-dd HH24:mi:ss') AS NOW FROM DUAL;
select count(*) from v$process; --当前的连接数
select value from v$parameter where name = 'processes'; --数据库允许的最大连接数
select sid,serial#,username,program,machine,status from v$session WHERE PROGRAM='plsqldev.exe';
alter system kill session 'sid,serial#' ;
alter system kill session '22,13377' ;
--建表语句
create table DM_SYS_USER
(
id VARCHAR2(32) not null,
login_account VARCHAR2(100),
login_pwd VARCHAR2(50),
user_code VARCHAR2(100),
user_name VARCHAR2(100),
user_alias VARCHAR2(100),
sex VARCHAR2(10),
email VARCHAR2(100),
user_state VARCHAR2(10),
user_type VARCHAR2(100),
memo VARCHAR2(500),
disp_num NUMBER(10),
update_user VARCHAR2(32),
update_date DATE
)
comment on table DM_SYS_USER
is '系统用户表';
-- Add comments to the columns
comment on column DM_SYS_USER.login_account
is '登录账号';
comment on column DM_SYS_USER.user_code
is '用户编码,类似于学生的学号';
comment on column DM_SYS_USER.user_name
is '用户姓名';
comment on column DM_SYS_USER.user_alias
is '用户别名,昵称';
comment on column DM_SYS_USER.sex
is '性别 0 男 1女';
comment on column DM_SYS_USER.user_state
is '用户状态:R:已注册 U:已审批 L:锁定 D:删除';
comment on column DM_SYS_USER.user_type
is '用户类型';
comment on column DM_SYS_USER.memo
is '描述,说明';
comment on column DM_SYS_USER.disp_num
is '排序';
comment on column DM_SYS_USER.update_user
is '更新人';
comment on column DM_SYS_USER.update_date
is '更新时间';
-- Create/Recreate primary, unique and foreign key constraints
alter table DM_SYS_USER
add constraint DM_SYS_USER primary key (ID)
--查看表占用空间大小
analyze table T_LOGSRV_SERVICE compute statistics;
select num_rows * avg_row_len / 1024 / 1024 as "实际占用大小(M)"
from user_tables
where table_name = 'T_LOGSRV_SERVICE';
select sum(bytes) / (1024 * 1024) as "分配大小(M)"
from user_segments
where segment_name = 'T_LOGSRV_SERVICE';
--时间处理
select to_date(t.update_time,'yyyymmddhh24miss'),to_date(t.update_time,'yyyymmddhh24miss')+rownum/24/60 as cudate,rownum from t_uaac_user t;
--添加字段
ALTER TABLE T_SMC_SERVICE_CATEGORY ADD DELETE_FLAG VARCHAR2(1);
ALTER TABLE T_SMC_SERVICE_CATEGORY ADD SORT NUMBER;
--查看当前用户下表以及表的注释信息
SELECT a.TABLE_NAME, b.COMMENTS
FROM user_tables a, user_tab_comments b
WHERE a.TABLE_NAME = b.TABLE_NAME
ORDER by TABLE_NAME;
--查看数据库版本号
select * from product_component_version;