oracle 之 函数
本次主题 青涩/色
函数的结束一定要使用return语句返回一个与声明匹配的值
--语法:
create[or replace] function<函数名> [(参数列表)]
return数据类型
is|as (is或as完全等价 )
[局部变量声明]
begin
pl/sql函数体
end[<函数名>]
--函数 没有参数
create or replace function getCount
return number
as v_num number;
begin
select count(*) into v_num from v_emp;
return v_num;
end;
--调用函数1
select getCount() from dual;
--调用函数2 plsql语句块
declare
num number;
begin
num := getCount();
dbms_output.put_line(num);
end;
--带有 in 参数的函数, in 默认 ,可以使用select语句和plsql语句块调用函数
create or replace function getName(v_name varchar2)
return varchar2
as
v_person v_emp%rowtype;
v_str varchar2(100);
begin
select * into v_person from v_emp where ename = v_name;
v_str := '当前人是'||v_person.ename||' 工资是'||v_person.sal;
return v_str;
end;
--调用函数 select语句
select getPersonByName('SMITH') from dual;
--调用函数 plsql语句块
declare
a_name varchar2(50);
begin
a_name := getName('SMITH');
dbms_output.put_line(a_name);
end;
--带有 out 参数的函数 函数携有out参数的,只能使用plsql语句块调用函数
create or replace function getSal(p_name varchar2,e_sal out number)
return varchar2
as
v_st varchar2(100);
begin
select sal into e_sal from v_emp where ename=p_name;
v_st := p_name||'每个月开'||e_sal||'元';
return v_st;
end;
--调用函数 plsql语句块
declare
v_str varchar2(20);
v_sal number;
begin
v_str := getSal('SMITH',v_sal);
dbms_output.put_line(v_str);
dbms_output.put_line(v_sal);
end;
-- 带有 in out 参数的函数 同样有out参数的函数,只能由plsql语句块调用函数
create or replace function swap(num1 in out number,num2 in out number)
return varchar2
as
temp number;
begin
temp := num1;
num1 := num2;
num2 := temp;
return 'abc';
end;
--调用函数
declare
num1 number := 10;
num2 number := 20;
v_str varchar2(20);
begin
dbms_output.put_line(num1||'=========='||num2);
v_str := swap(num1,num2);
dbms_output.put_line(num1||'=========='||num2);
end;
oracle 之 函数的更多相关文章
- oracle add_months函数
oracle add_months函数 add_months 函数主要是对日期函数进行操作,举例子进行说明 add_months 有两个参数,第一个参数是日期,第二个参数是对日期进行加减的数字(以月为 ...
- Oracle to_date()函数的用法
Oracle to_date()函数的用法 to_date()是Oracle数据库函数的代表函数之一,下文对Oracle to_date()函数的几种用法作了详细的介绍说明,供您参考学习. 在Orac ...
- Oracle over函数
Oracle over函数 SQL code: sql over的作用及用法RANK ( ) OVER ( [query_partition_clause] order_by_clause )DE ...
- Oracle常用函数
前一段时间学习Oracle 时做的学习笔记,整理了一下,下面是分享的Oracle常用函数的部分笔记,以后还会分享其他部分的笔记,请大家批评指正. 1.Oracle 数据库中的to_date()函数的使 ...
- Oracle SQL函数
Oracle将函数大致分为单行函数,聚合函数和分析函数. 单行函数分为字符函数,日期函数,转换函数,数字函数,通用函数,decode函数 一.字符函数 1)大小写控制函数 01.Lower() 全部小 ...
- Oracle trunc()函数的用法
Oracle trunc()函数的用法 /**************日期********************/1.select trunc(sysdate) from dual --2013-0 ...
- oracle中函数和存储过程的区别和联系【转载竹沥半夏】
oracle中函数和存储过程的区别和联系[转载竹沥半夏] 在oracle中,函数和存储过程是经常使用到的,他们的语法中有很多相似的地方,但也有自己的特点.刚学完函数和存储过程,下面来和大家分享一下自己 ...
- 转,Oracle中关于处理小数点位数的几个函数,取小数位数,Oracle查询函数
关于处理小数点位数的几个oracle函数() 1. 取四舍五入的几位小数 select round(1.2345, 3) from dual; 结果:1.235 2. 保留两位小数,只舍 select ...
- oracle日期函数转换真麻烦。。。
--Oracle trunc()函数的用法/**************日期********************/1.select trunc(sysdate) from dual --2011 ...
- Oracle to_char()函数的使用细则
Oracle to_char()函数的使用细则,学习连接 http://www.cnblogs.com/reborter/archive/2008/11/28/1343195.html
随机推荐
- Spring MVC Integration,Spring Security
http://docs.spring.io/spring-security/site/docs/4.2.0.RELEASE/reference/htmlsingle/#authorize-reque ...
- here was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache
tomcat重启后报以下错误: 09-Dec-2016 10:57:49.150 WARNING [localhost-startStop-1] org.apache.catalina.webreso ...
- wkhtmltopdf 中文参数详解
linux:wkhtmltopdf [OPTIONS]… [More input files] windows:wkhtmltopdf.exe [OPTIONS]… [More input files ...
- Leetcode: K-th Smallest in Lexicographical Order
Given integers n and k, find the lexicographically k-th smallest integer in the range from 1 to n. N ...
- Leetcode: Battleships in a Board
Given an 2D board, count how many different battleships are in it. The battleships are represented w ...
- Ubantu16.4的安装过程以及基本配置
Ubantu16.4的安装过程以及基本配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 欢迎加入高级运维工程师之路:598432640 其实很早以前就听朋友说ubantu这怎么好 ...
- MVC筛选自定义属性下拉表
MVC筛选自定义属性下拉表 string CompanyId = ""; CompanyId = ManageProvider.Provider.Current().Company ...
- Java使用占位符拼接字符串
大家知道,在C#编程中,可以用占位符来拼接字符串,用起来非常的方便. 特别是需要进行大量的参数拼接的时候,比如: Console.WriteLine(String.Format("该域名{0 ...
- Magento开发常用方法
这里是我做Magento开发常用到的方法,现在总结出来,后续会把更多有用的方法总结出来. 1.直接操作数据库 查找数据:$read = Mage::getSingleton("core/re ...
- 自定义属性 view
首先自定义一个圆,相信以前的学习大家都会画圆,在values下写一些自定义的属性 package com.exaple.day01rikao; import android.content.Conte ...