• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

oracle Dbeaver存储过程语法详解

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

可视化工具 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; 
<delete id="teacherDelete" parameterType="int">
        {call delTeacher(#{arg0})}
</delete>
<delete id="studentOfTeacherDelete" >
        {call delStudentOfTeacher(#{arg0}) }
</delete>

测试

@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; 
<insert id="teacherAdd">
        call addTeacher(#{arg0},#{arg1},#{arg2})
</insert>

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; 
<update id="teacherUpdate" >
        call updateTeacher(#{arg0},#{arg1},#{arg2});
</update>

学生增删改

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; 
<insert id="studentAdd" >
        call addStudent(#{arg0},#{arg2},#{arg1},#{arg3},#{arg4},#{arg5})
</insert>

CREATE OR REPLACE  PROCEDURE  delStudent(mySID IN varchar2)
IS 
BEGIN
	DELETE FROM student WHERE SID=mySID;
END delStudent; 
<delete id="studentDelete" >
        call delStudent(#{arg0})
</delete>

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; 

到此这篇关于oracle Dbeaver存储过程的文章就介绍到这了,更多相关oracle Dbeaver存储过程内容请搜索极客世界以前的文章或继续浏览下面的相关文章希望大家以后多多支持极客世界!


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
MySQL 全文检索的使用示例发布时间:2022-02-08
下一篇:
Redis的配置、启动、操作和关闭方法发布时间:2022-02-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap