Pl/sql Error: Identifier 'Record' must be declared
I am new to pl/sql. I am having a requirement to retrieve a row based on the given row id. For that I wrote a function that returns the row. This is the function that I have written.
CREATE OR REPLACE FUNCTION CHECKROW(ROW_ID_ IN VARCHAR2)
RETURN TBL_SPT%ROWTYPE
IS
VAR_TEMP_ TBL_SPT%ROWTYPE;
CURSOR GET_ROW IS
SELECT *
FROM TBL_SPT
WHERE ROWID = ROW_ID_;
BEGIN
OPEN GET_ROW;
FETCH GET_ROW
INTO VAR_TEMP_;
--Here I wrote the print statement to get the id only.
DBMS_OUTPUT.PUT_LINE(VAR_TEMP_.s_id);
RETURN VAR_TEMP_;
CLOSE GET_ROW;
END CHECKROW;
But when I test this function, it give the below error. My first question is why does this function give this error? I have used a cursor here. Is it wrong? Should I use a record? The other question is, should I use 'VAR_TEMP_.id' type for all the fields if I want to print the records. Is there any other method?
Here are my table definitions.
Name Type
----------- ------
S_ID NUMBER
P_ID NUMBER
PR_ID NUMBER
QUANTITY NUMBER
ROW_VERSION DATE
Here is the calling function that is produced when testing. row_id_
is a string.
declare
-- Non-scalar parameters require additional processing
result record;
begin
-- Call the function
result := checkrow(row_id_ => :row_id_);
end;
Solution 1:
The error is coming from the anonymous block you have calling the function, not from the function itself; it isn't getting as far as actually making that call.
The declaration:
result record;
should be:
result TBL_SPT%ROWTYPE;
to match the function's return type. It looks like the boiler-plate code uses a generic 'record' which it expects you to define or replace. And as it says in a comment, "Non-scalar parameters require additional processing".
That doesn't mean that your function doesn't have issues, as noted in comments; but those aren't causing this error.