Generate script for filling table

Hi all,
I've got table at test Oracle server table1 with columns ID, BTYPE, MYDESCRIPTION. Rows of this table have been inserted manually. Now my need is to write script for creating table (structure + data). I think about writing something like
CREATE TABLE table 1
AS
SELECT 1 AS ID, 'TYPE1' AS BTYPE, 'SOME TEXT' AS MYDESCRIPTION
UNION ALL
SELECT 2 AS ID, 'TYPE2' AS BTYPE, 'SOME TEXT 2' AS MYDESCRIPTION
But rows are too many to type... Could you please suggest some way of generating script for creating table at working server using existing table at test server? The problem is I don't have an access to working server.
Thanks ahead.

Use the view user_tab_cols
say
declare
cursor c1 is
select 'e_'||column_name ||' '||data_type||' ('||data_length||') ' col
  from user_tab_cols
  where table_name = 'DEPARTMENTS'
union
select 'd_'||column_name ||' '||data_type||' ('||data_length||') ' col
  from user_tab_cols
  where table_name = 'EMPLOYEES';
v1 varchar2(500);
begin
v1 := 'create table new_tabl (';
for i in c1 loop
v1 := v1||i.col||',';
end loop;
v1 := substr(v1,1,length(v1)-1);
dbms_output.put_line(v1||')');
end;
/i am using employees and departments table of hr schema.
now as both the tables have some column column so i have used e for employees and d for departments
just do one thing remove the length for date data type in o/p i dont know why it is not working.
this will give you structure for data use any sql stmt
Edited by: 810345 on Jun 9, 2011 9:58 PM

Similar Messages

  • Shell script for online table redefinition

    Hi,
    Could someone help me out in building a script for online table redefinition in AIX 11g, moving the table into a new table space.
    Thanks

    You are embarking upon a voyage in which you will expend a substantial effort reinventing the wheel.
    Look at Oracle DBMS_REDEFINITION built-in package.
    http://www.morganslibrary.org/reference/pkgs/dbms_redefinition.html
    and never do something outside the database, in a proprietary language, that can be done far more efficiently inside the RDBMS in a platform independent language.
    In other words, inside the database, I could code your entire project with error handling, in far less than an 15 minutes including testing.
    With a simple DDL statement, issued at the command prompt in SQL*Plus ... I could do it in less than 15 seconds: Your choice.
    ALTER TABLE <table_name> MOVE TABLESPACE <new_tablespace_name>;

  • Make a script for build table

    Hi everyone
    How to make a script for build table:
    col width 25mm
    align decimal
    align on close paren
    Thanks
    Teetan

    Hi Teetan VK,
    Merry Chrismas.
    I'm not really an InDesign scripter.
    But you can try the following code:
    // TableCreate_simple.jsx
    // regards pixxxelschubser
    var aDoc = app.activeDocument;
    // your width of every column
    var w = Number(prompt("width of columns", 25));
    var NrOfColumns = 3;
    var aTextFrame = aDoc.textFrames.add({visibleBounds:[0, 0, 30, NrOfColumns*w + 1]});
    var aTable = aTextFrame.insertionPoints[0].tables.add({columnCount:NrOfColumns,bodyRowCount:1});
    for (i=0; i<aTable.columns.length; i++) {
    aTable.columns[i].width = w;
    // Paragraph sytyle with decimal aligning should already exists in your document
    for (j = 0; j < aTable.cells.length; j++) {
        aTable.cells[j].texts[0].appliedParagraphStyle = aDoc.paragraphStyles.item("AlignDecimal");
    Be sure, that a paragraph style (named with "AlignDecimal") exists in your Document.
    But what is:
    Teetan VK schrieb:
    … align on close paren …

  • Unable to generate statistics for the table

    I have got a staging table of more than 600 columns which has got range portioning. Size of the table is 4GB. The average size of the row is around 3 MB. I have created a Functional index on one of the column ABC VARCHAR2(50) and it has only number values. Now when I try generating statistics for this table through ANALYZE or DBMS_STAT, it gives Invalid Number error but when I drop this index and try analyzing, it works.
    Executed TO_NUMBER(ABC) query on the table and it works fine.
    I have got Functional Indexes on other tables also but I don't get such problem with those tables. I tried dropping the index and re-creating it but it didn't work out.
    I was suspecting DATA BLOCK CORRUPTION so checked ALERT LOG and TRACE FILES but found nothing.
    So what is this magic called?

    I am using TO_NUMBER on the column.
    I have checked the MetaLink for the same problem but could not find anything on that. I still suspect datafile error which I am unable to get in ALERT LOG or TRACE FILES. So I am going to try it this way:
    1) Create new Tablespace with New Datafile
    2) Transfer the table from existing Tablespace to new Tablespace
    3) Create the functional index in the same new Tablespace
    4) Try generating the statistics.
    5) If it works then create seprate Tablespace for data and Index.
    Hope it works !!
    Thanks for the reply guys.

  • Is table maintenance generator only for custom table?

    hi ,
    i have doubt is table maintenance generator only for custom table?

    hi swamya,
    Table Maintanance Generator is used to create/change/delete table entries in a particular table.
    In the production system, end-users will not be having access to transaction codes like SE11 and SE16. Developers will not be having access to many transaction codes including the above two.To view the contents of the database table, we will use SE16n in Production system. All these authorizations will be maintained by BASIS team, by creating access profiles.So in order to edit or create the contents of a database table, we should go for table maintenance generator. In real time, authorizations will be maintained in production system.
    The second reason is, we can edit or create multiple entries at a time, using tablemaintenance generator.
    Apart from that we have options like 'Enter conditions' in table maintenance screen SM30.
    hope this helps in clearing ur doubt.
    Regards
    Saurabh

  • Required to create a script for base table update using XMLSTORE package.

    Hi can anybody provide me some help full suggestion on how to update base table using XMLSTORE package.
    I created a simple script for Employee table and can able to do the basic operation like Insert and update on the table.
    Query is as follow's
    DECLARE
    insCtx DBMS_XMLSTORE.ctxType;
    rows NUMBER;
    xmlDoc CLOB :=
    '<ROWSET>
    <ROW num="1">
    <EMPLOYEE_ID>922</EMPLOYEE_ID>
    <SALARY>1801</SALARY>
    <HIRE_DATE>17-DEC-2007</HIRE_DATE>
    <JOB_ID>ST_CLERK</JOB_ID>
    <EMAIL>RAUSSJACK</EMAIL>
    <LAST_NAME>JACK</LAST_NAME>
    <DEPARTMENT_ID>20</DEPARTMENT_ID>
    </ROW>
    <ROW>
    <EMPLOYEE_ID>923</EMPLOYEE_ID>
    <SALARY>2001</SALARY>
    <HIRE_DATE>31-DEC-2005</HIRE_DATE>
    <JOB_ID>ST_CLERK</JOB_ID>
    <EMAIL>PATHAK</EMAIL>
    <LAST_NAME>PRATIK</LAST_NAME>
    <DEPARTMENT_ID>20</DEPARTMENT_ID>
    </ROW>
    </ROWSET>';
    BEGIN
    insCtx := DBMS_XMLSTORE.newContext('EMPLOYEES'); -- Get saved context
    DBMS_XMLSTORE.clearUpdateColumnList(insCtx); -- Clear the update settings
    -- Set the columns to be updated as a list of values
    DBMS_XMLSTORE.setUpdateColumn(insCtx, 'EMPLOYEE_ID');
    DBMS_XMLSTORE.setUpdateColumn(insCtx, 'SALARY');
    DBMS_XMLSTORE.setUpdateColumn(insCtx, 'HIRE_DATE');
    DBMS_XMLSTORE.setUpdateColumn(insCtx, 'JOB_ID');
    DBMS_XMLSTORE.setUpdateColumn(insCtx, 'EMAIL');
    DBMS_XMLSTORE.setUpdateColumn(insCtx, 'LAST_NAME');
    DBMS_XMLSTORE.setUpdateColumn(insCtx, 'DEPARTMENT_ID');
    -- Insert the doc.
    rows := DBMS_XMLSTORE.insertXML(insCtx, xmlDoc);
    --COMMIT;
    DBMS_OUTPUT.put_line(rows || ' rows inserted.');
    -- Close the context
    DBMS_XMLSTORE.closeContext(insCtx);
    END;
    SELECT employee_id, LAST_name FROM employees WHERE employee_id = 114;
    DECLARE
    updCtx DBMS_XMLSTORE.ctxType;
    rows NUMBER;
    xmlDoc CLOB :=
    '<ROWSET>
    <ROW>
    <EMPLOYEE_ID>114</EMPLOYEE_ID>
    <LAST_NAME>PRABHU</LAST_NAME>
    </ROW>
    </ROWSET>';
    BEGIN
    updCtx := DBMS_XMLSTORE.newContext('EMPLOYEES'); -- get the context
    DBMS_XMLSTORE.clearUpdateColumnList(updCtx); -- clear update settings
    -- Specify that column employee_id is a "key" to identify the row to update.
    DBMS_XMLSTORE.setKeyColumn(updCtx, 'EMPLOYEE_ID');
    rows := DBMS_XMLSTORE.updateXML(updCtx, xmlDoc); -- update the table
    DBMS_XMLSTORE.closeContext(updCtx); -- close the context
    commit;
    END;
    Nowi want little modification on this above query like as i am passing static XML tags and i want it to pick the dynamic XML from web and use the XMLSTORE for the update.
    and also for complex XML having 2-3 levels how this query needs to be changed.As i am new to this Oracle utillity any help from xepert will be a great help for me.
    Thanks

    Nowi want little modification on this above query like as i am passing static XML tags and i want it to pick the dynamic XML from webFrom a Web Service?
    You'll need UTL_HTTP or HttpUriType interface to send the request and receive the XML response.
    Search in the forum, there are already a lot of useful examples available.
    and also for complex XML having 2-3 levels how this query needs to be changed.DBMS_XMLStore is OK for readily processing a canonical XML format (/ROWSET/ROW/COLUMN structure or alike).
    However, if you have to deal with a more complex structure, you either have to :
    - use a target object table that matches the XML structure
    - preprocess the input document using XSLT to transform it to canonical format
    That's why DBMS_XMLStore is not appropriate for multilevel documents, especially if they contain nested repeating groups.
    In this case, XMLTable is a more flexible way of parsing the XML and process it relationally at the same time.
    Depending on the size of the document, performance may be improved with schema-based object-relational storage.
    For more help, please post a new thread in the {forum:id=34} forum, with the following information :
    - database version (select * from v$version)
    - a sample XML document (the complex one)
    - DDL of your target table
    - mapping between XML elements and columns (ie which tag goes to which column?)
    - an XML schema (if you have one)

  • How to find out the script for the table using SQL

    Hi,
    Could any one tell me that how to find out the script for the table using SQL.
    Thanks,
    kamal

    Kamal,
    You can find the SQL query in Advanced tab of Answers
    Thanks,
    Balaa...

  • Generating Insert Scripts for multiple tables

    Hi,
    I have 6 tables TABLA,TABLB,TABLC,TABLED,TABLEE,TABLEF
    I want to generate Insert Scripts for the above 6 tables.
    Is there any mechanism to do so so that i can generate the .sql files for the above 6 tables to another schema?
    Any help will be needful for me.

    Hi,
    May the below given function script help you...
    CREATE OR REPLACE FUNCTION get_insert_script (v_table_name VARCHAR2)
       RETURN VARCHAR2
    AS
       b_found   BOOLEAN         := FALSE;
       v_tempa   VARCHAR2 (8000);
       v_tempb   VARCHAR2 (8000);
       v_tempc   VARCHAR2 (255);
    BEGIN
       FOR tab_rec IN (SELECT table_name
                         FROM all_tables
                        WHERE table_name = UPPER (v_table_name))
       LOOP
          b_found := TRUE;
          v_tempa := 'select ''insert into ' || tab_rec.table_name || ' (';
          FOR col_rec IN (SELECT   *
                              FROM cols
                             WHERE table_name = tab_rec.table_name
                          ORDER BY column_id)
          LOOP
             IF col_rec.column_id = 1
             THEN
                v_tempa := v_tempa || '''||chr(10)||''';
             ELSE
                v_tempa := v_tempa || ',''||chr(10)||''';
                v_tempb := v_tempb || ',''||chr(10)||''';
             END IF;
             v_tempa := v_tempa || col_rec.column_name;
             IF INSTR (col_rec.data_type, 'CHAR') > 0
             THEN
                v_tempc := '''''''''||' || col_rec.column_name || '||''''''''';
             ELSIF INSTR (col_rec.data_type, 'DATE') > 0
             THEN
                v_tempc :=
                      '''to_date(''''''||to_char('
                   || col_rec.column_name
                   || ',''mm/dd/yyyy hh24:mi'')||'''''',''''mm/dd/yyyy hh24:mi'''')''';
             ELSE
                v_tempc := col_rec.column_name;
             END IF;
             v_tempb :=
                   v_tempb
                || '''||decode('
                || col_rec.column_name
                || ',Null,''Null'','
                || v_tempc
                || ')||''';
          END LOOP;
          v_tempa :=
                v_tempa
             || ') values ('
             || v_tempb
             || ');'' from '
             || tab_rec.table_name
             || ';';
       END LOOP;
       IF NOT b_found
       THEN
          v_tempa := '- Table ' || v_table_name || ' not found';
       ELSE
          v_tempa := v_tempa || CHR (10) || 'select ''- commit;'' from dual;';
       END IF;
       RETURN v_tempa;
    END;(copied and pasted from a commercial site)
    *009*
    Edited by: 009 on Jan 14, 2010 10:43 PM
    (Function after debug)

  • Unable to generate spool for two tables in report output

    Hi,
    I created report with two custom containers displaying two tables in output. When I execute the report in background spool is created only for one table in top custom container.
    What should be done to generate spool for both the tables in two different custom containers.
    Thanks,
    Abhiram.

    Hi,
    Check the bellow link for your requirement.
    <<link removed>>
    Regards,
    Goutam Kolluru.
    Edited by: kishan P on Feb 2, 2012 1:50 PM

  • Simple SELECT query to generate  INSERT for a table

    Hi,
    I am looking for a SELECT query which generates INSERT statements for a table.Please guide.
    Thanks
    PG.

    Like this?
    SQL> SELECT * from kons;
         COL1      COL2
            1         1
            2         2
    SQL> SELECT 'INSERT INTO kons VALUES('||col1||','||col2||');' statement FROM kons;
    STATEMENT
    INSERT INTO kons VALUES(1,1);
    INSERT INTO kons VALUES(2,2);
    SQL> If you have character and / or date columns you will have to change my example,
    but you might get the idea from it.
    You can spool the result to a file.
    Regards,
    Guido
    Edit: ';' added to end of statement...

  • How do i get a script for a table

    hai
    i need sql query to create table script for already existing table.
    can any body help me.
    Edited by: 800324 on Feb 24, 2011 12:07 AM

    for examle
    SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name)
         FROM USER_ALL_TABLES uEdited by: Mahir M. Quluzade on Feb 24, 2011 12:23 PM

  • Where to dowload table script for demo table EMPLOYEE

    Hello!
    I'm reading the book "Oracle PL/SQL Programming, Fourth Edition"
    By Steven Feuerstein.
    And I can't find the script for the employee table ..
    Where can I get it?
    Regards
    Tobias

    Copy this script in notepad and then save in .sql format and then run
    rem
    rem Header: hr_main.sql 09-jan-01
    rem
    rem Copyright (c) 2001, Oracle Corporation. All rights reserved.
    rem
    rem Owner : ahunold
    rem
    rem NAME
    rem hr_main.sql - Main script for HR schema
    rem
    rem DESCRIPTON
    rem HR (Human Resources) is the smallest and most simple one
    rem of the Sample Schemas
    rem
    rem NOTES
    rem Run as SYS or SYSTEM
    rem
    rem MODIFIED (MM/DD/YY)
    rem ahunold 08/28/01 - roles
    rem ahunold 07/13/01 - NLS Territory
    rem ahunold 04/13/01 - parameter 5, notes, spool
    rem ahunold 03/29/01 - spool
    rem ahunold 03/12/01 - prompts
    rem ahunold 03/07/01 - hr_analz.sql
    rem ahunold 03/03/01 - HR simplification, REGIONS table
    rem ngreenbe 06/01/00 - created
    SET ECHO OFF
    PROMPT
    PROMPT specify password for HR as parameter 1:
    DEFINE pass = &1
    PROMPT
    PROMPT specify default tablespeace for HR as parameter 2:
    DEFINE tbs = &2
    PROMPT
    PROMPT specify temporary tablespace for HR as parameter 3:
    DEFINE ttbs = &3
    PROMPT
    PROMPT specify password for SYS as parameter 4:
    DEFINE pass_sys = &4
    PROMPT
    PROMPT specify log path as parameter 5:
    DEFINE log_path = &5
    PROMPT
    -- The first dot in the spool command below is
    -- the SQL*Plus concatenation character
    DEFINE spool_file = &log_path.hr_main.log
    SPOOL &spool_file
    REM =======================================================
    REM cleanup section
    REM =======================================================
    DROP USER hr CASCADE;
    REM =======================================================
    REM create user
    REM three separate commands, so the create user command
    REM will succeed regardless of the existence of the
    REM DEMO and TEMP tablespaces
    REM =======================================================
    CREATE USER hr IDENTIFIED BY &pass;
    ALTER USER hr DEFAULT TABLESPACE &tbs
    QUOTA UNLIMITED ON &tbs;
    ALTER USER hr TEMPORARY TABLESPACE &ttbs;
    GRANT CONNECT TO hr;
    GRANT RESOURCE TO hr;
    REM =======================================================
    REM grants from sys schema
    REM =======================================================
    CONNECT sys/&pass_sys AS SYSDBA;
    GRANT execute ON sys.dbms_stats TO hr;
    REM =======================================================
    REM create hr schema objects
    REM =======================================================
    CONNECT hr/&pass
    ALTER SESSION SET NLS_LANGUAGE=American;
    ALTER SESSION SET NLS_TERRITORY=America;
    -- create tables, sequences and constraint
    @?/demo/schema/human_resources/hr_cre
    -- populate tables
    @?/demo/schema/human_resources/hr_popul
    -- create indexes
    @?/demo/schema/human_resources/hr_idx
    -- create procedural objects
    @?/demo/schema/human_resources/hr_code
    -- add comments to tables and columns
    @?/demo/schema/human_resources/hr_comnt
    -- gather schema statistics
    @?/demo/schema/human_resources/hr_analz
    spool off

  • Generate dbsequnce for a table using a bean

    Is it possible to generate the next dbsequence for a table using bean?
    Thanks

    If you are only interested in the number in the bean, you should implement a service method in out application module, expose it to the client interface and call this via the binding layer.
    public oracle.jbo.domain.Number getSequenceNumber()   {
            try    {
                String seq = "YOUR_DB_SEQUENCE_SEQ";
                oracle.jbo.server.SequenceImpl empSeq =
                    new oracle.jbo.server.SequenceImpl(seq, getDBTransaction());
                oracle.jbo.domain.Number zSerienNrSeq = empSeq.getSequenceNumber();
                return zSerienNrSeq ;
            catch (Exception e)        {
                e.printStackTrace();
            return null;
    }Timo

  • Installation script for installing tables

    I am trying to create a packaged application .(package include app, themes, images , shared components and underlying tables)
    something similar to the lines of package application samples available here
    http://www.oracle.com/technology/products/database/application_express/packaged_apps/packaged_apps.html
    Please let me know if there is a way to create installation scripts for tables+sequences+triggers+data.
    Appreciate it

    These are MS Windows patches, say for server 2012.
    this is a simple batch file am using for monthly patches. But now there are servers in staging area of DC which are required to patch with all missing patches from last 1year or so. We got all the patches in to a folder, and need to run against each server.
    ================================
    SC QUERY state= all | findstr "DISPLAY_NAME | STATE" > C:\Services_Before_Reboot_Dec_14.txt
    # will grab service beofore reboot
    Windows8.1-KB2992611-x64.msu /quiet /norestart
    Windows8.1-KB3008923-x64.msu /quiet /norestart
    Windows8.1-KB3011780-x64.msu /quiet /norestart
    Windows8.1-KB3013126-x64.msu /quiet /norestart
    Pause
    ===================
    Cheers, Ramakrishna Darla.

  • Scripts for external table

    We've lost our backup script for a particularly hairy EXTERNAL TABLE def'n. TOAD is botching the script. Is there a SQL statement I can execute against the db which will deliver back the script?
    -Chuck

    Charles,
    <br>You can use DBMS_METADATA package.</br>
      1  SELECT dbms_metadata.get_ddl('TABLE', table_name)
      2  from user_tables
      3* where table_name = 'EXT_RN_DEPLOY_DATA' --your table name
    SQL> /
      CREATE TABLE "SCOTT"."EXT_RN_DEPLOY_DATA"
       (    "MONITOR_ID" VARCHAR2(30),
            "SAMPLE_ID" VARCHAR2(30),
            "LATITUDE" VARCHAR2(10),
            "DEW_POINT" NUMBER(18,8)
       ORGANIZATION EXTERNAL
        ( TYPE ORACLE_LOADER
          DEFAULT DIRECTORY "DATA_FILE_DIR2"
          ACCESS PARAMETERS
          ( RECORDS DELIMITED BY NEWLINE SKIP 1
    BADFILE DATA_FILE_DIR2:'REVEXT%A_%P.BAD'
    LOGFILE DATA_FILE_DIR2:'REVEXT%A_%P.LOG'
    FIELDS TERMINATED BY ","
    OPTIONALLY ENCLOSED BY '"'
    MISSING FIELD VALUES ARE NULL
          LOCATION
           ( "DATA_FILE_DIR2":'load.csv'
       REJECT LIMIT UNLIMITED
    SQL> <br>More info <a href=http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch15.htm#1005930><b>here</b></a></br>
    <br>Nicolas.</br>

Maybe you are looking for

  • Material wise reciept and Issue report with Opening and Closing Stock

    Hi I need a report,Material wise Receipt and issue with Opening and Closing stock.Is there any standard report available in SAP ? Or we have to go for Customised Report. Please reply

  • Less than a Month into BT and already shocked

    I am so shocked by BT I signed up for broadband as I really liked the upload speed compared to virgin media or Sky but wow am I regretting it now.  I signed up and everything was delivered and setup just as they said it was and even my infinity 2 spe

  • Substitution of Profit center at the time of goods issue for consumption

    Dear All, We have a requirement of changing the profit center at goods issue level i.e. when goods is issued for consumption, it will pick the profit center maintained at Sales order level instead of picking Profit center maintained in Finished Goods

  • Weird Artifactin​g with Windows Live Messenger

    So, I noticed that I get some artifacting with Windows Live Messenger's notifications after restoring my W520 to its factory settings again. I got angry at it and restored it to factory settings again, and it is still present. Yes, I've tried updatin

  • Feature Request: External Monitor!

    Please make Front Row work on external monitors without having to change the primary monitor to the external. This is a major pain, and it must be common for lots of people to use their large displays as a secondary monitor, so I'm frankly baffled at