您的位置:首页 > 数据库

PostgreSQL笔记 存储过程 循环插入数据

2011-01-06 13:56 1366 查看
CREATE OR REPLACE FUNCTION autoGenFeature_function() RETURNS text AS
$$
DECLARE
b_count int;
beacon_id int;
_total int;
BEGIN
select count(*) into b_count from beacon;
_total := b_count;
while b_count>0 loop
select pid into beacon_id from beacon limit 1 offset b_count-1;
insert into workfeature(typeid, typeactid, beaconid, creatorid, createdate, remark) values (7, 7, beacon_id, 1, now(), '系统自动生成的航标巡检作业');
b_count := b_count-1;
end loop;
RETURN '一共添加了' || _total || '个航标的巡检作业';
END;
$$
LANGUAGE plpgsql;


PostgreSQL 存储过程小示例

CREATE OR REPLACE FUNCTION increment(i integer) RETURNS integer AS $$
BEGIN
RETURN i + 1;
END;
$$ LANGUAGE plpgsql;


CREATE FUNCTION add(integer, integer) RETURNS integer
AS 'select $1 + $2;'
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: