create?or?replace?function?f(d?number)

創(chuàng)新互聯(lián)專注于清徐企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站,電子商務(wù)商城網(wǎng)站建設(shè)。清徐網(wǎng)站建設(shè)公司,為清徐等地區(qū)提供建站服務(wù)。全流程按需定制設(shè)計(jì),專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
return?varchar
is
begin
return?substr(d,instr(d,'.')+1);
end?f;
select?f(12.34)?from?dual;
基本概念
存儲(chǔ)過程和存儲(chǔ)函數(shù)相當(dāng)于一個(gè)東西。
存儲(chǔ)過程在Oracle里叫procedure。
存儲(chǔ)過程沒有返回值。
存儲(chǔ)函數(shù)在Oracle里叫function。
存儲(chǔ)函數(shù)有返回值。
基本語法
create or replace procedure 名字
--create or replace 意思是創(chuàng)建或者替換
as
--可以在此定義參數(shù)
begin
語句;
end;
例:
create? or? replace ? procedure ? sayhello
as
--說明 相當(dāng)與declare
begin
dbms_output.put_line('Hello World');
end;
基本調(diào)用
begin
-- Call the procedure
sayhello;
sayhello;
sayhello;
end;
帶參數(shù)的存儲(chǔ)過程--查詢某個(gè)員工的年收入
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;
特別的地方,參數(shù)要指明是輸入?yún)?shù)還是輸出參數(shù)。
存儲(chǔ)函數(shù)
create or replace function Fupmoney(tname in varchar2) ?? return number
as ? ? --定義月薪參數(shù)
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;
創(chuàng)建一個(gè)多輸出參數(shù)的存儲(chǔ)函數(shù)例子
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;
你這是無返回類型啊。
應(yīng)該這么寫試試。
create or replace function fu_pr02 return varchar2 as ----創(chuàng)建函數(shù)fu_pr02
2 number is yearsal number(7,2);---定義自變量yearsal
3 begin
4 select sal*12+nvl(comm,0)*12 into yearsal from emp where ename='WARD';--查詢用戶名叫wade的年薪并賦值給yearsal
5 return yearsal;
6 end;
create or replace
FUNCTION "函數(shù)名"
(
A in number,
B in number,
name in VARCHAR2
)
BEGIN
insert into 表名 values(A+B,name);
END 函數(shù)名;
//花括號(hào)里邊就是需要傳的參數(shù),name如果是固定的可以直接寫死,就不用傳參了
新聞標(biāo)題:oracle函數(shù)如何創(chuàng)建 oracle的函數(shù)怎么寫
網(wǎng)頁URL:http://chinadenli.net/article42/hejhhc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、動(dòng)態(tài)網(wǎng)站、網(wǎng)站制作、標(biāo)簽優(yōu)化、關(guān)鍵詞優(yōu)化、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)