加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle存储过程---创建存储过程语句

发布时间:2020-12-12 13:32:07 所属栏目:百科 来源:网络整理
导读:一、创建存储过程语句 ? ? ? 语法:? CREATE OR REPLACE PROCEDURE testname( argument1 TYPE1,....??) AS BEGIN ...... END? ?testname ? ? ? 例子: CREATE OR REPLACE PROCEDURE test_name(arg1 VARCHAR2 ,arg2 number ,arg3 number ) AS BEGIN insert into

一、创建存储过程语句

? ? ? 语法:? CREATE OR REPLACE PROCEDURE testname( argument1 TYPE1,....??) AS BEGIN ...... END? ?testname

? ? ? 例子:

CREATE OR REPLACE PROCEDURE test_name(
arg1 VARCHAR2,arg2 number,arg3 number)
AS
BEGIN
  insert into test_for_insert(
              STACID,LOANNO,SYSTID,PARA1,PARA2 
            )values(
                       1,arg1,wld,arg2,arg3
            );
        
  dbms_output.put_line(work!);
END test_name;

? ? ?右键‘测试’,输入参数

?

二、存储过程使用游标

? ? ? ?游标就像循环里面的指针

? ? ? ?语法:定义 :? CURSOR? point? IS SELECT number FROM test_table;??

? ? ? ? ? ? ? ? ? 使用:FOR? test_point? IN? point LOOP

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .................................

? ? ? ? ? ? ? ? ? ? ? ? ? ? ?END LOOP;

create or replace procedure test1 (sys in varchar2)is
  v_sys  test_table.SYSTID%TYPE;
  v_arg number(10,2);
  CURSOR table_cursor IS
  SELECT SYSTID,NUMBER from test_table;  
begin    

  for test_cursor in table_cursor LOOP 
    if sys = ‘TEST then
     dbms_output.put_line( work );
   end if;
  END LOOP;
end test1; 

?

三、给变量赋值

? ? ? ? ?语法? :?? SELECT? a.number,a INTO varible1 FROM test_table a;

? ? ? ? ?例子 :?

create or replace procedure test_pro(sys in varchar2) is 

  v_sys  test_table.SYSTID%TYPE;
  v_varible1 number(10,2);
  v_varible2 number(10,2);

  CURSOR test_cursor IS
  SELECT SYSTID,NUMBER 
  from test_table;  

BEGIN

 for v_cursor in test_cursor LOOP
   if sys = wld then
        select t.SYSTID,nvl(sum(t.var1+t.var2),0) 
        into v_sys,v_varible1
        from test_table t where  t.NUMBER = v_cursor.NUMBER;
       dbms_output.put_line(SYS :  || v_sys ||  v_varible1  :  || v_varible1 );
   end if;
 END LOOP;
END test_pro;

?

四、 插入表格

? ? ? ? 语法: INSERT INTO table1 ( arg1,arg2 .....) SELECT varible1,varible2 ..... FROM table2;

? ? ? ? 例子:

? ?

create or replace procedure test3 (sys in varchar2)is
  v_sys  test_table.SYSTID%TYPE;
  v_arg number(10,2);

begin    

    INSERT INTO table1
   (
    arg1,....
    )
    select 
    varible1,varible2,...     
    from table2;
    
end test3; 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读