oracle创建和调试存储过程

本文详细介绍了如何在Oracle数据库中创建并调试存储过程,通过具体示例展示了存储过程的添加和执行过程。同时,提供了创建emp、dept等常用表的SQL语句,以及如何为scott用户授予调试权限的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

一、添加存储过程

二、执行调试

三、附录-建表语句


一、添加存储过程

create or replace procedure add_emp(empno    number,
                                    ename    varchar2,
                                    job      varchar2,
                                    mgr      NUMBER,
                                    hiredate DATE,
                                    sal      number,
                                    com      NUMBER,
                                    deptno   number) is
BEGIN
  dbms_output.put_line('添加员工信息');
  INSERT INTO emp
  VALUES
    (empno, ename, job, mgr, hiredate, sal, com, deptno);
  commit;
EXCEPTION
  WHEN OTHERS THEN
    dbms_output.put_line('添加员工失败');
end add_emp;
使用scott用户登录oracle,自带emp、dept表,如果没有可以使用附录sql语句创建

二、执行调试

或者

grant  DEBUG CONNECT SESSION to scott;

单步执行

输出信息

结果查看

三、附录-建表语句

EMP.SQL

-- Create table
create table EMP
(
  empno    NUMBER(4) not null,
  ename    VARCHAR2(10),
  job      VARCHAR2(9),
  mgr      NUMBER(4),
  hiredate DATE,
  sal      NUMBER(7,2),
  comm     NUMBER(7,2),
  deptno   NUMBER(2)
)
tablespace USERS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
-- Add comments to the columns 
comment on column EMP.empno
  is '雇员编号';
comment on column EMP.ename
  is '雇员姓名';
comment on column EMP.job
  is '雇员职位';
comment on column EMP.mgr
  is '雇员对应的领导的编号';
comment on column EMP.hiredate
  is '雇员的雇佣日期';
comment on column EMP.sal
  is '雇员的基本工资';
comment on column EMP.comm
  is '雇员的奖金';
comment on column EMP.deptno
  is '雇员所在部门编号';
-- Create/Recreate primary, unique and foreign key constraints 
alter table EMP
  add constraint PK_EMP primary key (EMPNO)
  using index 
  tablespace USERS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table EMP
  add constraint FK_DEPTNO foreign key (DEPTNO)
  references DEPT (DEPTNO);


DEPT.SQL

-- Create table
create table DEPT
(
  deptno NUMBER(2) not null,
  dname  VARCHAR2(14),
  loc    VARCHAR2(13)
)
tablespace USERS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
-- Add comments to the columns 
comment on column DEPT.deptno
  is '部门编号';
comment on column DEPT.dname
  is '部门名称';
comment on column DEPT.loc
  is '部门所在位置';
-- Create/Recreate primary, unique and foreign key constraints 
alter table DEPT
  add constraint PK_DEPT primary key (DEPTNO)
  using index 
  tablespace USERS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

SALGRADE.SQL
-- Create table
create table SALGRADE
(
  grade NUMBER,
  losal NUMBER,
  hisal NUMBER
)
tablespace USERS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
-- Add comments to the columns 
comment on column SALGRADE.grade
  is '工资等级';
comment on column SALGRADE.losal
  is '此等级的最低工资';
comment on column SALGRADE.hisal
  is '此等级的最高工资';

BONUS.SQL
-- Create table
create table BONUS
(
  ename VARCHAR2(10),
  job   VARCHAR2(9),
  sal   NUMBER,
  comm  NUMBER
)
tablespace USERS
  pctfree 10
  initrans 1
  maxtrans 255;
-- Add comments to the columns 
comment on column BONUS.ename
  is '雇员姓名';
comment on column BONUS.job
  is '雇员职位';
comment on column BONUS.sal
  is '雇员工资';
comment on column BONUS.comm
  is '雇员奖金';

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值