--创建用户
create user zzg identified by zzg123;
--修改用户的密码
alter user zzg identified by unis;
--所有用户所在的表空间
select username,default_tablespace from dba_users;
--创建一个表空间.
create tablespace ts_zzg datafile 'f:\ts_zzg\zzg_data.dbf' size 200M;
--查询已创建的表空间
select * from DBA_DATA_FILES;
--用户分配权限
grant create session,create table,create view,create sequence,unlimited tablespace to zzg;
--查询用户所具有的权限
select *from session_privs;
--查看用户和默认表空间的关系
select username,default_tablespace from dba_users;
--查看当前用户能访问的表
select * from user_tables;
--Oracle查询用户表
select * from user_all_tables;
--Oracle查询用户视图
select * from user_views;
--查询所有函数和储存过程:
select * from user_source;
--查询所有用户:
select * from all_users;
--select * from dba_users
--查看当前用户连接:
select * from v$Session;
--查看用户角色
SELECT * FROM USER_ROLE_PRIVS;
--查看当前用户权限:
select * from session_privs;
--查看所有用户所拥有的角色
SELECT * FROM DBA_ROLE_PRIVS;
--查看所有角色
select * from dba_roles;
--查看数据库名
SELECT NAME FROM V$DATABASE;
--查看所有表空间使用情况
select a.file_id "FileNo",
a.tablespace_name "Tablespace_name",
a.bytes "Bytes",
a.bytes - sum(nvl(b.bytes, 0)) "Used",
sum(nvl(b.bytes, 0)) "Free",
sum(nvl(b.bytes, 0)) / a.bytes * 100 "%free"
from dba_data_files a, dba_free_space b
where a.file_id = b.file_id(+)
group by a.tablespace_name, a.file_id, a.bytes
order by a.tablespace_name;
Oracle 创建普通用户,并赋予权限
采用sys or system / manager as sysdba; 连接数据库。
--创建普通用户konglin:
create user konglin identified by pwd_oracle;
--删除用户,
drop user konglin;
--授予用户登录数据库的权限:
grant create session to konglin;
--授予用户操作表空间的权限:
grant unlimited tablespace to konglin;
grant create tablespace to konglin;
grant alter tablespace to konglin;
grant drop tablespace to konglin;
grant manage tablespace to konglin;
--授予用户操作表的权限:
grant create table to konglin; (包含有create index权限, alter table, drop table权限)
--授予用户操作视图的权限:
grant create view to konglin; (包含有alter view, drop view权限)
--授予用户操作触发器的权限:
grant create trigger to konglin; (包含有alter trigger, drop trigger权限)
--授予用户操作存储过程的权限:
grant create procedure to konglin;(包含有alter procedure, drop procedure 和function 以及 package权限)
--授予用户操作序列的权限:
grant create sequence to konglin; (包含有创建、修改、删除以及选择序列)
--授予用户回退段权限:
grant create rollback segment to konglin;
grant alter rollback segment to konglin;
grant drop rollback segment to konglin;
--授予用户同义词权限:
grant create synonym to konglin;(包含drop synonym权限)
grant create public synonym to konglin;
grant drop public synonym to konglin;
--授予用户关于用户的权限:
grant create user to konglin;
grant alter user to konglin;
grant become user to konglin;
grant drop user to konglin;
--授予用户关于角色的权限:
grant create role to konglin;
--授予用户操作概要文件的权限
grant create profile to konglin;
grant alter profile to konglin;
grant drop profile to konglin;
--允许从sys用户所拥有的数据字典表中进行选择
grant select any dictionary to konglin;
--查看所有用户:
select * from dba_users;
select * from all_users;
select * from user_users;
--查看用户或角色系统权限(直接赋值给用户或角色的系统权限):
select * from dba_sys_privs;
select * from user_sys_privs;
--查看角色(只能查看登陆用户拥有的角色)所包含的权限
sql>select * from role_sys_privs;
--查看用户对象权限:
select * from dba_tab_privs;
select * from all_tab_privs;
select * from user_tab_privs;
--查看所有角色:
select * from dba_roles;
--查看用户或角色所拥有的角色:
select * from dba_role_privs;
select * from user_role_privs;
--查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限)
select * from V$PWFILE_USERS
比如我要查看用户 wzsb的拥有的权限:
SQL> select * from dba_sys_privs where grantee='WZSB';
--比如我要查看用户 wzsb的拥有的角色:
SQL> select * from dba_role_privs where grantee='WZSB';
--查看一个用户所有的权限及角色
select privilege from dba_sys_privs where grantee='WZSB' union select privilege from dba_sys_privs where grantee in (select granted_role from dba_role_privs where grantee='WZSB' );
--创建表--student表
create table student(
stu_id varchar2(10) primary key,
stu_name varchar2(10) not null,
stu_sex varchar2(2) not null,
stu_birthday date,
class_id number
)
--追加注释
--添加表注释
comment on table student is '学生信息表';
--字段添加注释
comment on column student.stu_id is '学号(主键)';
comment on column student.stu_name is '学生姓名';
comment on column student.stu_sex is '学生性别';
comment on column student.stu_birthday is '学生出生年月';
comment on column student.class_id is '学生所在班级';
Oracle 自定义函数
create [or replace] function function_name
[(parameter_list)]
return datatype
{is/as}
[local_declarations]
begin
executable_statements;
[exception_handlers;]
end;
说明:
function_name:函数名称。
parameter_list:函数列表,可选。
return datatype:指定函数的返回类型,不能指定大小。
local_declarations:局部变量声明,可选。
executable_statements:要执行的PL-SQL语句。
exception_handlers:异常处理,可选。
or repalce:是否覆盖,可选。