0
即使我清空所有DECLARE塊和BEGIN-END塊並嘗試返回一個字符串,似乎也無法將此函數用於創建。任何人都可以幫我解決我在這裏做錯了什麼嗎?plpgsql在'CREATE'處或附近創建函數語法錯誤
試圖在pgAdminIII執行此(Ubuntu的):
CREATE OR REPLACE FUNCTION split_country()
RETURNS text as $$
DECLARE
titlecsv text;
arCountries text[];
country_cursor CURSOR
FOR SELECT DISTINCT country
FROM festfriend.films;
BEGIN
OPEN country_cursor;
LOOP
FETCH NEXT FROM country_cursor INTO titlecsv;
EXIT WHEN NOT FOUND;
SELECT regexp_split_to_array(titlecsv, ',') INTO arCountries;
RAISE NOTICE '%1', arCountries;
INSERT INTO festfriend.country (name, acronym)
SELECT trim(both ' ' from a.column2), upper(left(trim(both ' ' from a.column2), 3))
FROM unnest((SELECT arCountries)::text[]) WITH ORDINALITY a(column2)
WHERE (SELECT COUNT(id) FROM festfriend.country WHERE name = trim(both ' ' from a.column2)) = 0
AND char_length(trim(both ' ' from a.column2)) > 0;
END LOOP;
CLOSE country_cursor;
RETURN 'Split Countries, yo!';
END; $$
LANGUAGE 'plpgsql';
得到以下錯誤:
ERROR: syntax error at or near "CREATE"
LINE 1: CREATE OR REPLACE FUNCTION split_country()
^
********** Error **********
ERROR: syntax error at or near "CREATE"
SQL state: 42601
Character: 1
你正在做一些錯誤 - 它在我的比賽中沒有任何問題。可能您嘗試將更多的語句發送給服務器,並且缺少分號。 –