Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As you said you call a procedure to create a table from view. So I assume that you already are using dynamic SQL (Native Dynamic SQL aka <code>EXECUTE IMMEDIATE</code> statement or <code>DBMS_SQL</code> package) to execute DDL statements. Then you could generate more complicated <code>CREATE TABLE AS</code> statement with using the Oracle dictionary views such as <a href="http://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_4489.htm" rel="nofollow">USER_VIEWS</a> and <a href="http://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_4462.htm" rel="nofollow">USER_TAB_COLUMNS</a> to get info about columns' types, length, scale and whatever else you may need to write a right CAST call. </p> <p>A dirty example is below:</p> <pre><code>create or replace view v as select decode(dummy, 'Y', '123') s , 1 n , 2.2 f , cast (1.1 as number(5,3)) fs from dual / set serveroutput on declare l_query varchar2(32767) := 'create table t as select &lt;column list&gt; from v'; l_type varchar2(100); begin for tc in ( select * from user_tab_columns where table_name = 'V' order by column_id ) loop l_type := tc.data_type; l_type := l_type || case tc.data_type when 'NUMBER' then case when tc.data_precision is not null then '(' || tc.data_precision || case when tc.data_scale is not null then ','||tc.data_scale end || ')' end when 'VARCHAR2' then '(' || tc.char_length || ' ' || case tc.char_used when 'C' then 'char' else 'byte' end || ')' end; l_query := replace(l_query, '&lt;column list&gt;', 'cast("'||tc.column_name||'" as '|| l_type ||') "'||tc.column_name||'" ,&lt;column list&gt;'); end loop; l_query := replace(l_query, ',&lt;column list&gt;'); dbms_output.put_line(l_query); end; / </code></pre> <p>Results:</p> <pre><code>view V created. anonymous block completed create table t as select cast("S" as VARCHAR2(3 char)),cast("N" as NUMBER),cast("F" as NUMBER),cast("FS" as NUMBER(5,3)) from v </code></pre> <p>Good luck.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload