Question When you create a function in PostgreSQL, “Error: Syntax error is in or near” RowType “

The following is a simple process in PL/SQL

PROCEDURE emp_get_rec (emp_rec IN OUT NOCOPY emp_content%ROWTYPE)< br /> IS
v_cnt NUMBER;
BEGIN
SELECT COUNT(*)
INTO v_cnt
FROM emp_content
WHERE emp_id = emp_rec.emp_id;
IF v_cnt = 1
THEN
SELECT * INTO emp_rec
FROM emp_content
WHERE emp_id = emp_rec.emp_id;
END IF;
END emp_get_rec;

I am trying to convert in PostgreSQL,

Create or replace function emp_get_rec (emp_rec IN OUT emp_content%ROWTYPE)
AS $BODY$< br />DECLARE
v_cnt NUMBER;
BEGIN

SELECT COUNT(*)
INTO v_cnt
FROM emp_content
WHERE emp_id = emp_rec. emp_id;
IF v_cnt = 1
THEN
SELECT * INTO emp_rec
FROM emp_content
WHERE emp_id = emp_rec.emp_id;
END IF;
END;
$BODY$LANGUAGE'plpgsql';

I am facing the following error:

ERROR: syntax error at or near “ROWTYPE”

< /div>

Documentation says:

Whenever you create a table, a composite type is also automatically created, with the same name as the table, to represent the table’s row type.

Therefore, you can use the table name as the type name, syntactically it represents the type:

< /p>

create or replace function emp_get_rec (emp_rec IN OUT emp_content)

The following is a simple process in PL/SQL

< p>

PROCEDURE emp_get_rec (emp_rec IN OUT NOCOPY emp_content%ROWTYPE)
IS
v_cnt NUMBER;
BEGIN
SELECT COUNT(*)
INTO v_cnt
FROM emp_content
WHERE emp_id = emp_rec.emp_id;
IF v_cnt = 1
THEN
SELECT * INTO emp_rec
FROM emp_content
WHERE emp_id = emp_rec.emp_id;
END IF;
END emp_get_rec;

I tried to convert in PostgreSQL,

Create or replace function emp_get_rec (emp_rec IN OUT emp_content%ROWTYPE)
AS $BODY$
DECLARE
v_cnt NUMBER;
BEGIN

SELECT COUNT(*)
INTO v_cnt
FROM emp_content
WHERE emp_id = emp_rec.emp_id;
IF v_cnt = 1
THEN
SELECT * INTO emp_rec
FROM emp_content
WHERE emp_id = emp_rec.emp_id;
END IF;
END;
$BODY$LANGUAGE'plpgsql';

I am facing The following errors:

ERROR: syntax error at or near “ROWTYPE”

< p>Documentation says:

Whenever you create a table, a composite type is also automatically created, with the same name as the table, to represent the table’s row type.

Therefore, you can use the table name as the type name, and syntactically it means the type:

create or replace function emp_get_rec (emp_rec IN OUT emp_content)

Leave a Comment

Your email address will not be published.