I want to store the value of this query inside a Stored Procedure:
select * from myname;
using
select * into mydata from myname
but an error "mydata" is not a known variable occurs. Is there a way to store those results into a variable in postgre?
Assuming you are trying to do this in the context of a PL/PgSQL function, then you have to declare the variable first.
CREATE OR REPLACE FUNCTION foobar() RETURNS void AS $$
DECLARE
mydata RECORD;
BEGIN
SELECT * INTO mydata FROM mytable;
-- now do something with mydata
END
$$ LANGUAGE plpgsql;
See:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.