Oracle function usage

Source: Internet
Author: User
Method 1: variables with the same table Type

Create or replace function f_get_cust_name (v_no in customer. No % Type, v_compno in customer. compno % Type)
Return customer. Name
% Type
Is
V_name customer. Name
% Type;
Begin
Select customer. Name into v_name
From customer
Where
No
= V_no and compno = V_compno;
Return v_name;
Exception when no_data_found then return
'   ' ; --- Restore Blank
End;

Method 2: Change Data with a self-defined sequence

Create or replace function f_get_cust_name (v_no in varchar2, v_compno in varchar2)
Return varchar2
Is
V_name varchar2;
Begin
Select customer. Name into v_name
From customer
Where
No
= V_no and compno = V_compno;
Return v_name;
Exception when no_data_found then return
'   ' ; --- Restore Blank
End;

Example: -- 1 to confirm Login
-- 2. The password is incorrect.
-- 3. The specified snapshot does not exist.
-- Return Value Type
Create or replace function getaccount (acc_id
In Members. account_id % Type, acc_pwd In Members. account_password % Type)
Return Number
Is
V_result number;
V_count number;
V_acc_pwd members. account_password
% Type;
Begin

Select count (*)AsCount, Members. account_password into v_count, v_acc_pwd
From members
WhereMembers. account_id=Acc_id
Group by members. account_password;

If V_count > 0
Then
 
If V_acc_pwd = Acc_pwd then
V_result:
= 1 ;
Else
V_result:
= 2 ;
End
If ;
Else
V_result:
= 3 ;
End
If ;

 ReturnV_result;
Exception when no_data_found then return
3;
End;
Since: http://tw.myblog.yahoo.com/adar168-ADARA/article? Mid = 252 & l = F & FID = 7 # yarttrk

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.