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. 方法:一个简单的读取配置文件.properties的工具类 JAVA

    import java.util.ResourceBundle; public class ConfigHelper { private static ConfigHelper instance; p ...

  2. 南阳理工oj88--汉诺塔(一)

    题目链接.http://acm.nyist.net/JudgeOnline/problem.php?pid=88 #include <stdio.h> /* //测试一下49999和500 ...

  3. Codevs 1669 运输装备

    时间限制: 1 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 德国放松对英国的进攻后,把矛头指向了东北—— ...

  4. server2008R2服务器开启远程

    通常我们开启远程桌面只需要在我的电脑那边把远程的打开就可以了,然后允许访问 上面说的这些其实晚上很多都有的,自己找一下,这边是自己遇到的一点问题,就是弄了很久,按网上说的弄很久,发现问题原来是在,路由 ...

  5. fastclick插件 导致 input[type="date"] 无法触发问题解决方案

    鄙人才疏学浅,新人一枚,不足之处还请谅解,写下这个也只是为了给大家分享一下我解决这个BUG的方法,也是自己的一个笔记. 首先,我们使用fastclick插件的初衷是解决“tap”事件“点透”的BUG: ...

  6. Ubuntu14.04忘记root密码的解决方法

    电脑20多天没用忘记密码了,下面是在网上找到的一个解决办法,其它的和这个也大概相同.因为其中有些缺漏,没能给我解决问题.通过分析最终问题还是解决了,现解决方案的关键点记录一下.希望能方便到其它人. 1 ...

  7. 2013-07-29 IT 要闻速记快想

    ### ========================= ###传动视暴雪82亿美元赎身,腾讯参与投资 ### ========================= ###帮助企业解决打印&邮 ...

  8. Session原理简述

    Session存在的意义,估计每个用做web开发的人都是了解的,就为了解决HTTP是个无状态协议所带来的问题,不多说了.这里主要想说的是服务端与客户端是如何利用session进行交互的. Sessio ...

  9. mysql时间处理

    两种方式,一个是在数据库查询的时候就截取,另一个就是在使用的时候截取. 1.数据库 select date_format(日期字段,’%Y-%m-%d’) as ‘日期’ from test 2.ja ...

  10. 【面试虐菜】—— Apache知识整理

    Apache性能调优1 Apache 部分:1. 移除不用的模块.2. 使用 mod_disk_cache NOT mod_mem_cache .3. 扁平架构配置mod_disk_cache.4.  ...