2016-04-07 4 views

Antwort

1

Oracle-Setup:

CREATE TABLE account1 (
account_id INT, 
name  VARCHAR2(20) 
); 

INSERT INTO account1 VALUES (1, 'Bob'); 

create or replace function get_accounts 
(Acc_id in Account1.account_id%Type) 
return account1%rowtype 
as 
l_cust_record account1%rowtype; 
begin 
select * into l_cust_record from account1 
where account_id=Acc_id; 
return(l_cust_record); 
end; 
/

PL/SQL-Block:

DECLARE 
    r_acct ACCOUNT1%ROWTYPE; 
BEGIN 
    r_acct := get_accounts(1); 
    DBMS_OUTPUT.PUT_LINE(r_acct.name); 
END; 
/

Ausgang:

Bob 
0

Um eine Funktion in Oracle aufzurufen, müssen Sie ihren Rückgabewert verwenden. Das heißt, Sie können es nicht wie eine Prozedur bezeichnen. So etwas wie dies funktionieren würde:

declare 
    myrow account1%rowtype; 
    account_id Account1.account_id%Type := <VALID ACCOUNT ID VALUE>; 
begin 
    myrow := Get_Accounts(account_id); 
end; 
/
Verwandte Themen