你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle数据库实验应用

[日期:2012-05-07] 来源:Linux社区  作者:chengchanglun [字体:大 中 小]

存储过程:

  1. set serveroutput on;  
  2. create or replace procedure PrintStudentInfo is   
  3.   
  4. begin   
  5.    
  6. for s_current in (select * from student) loop   
  7. dbms_output.put(s_current.sno || '\');  
  8. dbms_output.put(s_current.sname || '\');  
  9. dbms_output.put_line(s_current.age);  
  10. end loop;  
  11.    
  12. end PrintStudentInfo;  
  13. /  
  14.   
  15. exec PrintStudentInfo;  
  16.   
  17.   
  18. create or replace procedure GetStudentInfo(ID in varchar2) is   
  19. type StudentInfo is record(  
  20. sID student.sno%type,  
  21. sName student.sname%type,  
  22. className course.Cname%type  
  23.   
  24. );  
  25.   
  26. v_studentInfo StudentInfo ;  
  27. begin   
  28. select s.sno,s.sname,c.cname  
  29. into v_studentInfo   
  30. from student s join course c  
  31. on s.sclass=c.sid  
  32. where s.sno=ID;  
  33.   
  34. dbms_output.put(v_studentInfo.SID || '\');  
  35. dbms_output.put(v_studentInfo.Sname || '\');  
  36. dbms_output.put(v_studentInfo.className || '\');  
  37.   
  38. exception when no_data_found then   
  39. dbms_output.put_line('not found this student');  
  40. end GetStudentInfo;  
  41. /  
  42.   
  43. declare   
  44. studentID varchar2(20):='804';  
  45. begin GetStudentInfo(id=>studentID);  
  46. end;  
  47. /  
触发器:
  1. drop table student_log;  
  2. create table student_log(  
  3. who varchar2(30),  
  4. ActionType varchar2(10),  
  5. ModelDate timestamp  
  6. );  
  7.   
  8. --触发   
  9. create or replace trigger InsertLog_trigger  
  10. after insert on student  
  11. begin  
  12. insert into student_log values(user,'INSERT',sysdate);  
  13. end;  
  14. /  
  15.   
  16. insert into student(sno,age,sname) values(222190912,23,'李小龙');  
  17.   
  18. select * from student_log;  
  19.   
  20. alter table student_log add Student_ID varchar2(10);  
  21.   
  22. alter trigger insertlog_trigger disable;  
  23.   
  24. create or replace trigger insert_row_log_trigger  
  25. before insert on student   
  26. referencing new as new_value  
  27. for each row  
  28. begin   
  29. insert into student_log   
  30. values(user,'INsert',sysdate,:new_value.SNO) ;  
  31. end;  
  32. /  
  33.   
  34. insert into student(sno,age,sname) values(32565132,231,'成长伦');  
  35.   
  36. select * from student_log;  
  37.   
  38. --test  
备份:
  1. -- exp system/manager@ORCL file=d:\daochu.dmp log=d:\logs\log.log full=y   
  2.   
  3. imp system/sa@ORCL  full=y  file=d:\daochu.dmp log=d:\logs\log.log ignore=y  

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux
相关资讯       oracle数据库教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款