Creating a table, to replace an old

Salvation of the experts;

I'm looking for advice about what I'll do.
This is the situation;
I had a table of production with more than 1 000 000 000 of records.
queries of this table are too slow, and I decided to create a new table, to replace this one.
But my doubts are:
How can I create a new table, including the same structure as that old and with data.
I received this request:

Create new_table in select * from ancienne_table
where trans_year = '2012 '.
I know with this I got the structure, but what about clues?
Another my doubt is, to replace the old, just I drop and rename a new?

This table belongs to an oracle 9i DB.

Thanks for your comments.

Al

user12048358 wrote:
owner = raditdb exp username/password@raditdb tables = raditdata query = "where status = 'start'" file=/mnt/raditdata.dmp buffer = 50000 log=/mnt/raditdata.log "

You must escape the quotation marks:

 exp username/password@raditdb owner=raditdb tables=raditdata query=\"where status= 'Start'\" file=/mnt/raditdata.dmp buffer=50000 log=/mnt/raditdata.log

Good luck.

Tags: Database

Similar Questions

  • create existing table in another schema

    Hi master,

    We are using oracle 10g R2 on linux.

    I have a scheme say user1 with many tables, starting with

    BC_ (50 PICTURES)

    PC_ (20 TABLES)

    LC_ (30 TABLES) etc.,.

    now, I want to create these tables in another schema with their constraints and their privileges in another schema.

    as I want to generate a create table script, which will create a table that begins with "BC_" only. another script will create table starting with "PC_" only. and like that.

    is it possible with the command

    create the table AS
    Select * from (old scheme). (table_name);

    can we use query sub in it to be more precise?

    and it will transfer all its privileges and grants the new schema?


    Thanks and greetings
    VD

    It is possible to CREATE TABLE as SELECT from a different scheme but CREATE TABLE as SELECT will transfer only the data and the structure of the base (column names and data types) table, no constraints.
    I think, you have two options to do this easily:
    (1) use SQLDeveloper (GUI) or a procedure from PL/SQL DBMS_METADATA. GET_DDL to generate the SQL script to create table with constraints, you can use INSERT INTO new table (columns) column SELECT FROM oldschema.oldtable
    DBMS_METADATA Description: http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_metada.htm#i1019414

    (2) export a schema data, import it into the other using Data Pump or exp/IMP.
    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14215/dp_export.htm#i1007466

  • Create a table with the old table and add the new column

    I want to create a table from old table old table, condition is new table contains a sid column which contains the id of the series.


    sname name sid
    AAA 1A
    BBB 2B
    CCC 3 C
    4 DDD D
    5 EEE E

    Use a sequence.

    SQL> create table t
      2  as
      3  select level no
      4    from dual
      5  connect by level <= 10
      6  /
    
    Table created.
    
    SQL> select * from t
      2  /
    
            NO
    ----------
             1
             2
             3
             4
             5
             6
             7
             8
             9
            10
    
    10 rows selected.
    
    SQL> create sequence my_seq
      2  /
    
    Sequence created.
    
    SQL> create table t1
      2  as
      3  select no, my_seq.nextval no1
      4    from t
      5  /
    
    Table created.
    
    SQL> select * from t1
      2  /
    
            NO        NO1
    ---------- ----------
             1          1
             2          2
             3          3
             4          4
             5          5
             6          6
             7          7
             8          8
             9          9
            10         10
    
    10 rows selected.
    

    Thank you
    Knani.

  • How to create a table in if/else or structure without 0-case?

    Hello

    I tried to do for a while now.

    I only managed to think about this in three ways:

    1. (what I'm doing right now create the table through a loop for, fills the table in automatic indexing.) Filled it with many of if true and with a '0' if the value false. The idea was to remove the 0 later in the code. However, this seems very inefficient.

    2 make use of a registry change, which automatically adds the correct number of a table. The problem is that the table will keep growing and growing and at the very least would enormously slow down my program. At worst, it would break.

    So my question is: how to create a table that if a comparison is true, it puts the item in and if not, it does nothing?

    I have attached a PNG of my code snippet.

    Kind regards

    David.

    If you want to only affect exactly as much memory as you need for the table, you can count the number of true elements in the table of Boolean everything first and then assign one of exactly this size. In this way, you are more memory and time-efficient whether overuse (such as allocation of an array of I32 as big as the whole table boolean) or underallocating (from zero element and let it grow automatically whenever you add on).

    Count the true values, allocate an array only the great and then replace each value in this new table with indexes / "I ' value where the real exists." An excerpt from VI:

  • Replacing an old hard drive causes the system had become unbootable

    OK, here's the scenario.

    Background:
    My old computer with Windows XP has been installed on a hard disk of 40 GB. Later through subsequent updates, I bought the upgrade Windows Vista Professional (retail) and proceeded to install Vista on a brand new 250 GB hard drive. Initially, he had some problems I did a clean install with upgrade to Vista, but then with the help of Mircrosoft support (and several hours of reformats and corrupt the old installation of XP) managed to get Vista installed hard disk new and active. I kept the old drive hard in the computer for about a year, but then noticed that he was starting to get out. I moved all the old information off the drive and recently bought a 1 TB drive to replace. I deleted everything that above with the exception of a few remaining files that won't let me not delete - documents and settings and startup records, respectively.

    Problem:
    When I take the old 40 GB hard drive to reside on Windows XP, my computer when startup is unable to find a drive it can boot from. Under disk management, it is labeled as system - even if the windows directory is on a completely separate drive. My intention was to replace the old hard drive, but I can't get my computer to recognize that it is not on the system drive somehow.

    Question:
    Is it possible to change what hard drive is recognized as a system disk or make sure I can get out the old hard drive and still keep my bootable system?

    Hello Lightningfst,

    Thanks for posting in the Microsoft answers Forum.  First off I would say that, before trying any of the suggestions I'm about to do that you completely back up the contents of the drive with Vista Business as a precaution.  The first suggestion I have is to copy the MBR of the disk of 40G to 250G drive.  It could be as simple as that.  However, when Windows sees a drive and initializes it, Windows writes a serial number of 4 bytes in the MBR (sector 0) of the disc. No matter what partition you create on this disc is then associated with the serial number and the drive letter that the partition is given.

    When you then progress to clone a boot partition on the new disk with a cloning program that does not copy the MBR, the serial number of the old drive is not copied to the new disk, so the new disk retains its serial number Windows has seen before.

    When Windows starts on the new disc, he sees the serial number of the new drive and guess the partition that is on that now belongs to the previously selected drive letter which is almost always not C:. Since installing Windows starts on C:, there is now no C: drive when Windows starts. Trying to connect allows Windows attempts to load the user from C:\Documents and Settings\registry, and the C: drive is not there, so Windows simply to abandon the attempt to logon and closes a session back.

    If this happens to you after copy the MBR of the disk of 40G to 150G Unit let us know and we can help you solve the problems that.  I hope this information is useful.

    Thank you

    Jack

    Jack
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • Anonymous blocks that goes down and creates a table

    Version: 11.2.0.3

    I'm relatively new to PL/SQL.

    We have a table named CHK_CNFG_DTL.

    I want to create a backup table for CHK_CNFG_DTL who will be named as CHK_CNFG_DTL_BKP_ < timestamp > for example: CHK_CNFG_DTL_BKP_JULY_22_2013

    Creating this backup table must be automated, so I want to create an anonymous block that will first remove the existing backup table and then create a new backup of the original table.

    The code below works fine. But the first time when you run it, the loop will not iterate because there is no such table named % CHK_CNFG_DTL_BKP.

    declare

    v_stmt varchar2 (1000);

    date of T_DATE;

    Start

    for rec in

    (select * from user_tables where table_name like '% CHK_CNFG_DTL_BKP')

    loop

    Start

    run immediately "alter session set nls_date_format =" DD_MON_YYYY "';"

    v_stmt: = 'drop table' | Rec.table_name | "purge."

    dbms_output.put_line (v_stmt);   -Old backup drops table

    immediately run v_stmt;

    Select sysdate in double T_DATE;

    v_stmt: = "create table CHK_CNFG_DTL_BKP_ | TO_DATE (V_DATE): ' in select * from CHK_CNFG_DTL';

    dbms_output.put_line ('Bkp création table CHK_CNFG_DTL_BKP_' | to_date (v_date));

    dbms_output.put_line (v_stmt);

    immediately run v_stmt;  -Creates the new table of backup

    exception

    while others

    then

    dbms_output. Put_line (rec.table_name |'-'|) SQLERRM);

    end;

    end loop;

    end;

    /

    PL/SQL procedure successfully completed.

    -Backup table was not created.

    SQL > select table_name from user_Tables where table_name like '% CHK_CNFG_DTL ';

    TABLE-NAME

    ------------------------------

    CHK_CNFG_DTL

    Of course, this can fixed by creating a table as bleow before running the anonymous block

    SQL > create table CHK_CNFG_DTL_BKP_JULY_22_2013 (x varchar2 (37));

    Table created.

    and now the block will be executed with success as

    24 end;

    25.

    drop table CHK_CNFG_DTL_BKP_JULY_22_2013 purge

    Creating table Bkp CHK_CNFG_DTL_BKP_22_JUL_2013

    create the table CHK_CNFG_DTL_BKP_22_JUL_2013 select * from CHK_CNFG_DTL

    PL/SQL procedure successfully completed.

    But it goes to production. We cannot have a table like CHK_CNFG_DTL_BKP_JULY_22_2013 without an appropriate reason.

    How can I change the code above so that if even if there is no such like '% CHK_CNFG_DTL_BKP' table, he will create the backup table?

    Hello

    Why don't you press the create backup of the loop?

    declare

    v_stmt varchar2 (1000);

    date of T_DATE;

    Start

    for rec in

    (select * from user_tables where table_name like 'CHK_CNFG_DTL_BKP %')

    loop

    Start

    run immediately "alter session set nls_date_format =" DD_MON_YYYY "';"

    v_stmt: = 'drop table' | Rec.table_name | "purge."

    dbms_output.put_line (v_stmt);   -Old backup drops table

    immediately run v_stmt;

    exception

    while others

    then

    dbms_output. Put_line (rec.table_name |'-'|) SQLERRM);

    end;

    end loop;

    Select sysdate in double T_DATE;

    v_stmt: = "create table CHK_CNFG_DTL_BKP_ | TO_DATE (V_DATE): ' in select * from CHK_CNFG_DTL';

    dbms_output.put_line ('Bkp création table CHK_CNFG_DTL_BKP_' | to_date (v_date));

    dbms_output.put_line (v_stmt);

    immediately run v_stmt;  -Creates the new table of backup

    end;

  • How to create queue table?

    How createHow to create the table queue?


    Give me step wise instruction to create the queue table

    solution

    First you must create the type.
    Second, we must CREATE_QUEUE_TABLE with the syntax of the procedure.
    and finally, we must create a CREATE_QUEUE with the syntax of the procedure.

    examples

    SQL > create or replace
    2. TAP 'the name of the type.
    3 (xxxxx VARCHAR2 (10))
    4 xxxx NUMBER,
    5 x_xxx VARCHAR2 (50).
    6 FUNCTION MEMBER card xxxxxx RETURN VARCHAR2
    (7);
    5 B

    Type of creation.

    SQL > START
    DBMS_AQADM 2. CREATE_QUEUE_TABLE (Queue_table-online "the queue table nom.proprietaire",
    3 Queue_payload_type-online "owner.type name",
    storage_clause 4-online "PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 TABLESPACE COMP_TB."
    5 Sort_list => 'ENQ_TIME', Compatible-online ' 8.1.3");
    6 END;
    5 m

    PL/SQL procedure successfully completed.

    SQL > START
    DBMS_AQADM 2. CREATE_QUEUE (nom_file_attente-online "nom.proprietaire queue",
    3 Queue_table => "nom.proprietaire of the table queue", Queue_type => Max_retries 0,-online 5.
    Retry_delay 4-online 0, dependency_tracking => FALSE);
    5 END;
    3 D

    PL/SQL procedure successfully completed.

  • creating a table of blocks of text [AS2]

    Hello

    I want to create a table of text blocks.

    The code I use is.

    for (c=0; c<5; c++) {
        tf = ("test_txt"+c.toString());
        this.createTextField(tf, 10, c*20, 80, 40, 20);
    }
    
    a = [test_txt0, test_txt1, test_txt2, test_txt3, test_txt4];
    
    for (c=0; c<5; c++) {
        a[c].text = "foo " + c.toString();
        a[c].border = true;
        a[c].borderColor = 0x00FF00;
        a[c].textColor = 0x0000FF;
        a[c].size = 24;
    }
    

    The result I want from the code is 5 spead of frames of text on the stage, but only the last block of text is created.

    Untitled-4.png

    What is the right way to create the frames in a loop and then having accsesible in a table?

    Thanks in advance

    Trevor

    The second argument of the createTextField method is the depth.  If you keep by specifying the same depth, you replace whatever you place there whenever you assign to something new at this depth.

  • error on 'create a table in select... '. "table with nested columns

    My Oracle 11.1 database, I have a problem with the nested table.

    on table with script
    CREATE TABLE TXV.IS_PODACI209
    (
      ID_OBJEKTA_IDENTIFIKACIJA  NUMBER(10),
      ID_OBJEKTA                 NUMBER(20),
      DATUM                      TIMESTAMP(6),
      TZ                         NUMBER(3),
      DATA1                      NUMBER(10),
      DATA2                      NUMBER(6),
      DATA3                      NUMBER(10),
      DATA4                      NUMBER,
      DATA5                      TXV.T_NTCIP_ILLUM_TABLE,
      DATA6                      NUMBER(10)
    )
    NESTED TABLE DATA5 STORE AS IS_PODACI209_STORE_TABLE
    TABLESPACE TXV_DATA
    PARTITION BY RANGE (DATUM)
    (  
      PARTITION P_201012 VALUES LESS THAN (TIMESTAMP' 2011-01-01 00:00:00')
        LOGGING
        NOCOMPRESS 
        TABLESPACE TXV_DATA,  
      PARTITION P_MAXVALUE VALUES LESS THAN (MAXVALUE)
        LOGGING
        NOCOMPRESS 
        TABLESPACE TXV_DATA
    )
    NOCOMPRESS 
    NOCACHE
    NOPARALLEL
    MONITORING;
    
    
    CREATE INDEX TXV.IDX_IS_PODACI209_KOMPLEKS ON TXV.IS_PODACI209
    (ID_OBJEKTA_IDENTIFIKACIJA, ID_OBJEKTA, DATUM)
      TABLESPACE TXV_DATA
    LOCAL (  
      PARTITION P_201012
        LOGGING
        NOCOMPRESS 
        TABLESPACE TXV_DATA,  
      PARTITION MAXX
        LOGGING
        NOCOMPRESS 
        TABLESPACE TXV_DATA
    )
    NOPARALLEL;
    that has a nested type column:
    CREATE OR REPLACE TYPE TXV.t_ntcip_ILLUM_FMT as object
    (  BRIGHTNESS_LEVEL FLOAT
    ,   PHOTOCELL_DOWN   FLOAT
    ,   PHOTOCELL_UP  FLOAT
    );
    and I create a table (to copy table partitions in a third table) step to help:
    CREATE TABLE TXV.IS_PODACI209_STAGE NESTED TABLE DATA5 STORE AS IS_PODACI209_STAGE_1 AS SELECT * FROM TXV.IS_PODACI209 WHERE 1=2
    The problem is when I try to move using the partition:
    ALTER TABLE TXV.IS_PODACI209 EXCHANGE PARTITION P_201012 WITH TABLE IS_PODACI209_STAGE EXCLUDING INDEXES WITHOUT VALIDATION UPDATE GLOBAL INDEXES
    I get an error:
    ALTER TABLE TXV.IS_PODACI209
      EXCHANGE PARTITION P_201012
      WITH TABLE IS_PODACI209_STAGE
      EXCLUDING INDEXES
      WITHOUT VALIDATION
      UPDATE GLOBAL INDEXES
    Error at line 3
    ORA-00604: error occurred at recursive SQL level 1
    ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
    but these tables are the same...

    someone had such a problem?

    concerning

    I think the UPDATE GLOBAL INDEXES is the origin of the problem.

    Try this,

    ALTER TABLE IS_PODACI209 EXCHANGE PARTITION P_201012 WITH TABLE IS_PODACI209_STAGE EXCLUDING INDEXES WITHOUT VALIDATION 
    

    Rebuild the indexes manually.

    And if I see your profile, you

    Messages total: 25
    Total issues: 16 (* 14 pending *)

    Always mark a thread as answered once you get the answer. It can save a lot of time for volunteers.

    G.

  • How to create temporary tables in stored procedures.

    Hello

    I am new to oracle, I have a requirement where I need to run a query in a loop for different values of where condition. Here, I need to record the results of the query on each iteration. After the end of the loop, I need to send the results to the front end. I did a lot of research for the concept of the temporary table in oracle, but I found myself unresolved except headaches. Everyone is showing how to create temporary tables in general but not in stored procedure.

    Bad, I need the concept of temporary tables, or is there an alternative way to store temporary results. My procedure looks like this.

    create or replace
    procedure uspMatchCode (parWord varchar2, p_recorderSet to types.cursor_type)
    as
    smallint parCnt;
    Start
    parcnt: = 0;
    Select count (1) in parCnt of...;
    If parcnt > 0 then
    Open for P_recorderSet
    Select field1, field2, field3,... of table1, table2, table2 where < < condition > >
    on the other
    -Here, I want to create a temporary table and store the result for the loop shape into the temporary table.
    CREATE TEMPORARY TABLE global my_temp_table (NUMBER of Column1, Column2) ON COMMIT DELETE ROWS.
    FOR parCnt in 0.3
    loop
    INSERT into my_temp_table select Field1, Field2, field3,... from table1, table2, table2 where < < condition > >
    end loop;
    Open for P_recorderSet
    Select * from < < temporary table > >
    end if;
    end;

    Any help would be great to check me on the problem.

    Thank you
    Kiran.

    This is a change to the query Kiss has posted:

    with data_text like)
    Select regexp_substr (' sales financing marketing ',' [^] +', 1, level ") val
    of tconnect by level<= length('sales="" finance="" marketing')-="" length(replace('sales="" finance="" marketing','="">
    )
    Select * from t, data_text, where t.colname like '% "| data_text. Val |' %'

    This will help you. Please change the column names and the name of the table as a result

  • Find/change the question numbers and create the Table of contents

    Hello! I need help to find all my item numbers and apply a paragraph style so I can use them to create a Table of contents page.

    The sample numbers

    #12345

    #12345-5

    #12345-20

    #12345-ABC

    #12345/N

    I tried to enter #^? ^ ? ^ ? ^ ? ^ ? in the search/replace and but it is exactly 5 characters after the sign #. I wonder if you can find all characters starting by # and up until the last characters.

    Once I found all item numbers, how can I apply the paragraph style to have these characters after the sign #? Because I only want to show item numbers without the # sign on the Table of contents/Index page.

    In addition, I have InDesign CS2, which have no function GREP maybe I can do this without the GREP?

    I really appreciate any help. Thank you very much.

    Are your numbers by themselves in a separate paragraph? OTHERWISE you can not USE the table of contents feature to list all the numbers.

    If are, then just look at # in find/replace, then set it to change formatting a new paragraph style (you must create this style in CS2) that you want to include in the table of contents, then as you say, you can use find/replace once more on the history of the TOC to remove the # of all numbers.

  • Create virtual table.

    Hi all

    I have a table with the subtype, DATAID, ORIGNALDATAID, DATE column.

    Select dataid, orignaldataid table where subtype = 1 and the Date = August 1, 2010.

    I have the above query statement. I need the dataid for further processing, but before the treatment is done. I need to check if the orignaldataid = 0, if yes, dataid remains of another dataid = orginaldataid. Before the list was move to another sql. But I intend to use sql nested for futher treatment, so I need the database to crunch the data instead of using java to change the data.

    I was thinking creaating another table of virtaual in DB where it will automatically do this for me instead of having the column dataid and orginaldatid, it will juice dataid column. Then I can just query the virtual table.
    Select dataid from virtualTable where subtype = 1 and the Date = August 1, 2010. Is this possible?

    I have a few questions to ask, because I'm not clear on what to do:

    (1) of the virtual table, did you mean a temporary table or view Inline?

    (2) is it an inevitable necessity for you to create another table just for fun a column?

    (3) did you want a (kind-of-a-thing) wrapper around the original with the required columns table for java work on, in this case, a query online can be a good option similar to below:

    create or replace view vw_table
    is
    select (case when orignaldataid = 0 then dataid
                      else orignaldataid
              end) dataid
    from table
    where subtype=1 and Date=01-Aug-2010
    

    You can use the select query as-is as a subquery.

    HTH.

  • Create the table in the return procedure ON gets PLS 00306

    I would like to know the best way to do it. I am writing a procedure to create a table if it exists not as a select of.
    All I want to do is return a code completion to the calling program. My error is the wrong number of arguments in the call to create_tab,
    but all I want to do is return the completion code. PLS - 00306 wrong number or types of arguments in the call to Create_tab

    I wonder if the experts out there have a better implementation or suggestions for it.

    Thank you.

    Create or replace procedure create_tab (pstatus NUMBER) is

    sqltextheader varchar2 (200);
    sqltextfrom varchar2 (200);
    sqltextwhere varchar2 (200);
    sqltextdrop varchar2 (200);
    Whole CNT;
    p_err COMP. = 0 ;

    Start

    Select count (*) in the cnt from user_tables where table_name = 'TESTA. "

    DBMS_OUTPUT. Put_line ('cnt value is' | cnt);

    If (cnt = 1)
    then
    sqltextdrop: = 'drop testa table ";
    immediately run sqltextdrop;
    DBMS_OUTPUT. Put_line ('Table testa fell ');

    sqltextheader: = 'crΘer testa table as ";
    sqltextfrom: = ' select * from ssg_test';
    sqltextwhere: = ' where col_one > sysdate ";
    run immediately sqltextheader | '' || sqltextfrom: "| sqltextwhere;
    commit;

    pstatus: = pstatus + 1

    end if;

    If (cnt = 0)

    then

    sqltextheader: = 'crΘer testa table as ";
    sqltextfrom: = ' select * from ssg_test';
    sqltextwhere: = ' where col_one > sysdate ";
    run immediately sqltextheader | '' || sqltextfrom: "| sqltextwhere;
    commit;

    pstatus: = pstatus + 1

    exception
    while others then
    p_created: = pcreated + 2;
    DBMS_OUTPUT. Put_line ('error raised is value' | pcreated_;)
    end create_tab;
    /

    sgonos wrote:
    This effort is just to make code testing and does not come into production. So I need something
    to make a return code to the calling program.

    It's well :)

    So, Yes, the code is consistent, but I get an error on the number of arguments. I am writing this
    procedure for a developer so I don't know exactly its code, other than what he wants me to a return code
    for him.

    Can you show us how you (or 'the developer') call this program?

    If you have examples of this? Where I am confused in the entrance and exit of the parameters for the procedure...

    Generally, if you want to return a single value of a routine, you use a FUNCTION. But you would need to talk to 'the developer' to see what they expect it to come back... and why.

    If I only returns a code of State STATUS OF THE number then why oracle gives me error on the
    wrong number or type of variables. If I set the STATUS in the procedure, then I get an error
    variables in double. Where get set STATE?

    I don't know, I need to see an example of how you call it, but here's an example that you can run using SQLPLUS.

    Create or replace procedure create_tab
    (
      pstatus OUT number
    )
    authid CURRENT_USER
    is
    
      sqltextheader varchar2(200);
      sqltextfrom   varchar2(200);
      sqltextwhere  varchar2(200);
      cnt           integer;
    
    begin
    
      select
        count(*)
      into
        cnt
      from user_tables
      where table_name ='TESTA';
    
      DBMS_OUTPUT.PUT_LINE ('cnt value is ' || cnt);
    
      if cnt = 1
      then
        execute immediate 'drop table testa';
        DBMS_OUTPUT.PUT_LINE('Table testa is dropped');
      end if;
    
      sqltextheader := ' create table testa as   ';
      sqltextfrom   := ' select * from ssg_test  ';
      sqltextwhere  := ' where col_one > sysdate ';
      dbms_output.put_line(sqltextheader || sqltextfrom || sqltextwhere );
      execute immediate sqltextheader || sqltextfrom || sqltextwhere ;
      pstatus := 1;
    
    end create_tab;
    / 
    
    variable x number;
    exec create_tab(:x);
    print :x
    

    I added an AUTHID CURRENT_USER in the procedure. That means that this code executes with the privileges of the user running it, if this isn't something you are willing to have (the code runs with the permissions of the owner of the procedure otherwise)... just remove it.

  • How to create a table with a variable

    Hello world!

    I have a procedure that receives a table as parameter name and need to create a table using this name

    For example:

    PROCEDURE REFRESH_REPORTS (table_name varchar2) IS

    BEGIN
    table_name_REPORT: = table_name;

    run immediately "create table table_name_REPORT...

    But I don't get this job. I'm just add this procedure as part of a package that is used for online/web declarations.

    Could someone guide me how can I create this table?

    I was getting errors such as invalid table name, and I even tried to use a variable that stores the SQL full and concatenated to the name of the table variable, but still that didn't work.

    Thank you so much in advance.

    Nithya

    Published by: user645399 on January 20, 2010 21:42

    You need create a valid SQL statement in the string. And if you want to add variables in this chain, do you this through the concatenation or replacement.

    For example using concatenation

    declare
      tableName varchar2(30);
      sqlCreate varchar2(1000);
    begin
      tableName := 'funky_foo';
      sqlCreate := 'create table '||tableName||' as select * from foo@remotedb';
      -- using dbms_output to enable the display of the SQL that is about to be executed
      execute immediate sqlCreate;
    end;
    

    For example using replacement (better option than the SQL syntax is more easily readable and maintainable and allows several variables to set in the SQL model)

    declare
      SQL_CREATE_TEMPLATE constant varchar2(1000) :=
    'select
       *
    from $TABLE@remotedb';
    
      tableName varchar2(30);
      sqlCreate varchar2(1000);
    begin
      tableName := 'funky_foo';
      sqlCreate := replace( SQL_CREATE_TEMPLATE, '$TABLE', tableName );
      -- using dbms_output to enable the display of the SQL that is about to be executed
      execute immediate sqlCreate;
    end;
    
  • How to create a table with auto-numbering?

    I want to create a table with a default value of column to the increase in whole number. The first thought came to me, is to use the sequence. I find in google than following create statement
    create table etl_stats1 (run_time date,arr_rows int,lid int default nextval('etl_req'));
    get ORA-04044: procedure, function, package or type is not allowed here.

    There are discussions described here uses the trigger to do the job. But that does not support by default in a sequence, it seems so average.

    You must create a sequence and a trigger:

    SQL> create table etl_stats1 (run_time date,arr_rows int,lid int)
      2  /
    
    Table created.
    
    SQL> create sequence etl_seq;
    
    Sequence created.
    
    SQL> create or replace
      2    trigger etl_stats1_bir
      3    before insert
      4    on etl_stats1
      5    for each row
      6    begin
      7        select etl_seq.nextval into :new.lid from dual;
      8  end;
      9  /
    
    Trigger created.
    
    SQL> insert into etl_stats1 (run_time,arr_rows) values(sysdate,99)
      2  /
    
    1 row created.
    
    SQL> select * from etl_stats1
      2  /
    
    RUN_TIME   ARR_ROWS        LID
    -------- ---------- ----------
    15:38:41         99          1
    
    SQL> 
    

    SY.

Maybe you are looking for

  • TOSHIBA Satellite L650-1MU is it original?

    Hello I live in Algeria and I found a good TOSHIBA laptop, the reference is the TOSHIBA Satellite L650-1MU but I've not found in toshiba.com here are the featuresTOSHIBA Satellite L650 - 1MU Core i5 - 480 M W7 laptopProcessor Intel Core i5 - 480 M GH

  • adding the new safety device for the family

    Dear all, I recently bought a new pc W8 for my 12 year old son.  When I added the user account for the new pc, I clicked on the box to indicate that he is a child and accessible account parental to ensure that all of the boxes on the right were click

  • Copy of MS Paint for XP Pro OS to use on a Windows OS Ultra - XP version preferred for use

    I want to copy my version of XP Pro OS MS Paint on my Acer Netbook, which uses the operating system Windows Ultra and Ultra of MS Paint version.  I prefer the old XP version because it is much simpler to use and I know where everything is so that I c

  • HP pavilion touchscreen laptop: green screen on videos (windows 8.1)

    I get a green screen when I try and watch videos (you tube etc.). It's a portable touchscreen and only a couple of the old days (windows 8.1) can you help advise?

  • The iis path network not found

    How to connect to my network from windows XP x 32 to a window 7 64 X from the computer of the tree, no one can conect they can see each other, but no ore file shear connection