使用对象类型+在存储过程使用+在函数中使用

来源:互联网 发布:广联达软件安装 编辑:程序博客网 时间:2024/06/05 19:01

使用对象类型

在存储过程使用
增删改查

--查询create or replace procedure select_stu_class(cid in stu_class.id%TYPE)as stu_c class4;beginselect value(sc) into stu_c from stu_class sc where id=cid;dbms_output.put_line(stu_c.id||' '||stu_c.name);end select_stu_class;/--插入create or replace procedure insert_stu_class(cid in stu_class.id%TYPE,cname in stu_class.name%TYPE)as v_stu_c class4:=class4(cid,cname);begininsert into  stu_class values(v_stu_c);exceptionwhen others then rollback;end insert_stu_class;/--更新create or replace procedure update_stu_class(v_class4 in class4)as beginupdate stu_class sc set  sc=v_class4  where  id=v_class4.id;exceptionwhen others then rollback;end update_stu_class;/--删除create or replace procedure delete_stu_class(cid in stu_class.id%TYPE)as begindelete  stu_class  where  id=cid;exceptionwhen others then rollback;end delete_stu_class;/ call select_stu_class(1101); call insert_stu_class(1103,'英语'); select * from stu_class; call update_stu_class(class4(1103,'商务英语'));  select * from stu_class; call delete_stu_class(1103);  select * from stu_class;

这里写图片描述

这里写图片描述

在函数中使用
在函数中使用1

--函数create or replace function select_stu_class_function(cid in stu_class.id%TYPE) return class4 asstu_c class4;beginselect value(sc) into stu_c from stu_class sc where id=cid;return stu_c;end select_stu_class_function;select select_stu_class_function(1101) from dual;/

这里写图片描述
这里写图片描述
在函数中使用2

 create or replace function select_stu_class_function2(cid in stu_class.id%TYPE) return  ref class4 asstu_c  ref  class4;beginselect ref(sc) into stu_c from stu_class sc where id=cid;return stu_c;end select_stu_class_function2;/ select deref(select_stu_class_function2(1101)) from dual;

这里写图片描述

原创粉丝点击