Samet Dağ
Samet Dağ

Reputation: 167

Invalid Identifier and return statement cannot contain expression in PL/SQL

I am trying to create function in PL/SQL but I am getting invalid identifier error

( for username VARCHAR2) and

"In a procedure, RETURN statement cannot contain an expression" error.

I tried similar questions solutions about invalid identifer and return statemnt error but noone of them worked for me.

I couldn't fix the issue . Idk what's the reason for throwing error.

I am using oracle 19c with oracle sql developer

Can you help me ? Thanks in advance

My create function code :

CREATE OR REPLACE FUNCTION bring_product
(
username VARCHAR2
)
RETURN pr%ROWTYPE
AS
product_tbl pr%rowtype;
BEGIN

 SELECT *  INTO product_table FROM PRODUCT pr WHERE pr.kulusername = username ;

 RETURN product_tbl ;

END;

Upvotes: 0

Views: 3082

Answers (1)

Barbaros Özhan
Barbaros Özhan

Reputation: 65105

You cannot use a table alias for variable declaration of %rowtype attribute-style

but the table name. So, convert to the following one :

SQL> CREATE OR REPLACE FUNCTION bring_product(username VARCHAR2)
        RETURN product%rowtype AS
   product_tbl product%rowtype;
BEGIN
  SELECT *
    INTO product_tbl
    FROM product pr
   WHERE pr.kulusername = username;

  RETURN product_tbl;
END;
/

Upvotes: 1

Related Questions