本篇文章小编给大家分享一下oracle Dbeaver存储过程语法代码示例解析,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
可视化工具 Dbeaver
基本语法
增
CREATE OR REPLACE PROCEDURE addStudent IS BEGIN INSERT INTO student values(6,2,5,'小陈',22,0); END addStudent; call addStudent(); DROP procedure getStudent SELECT * FROM student
删
CREATE OR REPLACE PROCEDURE delStudent IS BEGIN DELETE FROM student WHERE ID='6'; END delStudent; call delStudent(); DROP procedure delStudent SELECT * FROM student
改
CREATE OR REPLACE PROCEDURE updateStudent IS BEGIN UPDATE student SET AGE=25 WHERE ID='5'; END updateStudent; call updateStudent(); DROP procedure updateStudent SELECT * FROM student
单个查询
CREATE OR REPLACE PROCEDURE getStudentCount (studentCount OUT NUMBER) IS BEGIN SELECT count(*) INTO studentCount FROM student; END getStudentCount; DECLARE studentCount NUMBER(38); BEGIN getStudentCount(studentCount); dbms_output.put_line(studentCount); END; DROP procedure getStudentCount SELECT * FROM student
多行查询
--定义存储过程,返回游标 CREATE OR REPLACE PROCEDURE getAllStudent(resule OUT sys_refcursor) IS --返回游标 BEGIN OPEN resule FOR SELECT * FROM student; END; --查询存储过程 DECLARE cur SYS_REFCURSOR; --游标 result_row student%rowtype; BEGIN getAllStudent(cur); LOOP FETCH cur INTO result_row ; EXIT WHEN cur%notfound; dbms_output.put_line('ID: '||result_row.ID||' TID: '||result_row.TID||'SID: '||result_row.SID||' SNAME: '||result_row.SNAME||' AGE: '||result_row.AGE||' SEX: '||result_row.SEX); END LOOP; CLOSE cur; END; DROP procedure getAllStudent SELECT * FROM student
springboot中使用
一个student表,一个teacher表
有这样一个业务,删除教师,删除其所有学生
CREATE OR REPLACE PROCEDURE delTeacher(myTID IN VARCHAR2) IS BEGIN DELETE FROM teacher WHERE TID=myTID; END delTeacher;
CREATE OR REPLACE PROCEDURE delStudentOfTeacher(myTID IN VARCHAR2) IS BEGIN DELETE FROM student WHERE TID=myTID; END delStudentOfTeacher;
{call delTeacher(#{arg0})}
{call delStudentOfTeacher(#{arg0}) }
测试
@Test void contextLoads() { teacherService.deleteTeacher(2); }
增
CREATE OR REPLACE PROCEDURE addTeacher(myTID IN varchar2,myTNAME IN varchar2,myAGE IN varchar2) IS BEGIN INSERT INTO teacher values(myTID,myTNAME,myAGE); END addTeacher;
call addTeacher(#{arg0},#{arg1},#{arg2})
改
CREATE OR REPLACE PROCEDURE updateTeacher(myTNAME IN varchar2,myAGE IN varchar2,myTID IN varchar2) IS BEGIN UPDATE teacher SET TNAME=myTNAME,AGE=myAGE WHERE TID=myTID; END updateTeacher;
call updateTeacher(#{arg0},#{arg1},#{arg2});
学生增删改
增
CREATE OR REPLACE PROCEDURE addStudent(myID IN varchar2,myTID IN varchar2,mySID IN varchar2,mySNAME IN varchar2,myAGE IN number,mySEX IN varchar2) IS BEGIN INSERT INTO student values(myID,myTID,mySID,mySNAME,myAGE,mySEX); END addStudent;
call addStudent(#{arg0},#{arg2},#{arg1},#{arg3},#{arg4},#{arg5})
删
CREATE OR REPLACE PROCEDURE delStudent(mySID IN varchar2) IS BEGIN DELETE FROM student WHERE SID=mySID; END delStudent;
call delStudent(#{arg0})
改
CREATE OR REPLACE PROCEDURE updateStudent(mySID IN varchar2,mySNAME IN varchar2,myAGE IN NUMBER,mySEX IN varchar2) IS BEGIN UPDATE student SET SNAME=mySNAME,AGE=myAGE,SEX=mySEX WHERE SID=mySID; END updateStudent;
忍者必须死34399账号登录版 最新版v1.0.138v2.0.72
下载勇者秘境oppo版 安卓版v1.0.5
下载忍者必须死3一加版 最新版v1.0.138v2.0.72
下载绝世仙王官方正版 最新安卓版v1.0.49
下载Goat Simulator 3手机版 安卓版v1.0.8.2
Goat Simulator 3手机版是一个非常有趣的模拟游
Goat Simulator 3国际服 安卓版v1.0.8.2
Goat Simulator 3国际版是一个非常有趣的山羊模
烟花燃放模拟器中文版 2025最新版v1.0
烟花燃放模拟器是款仿真的烟花绽放模拟器类型单机小游戏,全方位
我的世界动漫世界 手机版v友y整合
我的世界动漫世界模组整合包是一款加入了动漫元素的素材整合包,
我的世界贝爷生存整合包 最新版v隔壁老王
我的世界MITE贝爷生存整合包是一款根据原版MC制作的魔改整