模式在 Postgresql 中不存在错误

schema does not exist error in Postgresql

我在 postgresql 中执行以下函数时有以下表和函数,它显示错误:架构 "tblmark" 没有 exist.Please 帮助。

CREATE TABLE "LandXML_QCC_ParcelMarks"("DPID" TEXT,"From" TEXT,"Name" TEXT);

INSERT INTO "LandXML_QCC_ParcelMarks" VALUES ('1','ram','kumar');

CREATE TABLE "LandXML_QCC_ParcelInformation"("DPID" TEXT,"Pntref" TEXT)

INSERT INTO "LandXML_QCC_ParcelInformation" VALUES ('1','ram');

CREATE OR REPLACE FUNCTION GetParcelNonParcel(PlanID TEXT)
RETURNS TEXT AS $GetParcelNonParcel$
DECLARE
    tblMark RECORD;
    parCount INTEGER;
    parNonCount INTEGER;
    totalParNonCount TEXT;
    tblCou INTEGER;
BEGIN
    parCount=0;
    parNonCount=0;

    FOR tblMark IN (SELECT * FROM "LandXML_QCC_ParcelMarks" WHERE "DPID" = PlanID) LOOP
        SELECT COUNT(*) INTO tblCou FROM "LandXML_QCC_ParcelInformation"
            WHERE "DPID"=PlanID
                AND (
                    "Pntref" LIKE '%' || tblMark.From || ',' || tblMark.Name '%'
                    OR
                    "Pntref" LIKE '%' || tblMark.Name || ',' || tblMark.From '%'
                );

        RAISE NOTICE 'Value: %', tblCou;

        IF tblCou > 0 THEN
            parCount = parCount + 1;
            RAISE NOTICE 'Value: %', parCount;
        ELSE
            parNonCount = parNonCount + 1;
        END IF;
    END LOOP;

    totalParNonCount = CAST(parCount AS TEXT) || ',' || CAST(parNonCount AS TEXT);
    RAISE NOTICE 'Value: %', totalParNonCount;
    RETURN totalParNonCount;
END;
$GetParcelNonParcel$ LANGUAGE plpgsql;

select GetParcelNonParcel('1');

执行上述功能时,显示错误:架构 "tblmark" 不存在。

FOR 循环内的 SELECT 中,您有以下条件:

... AND (
        "Pntref" LIKE '%' || tblMark.From || ',' || tblMark.Name '%'
        OR
        "Pntref" LIKE '%' || tblMark.Name || ',' || tblMark.From '%'
        )

您两次都缺少尾随 '%' 的串联运算符 ||。此外,您没有正确引用记录的列。由于您使用 " (双引号)建立了它们,因此您将始终需要以完全相同的方式引用它们(这是您不应该这样做的原因。所以如果不晚,请更改它不带引号的名字。)。

使用您的临时列名,这应该可以帮助您:

... AND (
        "Pntref" LIKE '%' || tblMark."From" || ',' || tblMark."Name" || '%'
        OR
        "Pntref" LIKE '%' || tblMark."Name" || ',' || tblMark."From" || '%'
        )