Oracle if 语句问题

接触Oracle没多久,问个if语句的问题
比如:
declare
bb varchar2(64);
begin
if 1=2 then
select xx into bb from pub_table;
update pub_table set xx ='1'
end if;
end;

问:then之后有两个执行语句一个赋值,一个修改。两者之间没什么关系,我是随便写的。
但问题是,这样写好像通不过,if下面只能跟一个的么?因为 我如果写成:
declare
bb varchar2(64);
begin
if 1=2 then
begin
select xx into bb from pub_table;
update pub_table set xx ='1'
end;
end if;
end;
好像也通不过。有谁知道有什么办法解么?Oracle和sql这个差异有点弄不懂了。谢谢了各位

oracle跟sqlserver不同
if 后 then就可以
而sqlserver中
if 后不跟then ,而是跟begin ....end;

所以你第一个是对的,第二个应该会报错的

同时update后需要commit;这个lz需要注意一下,否则只在当前会话中update生效,重新再开一个会话还会发现数据没写进去

还有,你select ...into那句,xx必须只能是一个值,不能是一列里N多条记录,否则一个变量不能存放N条数据,如果这种情况得需要用游标来处理
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-12-09
update pub_table set xx ='1' 这句末尾少了结束符";"
相似回答