oracle创建函数(oracle创建函数权限不足)
本篇文章给大家谈谈oracle创建函数,以及oracle创建函数权限不足对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、在线等! Oracle语句如何创建函数
- 2、107 ORACLE 创建存储过程,存储函数
- 3、Oracle题:创建一个函数,以员工号为参数,返回该员工所在部门的平均工资。
- 4、Oracle创建函数(根据雇员的薪资,佣金计算出雇员的年薪) year_salary(int salary,int commission_pct);
在线等! Oracle语句如何创建函数
CREATE OR REPLACE FUNCTION STUDENT_EXISTS(V_SNAME VARCHAR2)
RETURN VARCHAR2
IS V_RESULT VARCHAR2(100);
BEGIN
SELECT decode(count(*),0,'0',1,'1','2') into V_RESULT
FROM
Students
WHERE
Stu_Name=V_SNAME;
RETURN (V_RESULT);
END;
Students 换成 查旦中询的数据表名
Stu_Name 换成配缓对应姓培迟模名的表字段名
用下面的进行测试
SELECT STUDENT_EXISTS('李明') FROM dual;
107 ORACLE 创建存储过程,存储函数
基本概念
存储过程和存储函数相当于一个东西。
存储过程在Oracle里叫procedure。
存储过程没有返回值。
存储函数在Oracle里叫function。
存储函数有返回值。
基本语法
create or replace procedure 名字
--create or replace 意思是创建或者替换
as
--可以在此定义参数
begin
语句;
end;
例:
create or replace procedure sayhello
as
--说明 相当与declare
begin
dbms_output.put_line('Hello World');
end;
基本调用
begin
-- Call the procedure
sayhello;
sayhello;
sayhello;
end;
带参数的晌穗槐存储过程--查询某个员工的年收入
create or replace procedure upmoney(testname in test_procedure.name%type)
as
begin
update test_procedure t set t.money = t.money + 1000
where t.name = testname;
end
upmoney;
特别的地方,参数要指明是输入参数还是输出参数。
存储函数
create or replace function Fupmoney(tname in varchar2) return number
as --定义月薪参数
tmoney test_procedure.money%type;
begin
--得到月薪
select t.money
into tmoney
from test_procedure t
where t.name = tname;
dbms_output.put_line(tmoney*12);
return(tmoney*12);
end;
创建一个多输出参宴友数的存储函族态数例子
create or replace procedure manyparm(tname in varchar2,
tjob out varchar2,
tmoney out number,
tdept out varchar2)
is
begin
select t.job,t.money,t.dept
into tjob,tmoney,tdept
from test_procedure t
where t.name = tname;
end manyparm;
Oracle题:创建一个函数,以员工号为参数,返回该员工所在部门的平均工资。
创建一个函数,以部门号为参数,返回该部门的平均工资。
createorreplacefunctionf_sxt6(v_deptnoemp.deptno%type)returnemp.sal%typeis
vr_salemp.sal%type;
begin
selectavg(sal)intovr_salfromempwheredeptno=v_deptno;
returnvr_sal;
end;
执行
selectf_sxt6(20)部门平均工资fromdual;
扩展备睁资料:
创建一个函数,以员工号为参高衡数,返仿念岁回该员工所在的部门的平均工资。
createorreplacefunctionf_sxt7(v_empnoemp.empno%type)returnemp.sal%typeis
vr_salemp.sal%type;
begin
selectavg(sal)intovr_salfromempwheredeptno=(selectdeptnofromempwhereempno=v_empno);
returnvr_sal;
end;
执行:
select f_sxt7(7369)fromdual;
[img]Oracle创建函数(根据雇员的薪资,佣金计算出雇员的年薪) year_salary(int salary,int commission_pct);
说下思路
一个雇员的年薪=月薪*12
所以这个函数很简单
create or replace function year_salary
(salary int) --输入参数
return int --输拿谨出参数类型
is
commission_pct int;--定义输出参数
begin
commission_pct:=salary*12; --输出参数计算方圆敏敬法
return(commission_pct); --返回值
end;
执行
select year_salary(100) from dual --比如月薪100
结果应该橘慎是1200,也就是年薪
关于oracle创建函数和oracle创建函数权限不足的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。