简体   繁体   中英

Oracle sql developer| export from query to a table

Good day, In DBeaver db manager we are able to transfer data directly from query to a table created by us. We right click>execute>export to a table. Can anyone help me to do the same in oracle developer environment. Here I have created a table in the same connection,and want to store query results into table. Thank you

Right click on your table.

Choose Table - Copy.

在此处输入图像描述

Give it a name, and check 'Include Data'

在此处输入图像描述

You can see the code we're about to run by clicking on the SQL panel.

declare
  l_sql varchar2(32767);
  c_tab_comment varchar2(32767);
  procedure run(p_sql varchar2) as
  begin 
     execute immediate p_sql;
     
  end; 
begin
run('create table "HR".BEERS_COPY as select * from "HR"."BEERS" where '||11||' = 11');
  begin
  select comments into c_tab_comment from sys.all_TAB_comments where owner = 'HR' and table_name = 'BEERS' and comments is not null;
  run('comment on table HR.BEERS_COPY is '||''''||REPLACE(c_tab_comment, q'[']', q'['']')||'''');

  for tc in (select column_name from sys.all_tab_cols where owner = 'HR' and table_name = 'BEERS')
      loop
     for c in (select comments from sys.all_col_comments where owner = 'HR' and table_name = 'BEERS' and column_name=tc.column_name) 
     loop 
     run ('comment on column HR.BEERS_COPY.'||tc.column_name||' is '||''''||REPLACE(c.comments, q'[']', q'['']')||'''');
   end loop;
  end loop;
  EXCEPTION
    WHEN OTHERS THEN NULL; 
  end;
end;
                

So basically a CTAS + we grab the comments for you.

Disclaimer: I'm the product manager for SQL Developer and a Oracle employee.

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