我正在嘗試在 pgAdmin 的查詢工具中運行這個簡單的 WHILE 回圈:
DECLARE @counter INT = 1;
WHILE @counter <= 5
BEGIN
PRINT @counter;
SET @counter = @counter 1;
END
所需的結果只是一個從 1 到 5 的串列,但我的 pgAdmin 正在回傳此錯誤: *ERROR: syntax error at or near "@" LINE 1: DECLARE @counter INT = 1;
我是非 IT 課程的本科生,所以我希望您在解釋時考慮到這一點。謝謝!(代碼來源)
uj5u.com熱心網友回復:
您的示例來自SQL Server,而不是PostgreSQL。你應該嘗試這樣的事情:
do $$
declare
counter integer := 0;
begin
while counter < 5 loop
raise notice 'Counter %', counter;
counter := counter 1;
end loop;
end$$;
uj5u.com熱心網友回復:
由于問題的標簽不正確,此答案假定來源是 postgres 語法,而不是 sql-server。
SQL 識別符號和關鍵字必須以字母(az,但也可以是帶有變音符和非拉丁字母的字母)或下劃線 (_) 開頭。識別符號或關鍵字中的后續字符可以是字母、下劃線、數字 (0-9) 或美元符號 ($)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/397713.html
