求个创建存储过程Demo,   自己创建的怎么创都不对,   查询整个表的.                 

解决方案 »

  1.   


    create or replace procedure show_employee(empno_in in emp.empno%type)
    as
       v_sign number;
       v_empno emp.empno%type;
       v_ename emp.ename%type;
       v_deptno emp.deptno%type;
    begin
       select 1 into v_sign
       from dual
       where exists(select count(*) from emp where empno=empno_in);
       if v_sign=1 then
          select empno,ename,deptno into v_empno,v_ename,v_deptno
          from emp where empno=empno_in;
          dbms_output.put_line('information of'||empno_in||' are:');
          dbms_output.put_line('empno:'||v_empno||',ename:'||v_ename||',deptno:'||v_deptno);
       end if;
       exception
                when others then
                dbms_output.put_line('no data found');
    end show_employee;
    /
    SQL> exec show_employee(7788);
     
    PL/SQL procedure successfully completed
     
    SQL> set serveroutput on;
    SQL> /
     
    information of7788 are:
    empno:7788,ename:SCOTT,deptno:20
     
    PL/SQL procedure successfully completed
     
    SQL> 
      

  2.   

    create or replace procedure hehe is
     
     
    begin
    for cursor in (select id  ,type   from table1 where state=1) loop
        if cursor.id = 2
          then update table1 set state=3 where id=cursor.id;
          commit;
       else
          update table1 set state=4 where id=cursor.id;
          commit;
       end if;
    end loop;
    end ; 
      

  3.   

    create or replace procedure pro_test (param1_i in varchar2,param2_o out varchar2,param3_io varchar2....)
    is
      --声明部分
    begin
      --代码部分
    end pro_test;
    红色部分都是必须的。
    in out inout 不写 ,是几种参数的形式。
    in 表示只传入不传出,也就是说在代码部分,你不能更改这个参数的值。
    out 表示输出参数,也就是要输出的值,可以在代码部分给它赋值。
    inout 表示在代码部分可以更改它的值,也就是具备in 参数和out参数的特点。
    默认情况下不写这个参数类型,为in参数。