oracle – 两个带有begin和end的PLSQL语句,单独运行但不能一起运行?

前端之家收集整理的这篇文章主要介绍了oracle – 两个带有begin和end的PLSQL语句,单独运行但不能一起运行?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
只是想知道是否有人可以帮助这个,我有两个PLsql语句来改变表(添加额外的字段),它们如下:
-- Make GC_NAB field for Next Action By Dropdown

begin
if 'VARCHAR2' = 'NUMBER' and length('VARCHAR2')>0 and length('')>0 then
  execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NAB VARCHAR2(10,))';
elsif ('VARCHAR2' = 'NUMBER' and length('VARCHAR2')>0 and length('')=0) or
  'VARCHAR2' = 'VARCHAR2' then
  execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NAB VARCHAR2(10))';
else
  execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NAB VARCHAR2)';
end if;
commit;
end;

-- Make GC_NABID field for Next Action By Dropdown

begin
if 'NUMBER' = 'NUMBER' and length('NUMBER')>0 and length('')>0 then
  execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NABID NUMBER(,))';
elsif ('NUMBER' = 'NUMBER' and length('NUMBER')>0 and length('')=0) or
  'NUMBER' = 'VARCHAR2' then
  execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NABID NUMBER())';
else
  execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NABID NUMBER)';
end if;
commit;
end;

当我分别运行这两个查询时,没有问题.但是,当如上所示一起运行时,Oracle在启动第二个语句时给出了一个错误

Error report:
ORA-06550: line 15,column 1:
PLS-00103: Encountered the symbol "BEGIN" 
06550. 00000 -  "line %s,column %s:\n%s"
*Cause:    Usually a PL/sql compilation error.
*Action:

我假设这意味着第一个语句没有正确终止…我是否应该在语句之间放置任何内容以使其正常工作?

Oracle一次可以使用一个sql语句或PL / sql匿名块. (与sql Server不同,除了一次批处理外.)因此,您有几个选择.

>将两个匿名块包装在另一个匿名块中:

begin
  -- Make GC_NAB field for Next Action By Dropdown 
  begin 
  if 'VARCHAR2' = 'NUMBER' and length('VARCHAR2')>0 and length('')>0 then 
    execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NAB VARCHAR2(10,))'; 
  elsif ('VARCHAR2' = 'NUMBER' and length('VARCHAR2')>0 and length('')=0) or 
    'VARCHAR2' = 'VARCHAR2' then 
    execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NAB VARCHAR2(10))'; 
  else 
    execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NAB VARCHAR2)'; 
  end if; 
  commit; 
  end; 
  -- Make GC_NABID field for Next Action By Dropdown 
  begin 
  if 'NUMBER' = 'NUMBER' and length('NUMBER')>0 and length('')>0 then 
    execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NABID NUMBER(,))'; 
  elsif ('NUMBER' = 'NUMBER' and length('NUMBER')>0 and length('')=0) or 
    'NUMBER' = 'VARCHAR2' then 
    execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NABID NUMBER())'; 
  else 
    execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NABID NUMBER)'; 
  end if; 
  commit; 
  end;
end;

>告诉您正在使用的工具将PL / sql提交给Oracle以单独发送两个块.如何做到这一点将是特定工具.在sql * PLUS中,一行/一行将完成此任务:

-- Make GC_NAB field for Next Action By Dropdown 
  begin 
  if 'VARCHAR2' = 'NUMBER' and length('VARCHAR2')>0 and length('')>0 then 
    execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NAB VARCHAR2(10,))'; 
  elsif ('VARCHAR2' = 'NUMBER' and length('VARCHAR2')>0 and length('')=0) or 
    'VARCHAR2' = 'VARCHAR2' then 
    execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NAB VARCHAR2(10))'; 
  else 
    execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NAB VARCHAR2)'; 
  end if; 
  commit; 
  end; 
  /
  -- Make GC_NABID field for Next Action By Dropdown 
  begin 
  if 'NUMBER' = 'NUMBER' and length('NUMBER')>0 and length('')>0 then 
    execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NABID NUMBER(,))'; 
  elsif ('NUMBER' = 'NUMBER' and length('NUMBER')>0 and length('')=0) or 
    'NUMBER' = 'VARCHAR2' then 
    execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NABID NUMBER())'; 
  else 
    execute immediate 'alter table "SERVICEMAIL6"."ETD_GUESTCARE" add(GC_NABID NUMBER)'; 
  end if; 
  commit; 
  end;
  /

猜你在找的Oracle相关文章