Oracle
 sql >> Database >  >> RDS >> Oracle

come eseguire una funzione per restituire il tipo di riga da una tabella in pl/sql?

Impostazione 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;
/

Blocco PL/SQL :

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

Risultato :

Bob