批量执行多条sql语句

在程序中执行的原sql语句如下:
update TB_VG set seq = 1, vessel_id = 'Jin14', vessel_type = 'TRACK' where batch_number = '20837' and train_id = '0233086';
update TB_VG set seq = 2, vessel_id = 'Jin14', vessel_type = 'TRACK' where batch_number = '20992' and train_id = '0233110';
这个时候会报错:
【ORA-00911: 无效字符】
修改sql语句如下:
begin
update TB_VG set seq = 1, vessel_id = 'Jin14', vessel_type = 'TRACK' where batch_number = '20837' and train_id = '0233086';
update TB_VG set seq = 2, vessel_id = 'Jin14', vessel_type = 'TRACK' where batch_number = '20992' and train_id = '0233110';
end;

如果不采用这种方式,可能的异常有:

ORA-00933: SQL 命令未正确结束(如果sql没有以分号结尾)
ORA-00911: 无效字符(如果未加begin 和 end)
ORA-06550: 第x行, 第xxx列: PLS-00103: 出现符号 "end-of-file"在需要下列之一时:......(如果end后面没有;分号)
ORA-06550: 第x行, 第xxx列: PLS-00103: 出现符号 ""在需要下列之一时:......(语句之间有换行符)

猜你喜欢

转载自ysbwsx2017.iteye.com/blog/2400352