开发者

What is the equivalent of PL/SQL %NOTFOUND in PL/pgSQL?

开发者 https://www.devze.com 2023-01-19 02:58 出处:网络
Everything\'s in the title. I am Looping on a cursor and would like to have the EXIT WHEN curs%NOTFOUND

Everything's in the title.

I am Looping on a cursor and would like to have the

EXIT WHEN curs%NOTFOUND

when there is no more row, what is the equivalent of %NOTFOUND under PostgreSQL ?

Edit

Or the other开发者_高级运维 cursors attributes %ISOPEN, %EMPTY, etc...


Can't test this right now but what if you try this? Check out section title 37.7.3.2. EXIT at this link http://www.postgresql.org/docs/8.2/static/plpgsql-control-structures.html

IF NOT FOUND THEN
    EXIT;
END IF;

OR

EXIT WHEN NOT FOUND;


The FOUND variable

Implicit cursor

SELECT * INTO myrec FROM emp WHERE empname = myname;
IF NOT FOUND THEN
    RAISE EXCEPTION 'employee % not found', myname;
END IF;

With an explicit cursor

...   
    LOOP
        FETCH cursor INTO whatever;
        EXIT IF NOT FOUND;
           do something with whatever
    end LOOP;
0

精彩评论

暂无评论...
验证码 换一张
取 消