PostgreSQL操作rowtype类型(赋值、插入)

前端之家收集整理的这篇文章主要介绍了PostgreSQL操作rowtype类型(赋值、插入)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
CREATE OR REPLACE FUNCTION create_new_stu()
  RETURNS trigger AS
$BODY$
declare
usrid int;
student students%rowtype;
begin
usrid := NEW.id;
select * from students where sno='111' into student;
student.sname := 'zxh';
if student.cno is NULL then
	student.scid := 1;
end if;
insert into students select student.*;

return NEW;

end;

$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION create_new_stu()
  OWNER TO postgres;

rowtype类型的变量可以看作一个结构体,可以通过点访问符来获取修改某个字段的值。将某个rowtype类型的变量值直接插入到某个结构相同的表中:

insert into students select student.*;

猜你在找的Postgre SQL相关文章