Thiết lập Oracle :
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;
/
Khối PL / SQL :
DECLARE
r_acct ACCOUNT1%ROWTYPE;
BEGIN
r_acct := get_accounts( 1 );
DBMS_OUTPUT.PUT_LINE( r_acct.name );
END;
/
Đầu ra :
Bob