In Oracle, you can create your own functions.
译:在ORACLE中,你可以创建你自己的方法。
The syntax for a function is:
CREATE [OR REPLACE] FUNCTION function_name
    [ (parameter [,parameter]) ]
    RETURN return_datatype
IS | AS
    [declaration_section]
BEGIN
    executable_section
[EXCEPTION
    exception_section]
END [function_name];
 
When you create a procedure or function, you may define parameters. There are three types of parameters that can be declared:
1.IN - The parameter can be referenced by the procedure or function. The value of the parameter can not be overwritten by the procedure or function.
2.OUT - The parameter can not be referenced by the procedure or function, but the value of the parameter can be overwritten by the procedure or function.
3.IN OUT - The parameter can be referenced by the procedure or function and the value of the parameter can be overwritten by the procedure or function.
译:在你创建一个过程或者是方法时,可能会定义参数。这里有三种类型的参数可被定义:
1IN -该参数可以被过程或者是方法引用。但该参数的值不可以被过程或者是方法重写。
2、 OUT -该参数不可以被过程或者是方法引用。但该参数的值可以被过程或者是方法重写。
3、 IN OUT -该参数既可以被过程或者是方法引用。该参数的值也可以被过程或者是方法重写。
The following is a simple example of a function:
CREATE OR REPLACE Function FindCourse
   ( name_in IN varchar2 )
   RETURN number
IS
    cnumber number;
    cursor c1 is
    select course_number
      from courses_tbl
      where course_name = name_in;

BEGIN

open c1;
fetch c1 into cnumber;

if c1%notfound then
     cnumber := 9999;
end if;

close c1;

RETURN cnumber;
EXCEPTION
WHEN OTHERS THEN
      raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
END;
This function is called FindCourse. It has one parameter called name_in and it returns a number. The function will return the course number if it finds a match based on course name. Otherwise, it returns a 99999.
译:方法名为FindCourse,它有一个名为name_in的参数并且结果返回一个数字。如果它找到一个与课程名相同,那么就返回该课程号,否则就返回99999。
You could then reference your new function in an SQL statement as follows:
译:你可以在SQL语句这样引用你的新方法:
select course_name, FindCourse(course_name) as course_id
from courses
where subject = 'Mathematics';

Oracle/PLSQL: Creating Functions的更多相关文章

  1. Oracle/PLSQL: ORA-06550

    参考: http://blog.csdn.net/haiross/article/details/20612135 Oracle/PLSQL: ORA-06550 Learn the cause an ...

  2. 关于oracle 10g creating datafile with zero offset for aix

    参考文档: 1.创建oracle数据文件时需要注意的地方(OS Header Block) http://www.aixchina.net/Question/20406 2.oracle 创建数据文件 ...

  3. Oracle PLSQL读取(解析)Excel文档

    http://www.itpub.net/thread-1921612-1-1.html !!!https://code.google.com/p/plsql-utils/ Introduction介 ...

  4. MyEclipse+Weblogic+Oracle+PLSQL配置注意事项

    Weblogic配置详情:<Weblogic安装与配置图文详解>Oracle+PLSQL配置详情:<PL/SQL访问远程Oracle服务器(多种方式)>MyEclipse配置: ...

  5. oracle Plsql 运行update或者delete时卡死问题解决的方法

    oracle Plsql 运行update或者delete时 遇到过Plsql卡死问题或者导致代码运行sql的时候就卡死. 在开发中遇到此问题的时候,本来把sql复制出来,在plsql中运行,Sql本 ...

  6. oracle plsql基本语法

    oracle plsql 基本语法 --plsql默认规则:plsql赋值用":=" plsql判断用"=" plsql输入用"&" ...

  7. Oracle/PLSQL存储过程详解

    原文链接:https://blog.csdn.net/zezezuiaiya/article/details/79557621 Oracle/PLSQL存储过程详解 2018-03-14 17:31: ...

  8. Oracle / PLSQL写语句的时候常使用的函数

    最近在学习数据库方面的知识,做个标记. 这里有英文解释,建议多看看英文文档: https://www.techonthenet.com/oracle/functions/ 下面开始记录一下,自己在Or ...

  9. Oracle / PLSQL函数 - NUMTODSINTERVAL和NUMTOYMINTERVAL

    最近在学习数据库方面的知识,做个标记. 这里有英文解释,建议多看看英文文档: https://www.techonthenet.com/oracle/functions/ 下面开始记录一下,自己在Or ...

随机推荐

  1. DBCP--""连接池创建"与"资源关闭"Util类

    import java.io.InputStream; import java.sql.Connection; import java.sql.ResultSet; import java.sql.S ...

  2. ResourceBundle和Properties(转载)

    转载: 一般来说,ResourceBundle类通常是用于针对不同的语言来使用的属性文件. 而如果你的应用程序中的属性文件只是一些配置,并不是针对多国语言的目的.那么使用Properties类就可以了 ...

  3. 设置textview背景色为透明

    UITextView *textView=[[UITextView alloc]initWithFrame:CGRectMake(20, 40, 150, 170)];//初始化并设置大小 textV ...

  4. js生成 1-100 不重复随机数

    var count=100; var a=new Array(); for(var i=0;i<100;i++){ a[i]=i+1; } a.sort(function(){ return 0 ...

  5. getMeasuredHeight() 与 getHeight() 的区别

    http://www.cnblogs.com/x-dev/p/3767538.html?utm_source=tuicool&utm_medium=referral public final ...

  6. Hibernate 插入,修改,删除,查询语句

    /* *具体操作hibernate的类 *增加,删除,修改,按ID查询,模糊查询,查询全部 **/ public class PersonOperate { //在hibernate中所有操作都是由S ...

  7. 重绘panel控件,实现panel的阴影效果

    最近想在项目中添加一个要有阴影的panel控件,找了好多资料,最后通过采用图片的方式实现了panel的阴影效果,效果图如下: 重绘代码如下: using System; using System.Co ...

  8. openerp经典收藏 深入理解工作流(Workflow)(转载)

    深入理解工作流(Workflow) 原文:http://shine-it.net/index.php/topic,2494.0.html 一.工作流定义:<?xml version=" ...

  9. 第六周 E题 期望.....

    Description Given a dice with n sides, you have to find the expected number of times you have to thr ...

  10. android LayoutInflater.inflate()的参数介绍

    LayoutInflater.inflate()的作用就是将一个xml定义的布局文件实例化为view控件对象: 与findViewById区别: LayoutInflater.inflate是加载一个 ...