简体   繁体   中英

insert and update a table using cursor

I'm trying to insert records to table

input from information_schema :

select table_schema,table_name,table_type
from information_schema.tables
where table_schema = 'MYSCHEMA';

expected output:

insert into new table along with DDL of table_name to get DDL: select get_ddl('table','INVOICING')

Can you help me?

create or replace procedure proc_getddl
is
v_tableschema varchar(30);
v_tablename varchar(30);
v_tabletype varchar(30);
v_getddl varchar(110);

cursor getddl is 
select table_schema,table_name,table_type,get_ddl('table','INVOICING')
from information_schema.tables
where table_schema = 'MYSCHEMA';
begin
open getddl;
LOOP
fetch getddl into v_tableschema,v_tablename,v_tabletype,v_getddl;
EXIT WHEN getddl%NOTFOUND;
INSERT INTO backup_table
values (v_tableschema,v_tablename,v_tabletype,v_getddl);

END LOOP;
close getddl;
end proc_getddl;

I can use this but I want it to execute for all tables in information schema

Try something like

create table backup_table as 

select table_schema,table_name,table_type,get_ddl('table','INVOICING')
from information_schema.tables
where table_schema = 'MYSCHEMA';

According to this https://sparkbyexamples.com/snowflake/snowflake-create-table-as-select/

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM