??xml version="1.0" encoding="utf-8" standalone="yes"?>
grant connect,create table to test1;
conn cyts_cc/cyts_cc@orcl2000;
create table(
id int)
tablespace user;
ERROR 位于W?1 ?
ORA-01950: 表空?USERS'中无权限
conn cyts_cc/cyts_cc@orcl2000;
alter user test1 quota 1M on users;
create tab
(id int);
success
alter user test1 account lock;
conn test1/test1@orcl2000;
ERROR:
ORA-28000: the account is locked
1 Database Schema
a schema is a named collection of objects
b user is created and a corresponding schema is created
c user can be associated only with one schema
d username and schema are often userd interchangely.
2 Checklist for creating users
a idntfigy tablespaces in which the usr nedds to store objects
b decide on quotas for each tablespace
c assign a default tablespace and temporary tablespace.if you do not specify at the time of create user,system tablespace will be the defalut tablespace and temporary.it will affect the performance of the oralce.
d create user
e grant privileges and roles to user
desc dba_users;
select * from dba_users;
3 Creating a new user:
Database Authentiacation
set the initial password
create user aaron
identified by soccer
default tablespace data
temporary tablespace temp
guota 15m on data
password expire;
alter database default temporary tablespace temp;
4 Creating a new user operating System Authentication
os_authent_prefix initialllization parameter specifies the format of the username
defauts to ops$
create user arron
identified externally
default tablespace users
temporary tablespace temp
quota 15m on data
password expire;
conn /
show parameter os
os_authent_prefix string OPS$
create user ops$test3
identified externally
default tablespace us
temporary tablespace
quota 10m on users
thee test2 is an user of os ,which the oracle is installed.
5 Changing user quota on tablespace
alter user test3 quota 4m on users;
you cann't grant quota on temp and undotbs.
alter quota 0 on uers -- means that no new table space can be allocated and cannot change the exist object in the tablespaces
6 drop user
you cannot drop user who has connected to oracle
drop user (cascade)
7 Obtaining User information
information about uers can be obtained by qerying the data dictionary
dba_users
名称
-----------------------------
USERNAME
USER_ID
PASSWORD
ACCOUNT_STATUS
LOCK_DATE
EXPIRY_DATE
DEFAULT_TABLESPACE
TEMPORARY_TABLESPACE
CREATED
PROFILE
INITIAL_RSRC_CONSUMER_GROUP
EXTERNAL_NAME
dba_ts_quotas
名称
---------------
TABLESPACE_NAME
USERNAME
BYTES
MAX_BYTES
BLOCKS
MAX_BLOCKS
5 set operator guidelines
. teh expressions in the select list must match in number and data type;
. Parentheses can be used to alter the sequence of the execution
.The order by clause:
can appear only at the very end of the statement
will accept the column name,aliases from thee firest select statement ,or thee positional notation
.Duplicate row are atuomatically eliminated except in union all.
.Column names from the first query appear in the result
.The output is sorted in ascending order by default except in union all
6 matching the select statement
select department_id,to_number(null),location,hire_date
from employees
union
select department_id,location_id,to_date(null)
from departments;
select employee_id,job_id,salary
from employees
union
select employee_id,job_id,0
from job_history;
7 Controlling the order of the rows
select 'sing' as "my dream" ,3,a_dummy
from dual
union
select 'like''d like to teach',1
from dual
union
select 'the world to',2
from dual
order by 2;
4) 带有 in out 参数
create or replace function result
(num1,number,num2 in out nu8mber)
return number
as
v_result number(6);
v_remainder number;
begin
v_result:=num1/num2;
v_remainder:=mod(num1,num2);
num2:=v_remainder;
retrun v_result;
exception
when zero_divide then
raise_application_error(-20000,'zero divied');
end;
5) 函数调用的限?br /> -- 在sql 语句中只能调用存储函?br /> -- 在sql 语句中只能调用带有输入参数in Q而不能有输出参数out 和in out 参数的函?br /> -- 在sql 语句中调用的函数的参数必L标准的sql 数据cdQ不能是pl/sql 所Ҏ的数据类?br /> -- 在sql 语句中调用的函数不能包含insertQupdate 和delete
6) 查看源代?br /> set pagesize 40
select text form user_source where name='result';
7) 删除函数
drop function result;
3 理子程?br /> 1) 列出当前用户的子E序
select object_name,created,status form user_objects
where object_type in ('procedure','function');
2)列出子程序源代码
select text from user_sorce where name='raise_salary'
3)cd子程序编译错?br /> -- show errors
--使用数据字典user_errors 定错误原因和位|?br /> select line||'/'||position as "line/col",text error
from user_errors where name='raise_salary';
4) 列出对象的依赖关p?br /> -- 使用 user_dependenciess 定直接依赖关系
select name,type from user_dependencies
where referenced_name='emp'
-- 使用 deptree ?ideptree 定依赖和见解依赖关p?br /> select nested_level,name,type from deptree;
5) 重新~译子程?br /> 当被应用对象的结构被修改以后Q就会将相关依赖对象转变为无效invalid Q需要重新编?br /> 1
alter table emp add remark varchar2(100);
2
select object_name,object_type from user_objects
where status='invalid'
3
alter procedure add_employee compile;
alter view dept10 compile;
alter function get_info compile;
end;
)
3) 限制行触发器
当用行触发器,默认情况下会咱每个被作用行上七星一ơ触发器代码Qؓ了时得再特定条g下执行行触发器代码,需要用when 子句
create or replace trigger tr_sal_change
after update of sal on emp
for each row
when(old.job='salesman')
declare
v_temp int..
2 dml 触发器用注意事?br /> 触发器代码不能从触发器所对应的基表中d数据
3 dml 触发?br /> Z保证数据库满特定的商业规则或企业逻辑Q可以用约束,触发器和子程序。约束性能最好,实现最单,所以ؓ售选,如果触发器不盟实玎ͼ可以选择触发器?br /> dml 触发器可以用于实现数据安全保护,数据审计Q数据完整性,参照完整性,数据复制{功能?br /> 1) 控制数据安全
create or replace trigger tr_emp_time
before insert or update or delete on emp
begin
if to_char(sysdate,'hh24') not between '9' and '17' then
raise_application_error(-20101,'not work time');
end if;
end;
2) 实现数据审计
使用数据审计只能审计sql 操作Q而不会记载数据变?br /> audit insert,update,delete on emp by access
3)实现数据完整?br /> 首选约?alter table emp add constraint ck_sal check (sal>=800),但是在有些情况下只能使用触发器来实现数据完整?br /> create or replace trigger tr_check sal
before update of sal on emp
for each row
when (new.sla<old.sal or new.sal>1.2* old.sal)
begin
raise_application_error(,,,,,,)
end;
3) 使用引用完整?br /> 采用 on delete cascade 可以q行集联删除Q但是却不能q行集联更新。采用触发器实现集联更新
create or replace trigger tr_update
after update of sal on emp
for each row
begin
update emp set depno=:new.deptno where dentno=:old.deptno;
end;
4 建立instead of 触发?br /> 对于单视囑֏以直接进行insert update 和delete {操作,但是对于复杂视图不允许进行insertQupdate 和delete 操作?br /> 满一下条件的为复杂视?br /> h操作集合W?unionQunion all QintersectQminus
h分组函数 minQmaxQavgQsumQcount
hgroup by connect ~译 或start with
hdistinct
hq接
Z在复杂视图上执行dml 操作Q必要Zinstead-of 触发器,建立insteadQof 触发器后Q就可以Z复杂视图执行insertQupdate和delete 语句?br /> instead of 选项只用于视图
Z视图建立触发器时Q不能定义before ?after
在徏立视图时不能指定 with check option
当徏立instead of 触发器时Q必L定for each row 选项
1) 建立复杂视图dept_emp
create or replace view dept_emp as
select a.deptno,a.dname,b,empno,b,ename
from dept a,emp b
where a,deptno=b.deptno;
2) 建立 insteadQof 触发?br /> create of replacee trigger tr_instead_of_dept_emp
instead of insert on dept_emp
for each row
declare
v_temp int;
beegin
select count(*) into v_temp from dept where deptno=:new.deptno;
if v_temp=0 then
insert into dept(deptno,dname) values(:new.deptno,:new.dname);
end if;
select count(*)into v_temp from emp where empno=:new.empno;
if v_temp=0 then
insert into emp(empno,ename,deptno)
values(:new.deptno,:new.ename,:new.deptno);
end if;
end;
可以对视图执行insert 操作?br /> insert into dept_emp values(50,'admin','1223','mary')
5 理触发?br /> 1) 昄触发器信?br /> select trigger_name,status from user_triggers
where table_name='emp';
2)止触发?br /> alter trigger tr_check_sal disable;
3) Ȁz触发器
alter trigger tr_check_sal enable;
4) 止或激z表上的所有触发器
alter table emp disable all triggers;
alter table emo eanble all triggers;
5)重新~译触发?br /> alter trigger tr_check_sal compile;
6) 删除触发?br /> drop trigger tr_check_sal;