oracle 函式學習應用3月8日

2021-08-16 10:54:08 字數 2337 閱讀 3691

一.建立乙個函式

在pl/sql  devoloper 中新建乙個「function」函式,函式便自動帶出開頭與結尾」

create or replace function  函式名(name in type,name in type,name in type) return varchar2 is

functionresult varchar2;

begin

return(functionresult);

end 函式名;

例:函式名(name in type,..) 裡的name in type 為入參值的名稱,例如入參值的欄位名為party_id,該入參值的字元型別為數值型,則為「函式名(party_id in number)。

二.為函式宣告變數值

在begin之前宣告變數的值 例:cc number(10)   便聲名cc為數值型且長度不超過10的變數。

三.用if條件來判斷並賦值

if...then...end if;

例:某乙個欄位的值與其中的值有相似的就給返回值賦值

if rec.cust_name like'未登記%' then

ret_msg:='【提示】客戶未實名校驗,如使用者辦理業務請實名制或過戶到實名客戶'||chr(10)||ret_msg; 

end if;

四.用for迴圈來進行欄位的的

for rec in(select 欄位名1,欄位名2,欄位名3...from 表 where 條件) loop

end loop;

例:需要校驗不同欄位的值,與if搭配使用。

for rec in(

select ccu.cust_name,ccu.cust_type,ccu.region_id,ccu.status_cd,

(select max(cert_num)from  party_cert_view pc where pc.party_id=ccu.party_id and pc.cert_type='1') x

from  customer_view ccu

where ccu.party_id=dy_party_id

)loop

if rec.cust_name like'未登記%' then

ret_msg:='【提示】客戶未實名校驗,如使用者辦理業務請實名制或過戶到實名客戶'||chr(10)||ret_msg; 

end if;

if rec.cust_name is null then`,,k

ret_msg:='【異常】客戶缺少名稱,(cust.customer)中name欄位為空,前台不能定位客戶'||chr(10)||ret_msg;

return ret_msg;

end if;

if rec.cust_type='1000'and rec.x is not null  then

ret_msg:='【提示】客戶有身份證資訊,但是判定為組織客戶。使用者如要辦理業務,建議諮詢使用者後為使用者辦理新客戶並過戶到新客戶後辦理'||chr(10)||ret_msg; 

end if;

if rec.cust_type='1000' and rec.x is  null then

ret_msg:='【正常】客戶未校驗身份證資訊判定為組織客戶,注意辦理業務需要使用者提供單位證明或號碼使用證明。使用者如需要轉成個人客戶需要辦理新客戶並過戶到新客戶'||chr(10)||ret_msg; 

end if; 

if rec.region_id='' then

ret_msg:='【異常】客戶地區為成都市(crm.party),可能導致訂購銷售品不可見'||chr(10)||ret_msg; 

return ret_msg;

end if;

if rec.status_cd is null then

ret_msg:='【異常】客戶狀態為空(crm.party.party_status_cd),可能導致產品號碼不可見'||chr(10)||ret_msg; 

return ret_msg;

end if;

if rec.region_id like'' then

ret_msg:='【提示】客戶地區非大成都範圍,辦理業務請注意銷售品選擇'||chr(10)||ret_msg; 

end if;

end loop;

需要注意:

1.賦給返回值的ret_msg:=『』××××××  」的是」:=「這樣的符號。

2.code section的開始和結束都是有「begin ...end;」對應的。

8月3號 學習報告

這一周,主要接觸了學習了以下內容 1.oracle資料庫從非歸檔狀態轉變為歸檔狀態,還有一些操作oracle資料庫的基本操作。2.mysql 資料庫,可能是自然而然地成為了這週學習的重點,從基本的運算元據庫,到遠端登入資料庫,到遠端用python指令碼操作mysql資料庫,因為測試過程中需要備份和恢...

oracle統計函式學習

資料庫準備 create table emp deptno int not null,ename varchar 100 default null,sal int default null insert into emp values 10,king 5000 insert into emp val...

oracle 日期函式學習一

時間和日期處理函式 檢索年份是2007的所有 prod end資料 select from products where to number to char prod end,yyyy 2007 select from products where prod end between to date ...