I made this function but it return an error when i execute it!
create or replace function get_accounts
(Acc_id in Account1.account_id%Type)
return account1%r
To call a function in Oracle, you need to use its return value. That is, you can't call it as you would a procedure. Something like this would work:
declare
myrow account1%rowtype;
account_id Account1.account_id%Type := <VALID ACCOUNT ID VALUE>;
begin
myrow := Get_Accounts(account_id);
end;
/
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;
/
Output:
Bob