您的位置:首页 > 博客中心 > 数据库 >

oracle 写declare例子

时间:2022-03-14 01:18

注意:

1.赋值要用 :=

2.或的关系用 or 表示

 

declare

  prefix VARCHAR2(2); --前缀

  res_value VARCHAR2(20);

begin

  prefix := ‘QZ‘;

  for i in (select col1,col2 from table_name ) loop

    if i.col1= ‘col1‘ or i.col2= ‘col2‘  then
         res_value := ‘123456‘;
      end if;

  end loop;

  res_value := SUBSTR(res_value,0,2);  --截取字符串 从第一位(0和1都代表第一位)开始截取2为数

  dbms_output.put_line( res_value ); -- 输出语句

end;

最后输出 “12”

热门排行

今日推荐

热门手游