zoukankan      html  css  js  c++  java
  • Oracle新建存储过程和程序包

    
    
    建存储过程之前需要新增一张jdbc_student表,接下来用的到

    新增一个简单的存储过程
    create or replace procedure proc_jdbc_student_add(name in varchar2, age in number)
    as begin
    insert into jdbc_student (name, age) values (name, age);
    end proc_jdbc_student_add;
    调用存储过程
    exec proc_jdbc_student_add('user4',28) 新增一个有返回值的存储过程 CREATE PROCEDURE proc_jdbc_student_outpara (inParam in varchar2, address out varchar2) as begin select address into address from jdbc_student where name = inParam; end proc_jdbc_student_outpara;
    我也不会直接调用,我是用SQLdevloper自带的测试工具测的
    新增存储过程后,右键存储过程可以执行或debug执行,只需要输入参数即可

    新增程序包

    create or replace package test_pkg is --test_pkg为包名
    procedure showMessage; --声明一个过程
    function myAdd(x in number,y in number) return number; --声明函数
    function of_stop_clinic_dict(in_item_code in varchar2, out_message out varchar2) return integer; -- 声明一个有返回值的函数
    end test_pkg;

    --主体
    create or replace package body test_pkg is --包名必须一致

    procedure showMessage is --实现规范中的过程
    begin
    dbms_output.put_line('创建一个简单的包!'); --打印字符串用单引号括起来
    end showMessage;

    function myAdd(x in number,y in number) --实现函数
    return number is
    mySum number:=1;
    begin
    mySum:=x+y;
    return mySum;
    end myAdd;

    function of_stop_clinic_dict(in_item_code in varchar2, out_message out varchar2) -- 实现有返回值的函数
    return Integer is
    backNumber INTEGER := 0;
    begin
    out_message := '返回值信息';
    return backNumber ;
    end of_stop_clinic_dict;
    end test_pkg;



    --调用程序包,这个仅测试用
    set serveroutput on
    declare
    testSum number:=1;
    testInteger integer:=1;
    testPram varchar2(50):= '测试';
    begin
    test_pkg.showMessage;
    testSum:=test_pkg.myAdd(10,11);
    testInteger:=TEST_PKG.OF_STOP_CLINIC_DICT('123_45',testText1);
    dbms_output.put_line(testSum);
    dbms_output.put_line(testInteger);
    end;




  • 相关阅读:
    自介
    打招呼
    试验四
    作业:实验二
    个人简介
    实验4
    构建之法—心得体会
    作业:实验二
    个人简介
    软件测试第四次博客作业2
  • 原文地址:https://www.cnblogs.com/funian/p/15294203.html
Copyright © 2011-2022 走看看