当前位置: 移动技术网 > IT编程>数据库>Oracle > oracle 编程

oracle 编程

2019年08月16日  | 移动技术网IT编程  | 我要评论

天津三维地图,海贼王728话,使诈拐娇妻

 

 

into用法:

declare
a number;
b number;
c number;
begin
select max(sal),min(sal),avg(sal) into a,b,c from emp;
dbms_output.put_line('最高工资:'|| a);
dbms_output.put_line('最低工资:'|| b);
dbms_output.put_line('平均工资:'|| c);
end;

 

if语句

 

declare
  score number := 90;
begin
  if score < 60 then
    dbms_output.put_line ( '你有些落后了,还不快追上' );
  elsif score < 80 then
    dbms_output.put_line ( '成绩一般,要加把劲.' );
  else

    dbms_output.put_line ( '你很优秀' )

end if;


end;

 

 

 

select product_id,product_type_id,
case
when product_type_id=1 then '图书类'
when product_type_id=2 then '服装类'
when product_type_id=3 then '日用类'
when product_type_id=4 then '电器类'
else '其它分类'
end case;
from products

 

 

 

declare
  score number := 70;
begin
  case
    when score > 80 then
      dbms_output.put_line ( '优秀' );
    when score > 60 then
      dbms_output.put_line ( '一般' );
    else
      dbms_output.put_line ( '待努力' );
  end case;
end;

 

declare
  a integer := 10;
  total integer := 1;
begin
  loop
    total := total*a;
    a:=a-1;
    exit when a=1;
  end loop;
dbms_output.put_line('10*9*...*2*1='||total);
end;

例如:1.计算198-273之和
  

declare
  a integer;
  tot integer:=0;
begin
  for a in 198..273 loop
    tot:=a+tot;
  end loop;
dbms_output.put_line('198+199+...+273='||tot);
end;

 2.又如打印九九乘法表

declare
  a integer;
  b integer;
  c integer;
begin
  for a in 1..9 loop
    for b in 1..a loop
      c:=a*b;
      dbms_output.put(b||'*'||a||'='||c||' ');
    end loop;
    dbms_output.put_line('');
  end loop;
end;

 

goto结构又称跳转结构,可以在plsql块中设定一个标签,

标签使用<<标签名>>来定义,然后使用goto 标签名;完成跳转。

巧妙的使用goto语句能实现选择结构,也能实现循环结构。

例如改写计算1-100之和的程序 

declare
  a integer:=1;
  tot integer:=0;
begin
  <<cal>>
  tot:=tot+a;
  a:=a+1;
  if a<=100 then
    goto cal;
  end if;
dbms_output.put_line('1+2+...+100='||tot);
end;

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网