Oracle学习(一)

近期工作中一直用到Oracle数据库,在学校Oracle数据库学习并不牢固,所以用闲暇时间再次学习Oracle
Oracle中新建包
 
CREATE OR REPLACE PACKAGE pkg_Config
AS
   TYPE myrctype IS REF CURSOR;  自定义游标类型

   PROCEDURE Config_queryopermenuright(
    i_operid     IN       VARCHAR2,                               --操作员代码
    o_curult     OUT     myrctype,                                --返回结果
    o_cursor     OUT      myrctype                                --返回结果
 );
 end pkg_Config;
 
新建包体:
 
 
CREATE OR REPLACE PACKAGE BODY pkg_sys as
  --操作员登录
  PROCEDURE sp_sys_operlogin(i_loginName IN NVARCHAR2, --操作员代码
                             i_StaffPwd  IN NVARCHAR2, --操作员密码
                             o_cursor    OUT myrctype) AS
  begin
    declare
      v_recordcount INT;
    begin
      select count(*)
        into v_recordcount
        from Staff
       where loginName = i_loginName
         and struts = '0';
      if v_recordcount = 0 THEN
        open o_cursor for
          select -1, '该操作员不存在, 请填写正确的操作员' from dual;
        RETURN;
      END if;
      SELECT COUNT(*)
        INTO v_recordcount
        FROM Staff
       WHERE loginName = i_loginName
         and StaffPwd = i_StaffPwd
         and STAFFDELTYPE = 0;
      IF v_recordcount = 0 THEN
        open o_cursor for
          select -1, '该操作员密码不正确, 请重新输入正确的密码' from dual;
        RETURN;
      END IF;
      open o_cursor for
        select 0, '该操作员登陆成功' from dual;
    END;
  Exception
    WHEN NO_DATA_FOUND THEN
      open o_cursor for
        select -1, '操作员登陆失败' from dual;
    WHEN OTHERS THEN
      open o_cursor for
        select -1, '操作员登陆失败' from dual;
   
  END sp_sys_operlogin;
end pkg_sys;
 
包体中可写存储过程,包体中的存储过程一定要在包头中注册

你可能感兴趣的:(oracle,数据库,职场,休闲)