ORACLE 10 (付首昕)学习笔记-第2节-命令。

ORACLE 10 学习笔记-第2节-命令。

1. inner join / left join/ right join / full join
select a.dname, b.ename from dept a, emp b where a.deptno=b.deptno and a.deptno=10;
select a.dname, b.ename from dept a inner join emp b
on a.deptno=b.deptno and a.deptno=10;
select dname,ename from dept natural join emp;
select a.dname,b.ename from dept a left join emp b
on a.deptno=b.deptno and a.deptno=10;
select a.dname, b.ename from dept a right join emp b
on a.deptno=b.deptno and a.deptno=10;
select a.dname, b.ename from dept a, emp b where a.deptno=b.deptno(+) and b.deptno(+)=10;
2. 单行子查询
select ename,sal,deptno from emp where deptno=
(select deptno from emp where ename='scott');
select ename,job,sal,deptno from emp where job in
(select distinct job from emp where deptno=10);
select ename,sal,deptno from emp where sal>all
(select sal from emp where deptno=30);
3.建立触发器
create [or replace] trigger grigger_name
timing event1 [or event2 or event3]
on table_name
pl/sql block;
4.休息日不能修改雇员信息
create or replace trigger tr_sec_emp
before insert or update or delete on emp
begin
  if to_char(sysdate,'DY','nls_date_language=AMERICAN')
     IN ('SAT','SUN') THEN
    case
      when inserting then
        raise_application_error(-20001,'不能在休息日增加雇员');
      when updateing then
        raise_application_error(-20001,'不能在休息日更新雇员');
      when deleteing then
        raise_application_error(-20001,'不能在休息日解雇雇员');
     end case;
   end if;
end;
/
5.
create table audit_table(
name varchar2(20),ins int,upd int,del int,
starttime date,endtime date);
6.
create or replace trigger tr_audit_emp
after insert or update or delete on emp
declare
  v_temp int;
begin
select count(*) into v_temp from audit_table
  where name='emp';
if v_temp=0 then
   insert into audit_table values
   ('emp',0,0,0,sysdate,null);
end if;
case
  when inserting then
    update audit_table set ins=ins+1,endtime=sysdate
      where name='emp';
  when updating then
    update audit_table set upd=upd+1,endtime=sysdate
      where name='emp';
  when deleting then
    update audit_table set del=del+1,endtime=sysdate
      where name='emp';
end case;
end;
/
7.
update emp set sal=2000 where empno=7788;
update emp set sal=2000 where empno=7369;
select upd,starttime,endtime from audit_table
where name='emp';

8.
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,'非工作时间');
end if ;
end ;
/

9.视图
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;

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值