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. 炫酷实用的jQuery插件 涵盖菜单、按钮、图片

    新的一周开始了,今天我们要为大家分享一些全新的jQuery插件和HTML5/CSS3应用,这些jQuery插件不仅非常炫酷,而且还挺实用,这次的分享包含jQuery菜单.CSS3按钮已经多种图片特效, ...

  2. Asp.net 生成验证码

    生成验证码一般来说大体有这么几步: 1.生成验证码字符串,一般由四个或更多随机字符拼凑而成: 2.填充图片背景,并绘制图片的背景噪音线: 3.将验证码绘制到图片中: 4.绘制前景噪点: 5.返回图片流 ...

  3. WP开发笔记——日期时间DateTime.Now函数

    //2008年4月24日 System.DateTime.Now.ToString("D"); //2008-4-24 System.DateTime.Now.ToString(& ...

  4. Java Web动态配置log4j

    导入log4j的jar包, 在web.xml中做如下配置 <!-- Log4j Configuration --> <context-param> <param-name ...

  5. CenterOS中安装Redis及开机启动设置

    Redis安装 从官方下载最新Redis进行安装,官网地址:http://redis.io/download $ wget http://download.redis.io/releases/redi ...

  6. (原创)LINUX_UNIX设计思想-读书笔记

    第一章 一.Unit哲学 1.小即是美 2.让每一个程序只做好一件事情 3.尽快建立原型 4.舍高效率而取可移植性 5.使用纯文本文件来存储数据 6.充分利用软件的杠杆效应 7.使用shell脚本来提 ...

  7. CLR via C# I/O基元线程同步构造

    1. 分为用户模式构造和内核模式构造 2. 用户模式构造 a.易失构造 在一个简单数据类型的变量上执行原子性读或写操作 VolaileWrite 强制address中的值在调用时写入,除此之外,按照源 ...

  8. 解决前端浏览器传JSON对像到服务端后全部变成string类型的方法

    这几天公司用nodejs+mongodb来做些东西,UI用的是kendo UI 碰到一个问题: 举个例子var a={"name":"张三","age ...

  9. #ifdef预编译相关用法

    #ifdef预编译相关用法主要有:(1)#ifdef XXX executing the corresponding xxx code #endif(2)#ifdef XXX executing th ...

  10. Linux挂载60T存储

    操作系统: CentOS 6.3 存储:总大小为72T,并划分成3个块,每块20T 安装多实例MySQL数据库,不想挂载3个块,弄成一个大的比较方便管理,个人比较懒. 配置多路径:http://blo ...