Issue While creating function in PostgreSQL "ERROR: syntax error at or near "ROWTYPE""
Issue While creating function in PostgreSQL "ERROR: syntax error at or near "ROWTYPE""
下面是PL/SQL
中的简单程序
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;
我正在尝试在 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';
我遇到以下错误:
ERROR: syntax error at or near "ROWTYPE"
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.
因此您可以使用 table 名称作为类型名称,在句法上它表示类型:
create or replace function emp_get_rec (emp_rec IN OUT emp_content)
下面是PL/SQL
中的简单程序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;
我正在尝试在 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';
我遇到以下错误:
ERROR: syntax error at or near "ROWTYPE"
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.
因此您可以使用 table 名称作为类型名称,在句法上它表示类型:
create or replace function emp_get_rec (emp_rec IN OUT emp_content)