WHILE循环

最近更新时间: 2024-06-12 15:06:00

postgres=# CREATE OR REPLACE FUNCTION f27() RETURNS VOID AS
postgres-# $$    
postgres$# DECLARE
postgres$#     v_id INTEGER := 1;
postgres$#     v_random float8 := random() ;
postgres$# BEGIN           
postgres$#     WHILE v_random > 0.8 LOOP
postgres$#         RAISE NOTICE '%',v_id;
postgres$#         v_id := v_id + 1;
postgres$#         v_random = random();
postgres$#     END LOOP;  
postgres$# END;
postgres$# $$
postgres-# LANGUAGE plpgsql;
CREATE FUNCTION
postgres=# SELECT f27();
NOTICE:  1
 f27 
-----
(1 row)