Sql 执行不同任务的存储过程?

Sql 执行不同任务的存储过程?,sql,oracle,Sql,Oracle,我有一张顾客桌 我已经创建了可用于将新数据插入表的存储过程。但是,如果我想使用相同的过程来更新或删除该表中的数据,该怎么办呢。我可以很容易地做到这一点,还是必须为每个函数使用单独的函数/过程 create or replace procedure add_customer(custid in table.id%type, name table.name%type) is begin insert into table(id, name) values(id, name); commit; en

我有一张顾客桌

我已经创建了可用于将新数据插入表的存储过程。但是,如果我想使用相同的过程来更新或删除该表中的数据,该怎么办呢。我可以很容易地做到这一点,还是必须为每个函数使用单独的函数/过程

create or replace procedure add_customer(custid in table.id%type,
name table.name%type) 
is
begin
insert into table(id, name)
values(id, name);
commit;
end;
/

您可以在下面的示例中添加类似动作的参数,并在代码中使用它:

create or replace procedure modify_customer(
  action in varchar2, custid in table.id%type, custname table.name%type) 
is
begin
if action = 'insert' then
  insert into table(id, name) values(custid, name);
  commit;
elsif action = 'delete' then 
  delete from table where id = custid and name = custname;
  commit;
end if;
end;

您可以将鉴别器参数添加到add_customer过程中,该过程说明操作是插入、更新还是删除。基于此参数,您可以创建所需的insert、update或delete语句。通过这种方式,您将能够对所有操作使用通用过程

至于使用一个过程或多个过程,如果表是一个列数有限的简单表,一个过程就可以了。但一旦表中的列数增加,一个过程可能会变得比需要的更复杂