PL/SQL编程—函数

SQL> select * from mytest;
 
ID    NAME                 PASSWD                                                                                         SALARY
----- -------------------- -------------------- --------------------------------------------------------------------------------
1     gagaga               123                                                                                               100
2     gaodingle!!!!        123                                                                                               100
3     gagaga               123                                                                                               100
 
SQL>
SQL> create function annual_calsaly(id_in varchar2)
  2  return
  3  number is calsaly number(7,2);
  4  begin
  5  select salary*12 into calsaly from mytest where id =id_in;
  6  return calsaly;
  7  end;
  8  /
 
 
Function created
 
SQL> var abc number;
SQL> call annual_calsaly('1')into:abc;
 
Method called
abc
---------
1200
函数必须要有返回值的在函数的开头
return 返回类型 is 返回变量名 具体类型
在begin操作完数据后在把对应的变量进行返回 return 返回变量名 
 
posted @ 2017-06-29 17:55  翎野君  阅读(243)  评论(0编辑  收藏  举报