Create Table from XMLTable (with hierarchy)

Hi,
I've following XML File Structure:
<?xml version="1.0" encoding="ISO-8859-1"?>
<MenuSystem>
<Definition>
<Menue label="Main">
<File label="A">
<File label="B">
<File label="C">
<File label="D">
<Prog label="first"/>
<Prog label="second"/>
<Prog label="third"/>
</File>
<File label="E">
<Prog label="1"/>
<Prog label="2"/>
<Prog label="3"/>
</File>
</File>
<File label="F">
<File label="G">
<Prog label="AA"/>
<Prog label="BB"/>
</File>
<File label="H">
<Prog label="CC"/>
</File>
File label="I">
<Prog label="DD"/>
<Prog label="EE"/>
</File>
</File>
</File>
</File>
</Menue>
</Definition>
</MenuSystem>
what I need is a sql query to get following columns:
ID Parent_ID Tag Value
1 0 Menue Main
2 1 File A
3 2 File B
4 3 File C
5 4 File D
6 5 Prog first
7 5 Prog second

You mean instead of "1", "1.1", "1.2" etc. ?
The XSLT solution described in the link does that (pretty much), you just have to remove the leading "K".
Using XQuery, it's feasible too, but retrieving the node ID adds a little complexity :
SQL> SELECT x.*
  2  FROM temp_xml t
  3     , XMLTable(
  4       'declare function local:getChildren($e as node(), $pID as xs:integer?) as element()*
  5        {
  6          for $i in $e/child::*
  7          let $ID := (for $j at $p in $d/MenuSystem/Definition/descendant::* where $j is $i return $p)
  8          return element r
  9          {
10            element node_id {$ID}
11          , element parent_node_id {$pID}
12          , element node_name {name($i)}
13          , element node_value {data($i/@label)}
14          }
15          | local:getChildren($i,$ID)
16        }; (: :)
17        local:getChildren($d/MenuSystem/Definition,())'
18        passing t.doc as "d"
19        columns node_id         number        path 'node_id'
20              , node_name       varchar2(15)  path 'node_name'
21              , node_value      varchar2(30)  path 'node_value'
22              , parent_node_id  number        path 'parent_node_id'
23       ) x
24  ;
   NODE_ID NODE_NAME       NODE_VALUE                     PARENT_NODE_ID
         1 Menue           Main                          
         2 File            A                                           1
         3 File            B                                           2
         4 File            C                                           3
         5 File            D                                           4
         6 Prog            first                                       5
         7 Prog            second                                      5
         8 Prog            third                                       5
         9 File            E                                           4
        10 Prog            1                                           9
        11 Prog            2                                           9
        12 Prog            3                                           9
        13 File            F                                           3
        14 File            G                                          13
        15 Prog            AA                                         14
        16 Prog            BB                                         14
        17 File            H                                          13
        18 Prog            CC                                         17
        19 File            I                                          13
        20 Prog            DD                                         19
        21 Prog            EE                                         19
21 rows selected

Similar Messages

  • CREATE TABLE AS using WITH

    I am converting a PostreSQL query to T-SQL but am running into a syntax error that I cannot understand.
    My main query below works fine.
    WITH itowner AS (
            SELECT itowner_1.comp1id AS businessserviceid,
                person.name AS itowner_name,
                person.username AS itowner_username,
                person.component_id AS itowner_id
               FROM dbo.rel_BusinessServiceHasITOwnerPerson itowner_1
          JOIN comp_Person person ON person.component_id = itowner_1.comp2id
    busowner AS (
             SELECT bown.comp1id AS businessserviceid,
                person.name AS busown_name,
                person.username AS busown_username,
                person.component_id AS busown_id
               FROM dbo.rel_BusinessServiceHasBusinessOwnerPerson bown
          JOIN comp_Person person ON person.component_id = bown.comp2id
    cat AS (
            SELECT biz.component_id businessserviceid, biz.bsname AS Business_Service, 
    c.name AS Category
    FROM dbo.comp_BusinessService biz
    left outer join rel_BusinessServiceHasCategory a on biz.component_id = a.comp1id
    join comp_ApoCategory c on a.comp2id = c.component_id
    LEFT OUTER JOIN comp_ApoCategory c1 ON c.parent = c1.objectuuid
     SELECT 
        cat.Category,
        biz.component_id AS businessservice_id,
        biz.bsname as businessservice_name,
        biz.description,
        itowner.itowner_name,
        busowner.busown_name
       FROM comp_BusinessService biz
       LEFT JOIN itowner  ON itowner.businessserviceid  = biz.component_id
       LEFT JOIN busowner ON busowner.businessserviceid = biz.component_id
       LEFT JOIN cat      ON cat.businessserviceid      = biz.component_id;
    However, as soon as I wrap it in a CREATE TABLE AS I get an syntax error at the first WITH.
       Incorrect syntax near 'WITH'.  Expecting ID.
    Below is the full statement.
    CREATE TABLE "dm_amd_business_services" AS
    WITH itowner AS (
            SELECT itowner_1.comp1id AS businessserviceid,
                person.name AS itowner_name,
                person.username AS itowner_username,
                person.component_id AS itowner_id
               FROM dbo.rel_BusinessServiceHasITOwnerPerson itowner_1
          JOIN comp_Person person ON person.component_id = itowner_1.comp2id
    busowner AS (
             SELECT bown.comp1id AS businessserviceid,
                person.name AS busown_name,
                person.username AS busown_username,
                person.component_id AS busown_id
               FROM dbo.rel_BusinessServiceHasBusinessOwnerPerson bown
          JOIN comp_Person person ON person.component_id = bown.comp2id
    cat AS (
            SELECT biz.component_id businessserviceid, biz.bsname AS Business_Service, 
    c.name AS Category
    FROM dbo.comp_BusinessService biz
    left outer join rel_BusinessServiceHasCategory a on biz.component_id = a.comp1id
    join comp_ApoCategory c on a.comp2id = c.component_id
    LEFT OUTER JOIN comp_ApoCategory c1 ON c.parent = c1.objectuuid
     SELECT 
        cat.Category,
        biz.component_id AS businessservice_id,
        biz.bsname as businessservice_name,
        biz.description,
        itowner.itowner_name,
        busowner.busown_name
       FROM comp_BusinessService biz
       LEFT JOIN itowner  ON itowner.businessserviceid  = biz.component_id
       LEFT JOIN busowner ON busowner.businessserviceid = biz.component_id
       LEFT JOIN cat      ON cat.businessserviceid      = biz.component_id;
    Any advice on getting the correct syntax?
    Thanks, Bruce...

    ;WITH itowner AS (
    SELECT itowner_1.comp1id AS businessserviceid,
    person.name AS itowner_name,
    person.username AS itowner_username,
    person.component_id AS itowner_id
    FROM dbo.rel_BusinessServiceHasITOwnerPerson itowner_1
    JOIN comp_Person person ON person.component_id = itowner_1.comp2id
    busowner AS (
    SELECT bown.comp1id AS businessserviceid,
    person.name AS busown_name,
    person.username AS busown_username,
    person.component_id AS busown_id
    FROM dbo.rel_BusinessServiceHasBusinessOwnerPerson bown
    JOIN comp_Person person ON person.component_id = bown.comp2id
    cat AS (
    SELECT biz.component_id businessserviceid, biz.bsname AS Business_Service,
    c.name AS Category
    FROM dbo.comp_BusinessService biz
    left outer join rel_BusinessServiceHasCategory a on biz.component_id = a.comp1id
    join comp_ApoCategory c on a.comp2id = c.component_id
    LEFT OUTER JOIN comp_ApoCategory c1 ON c.parent = c1.objectuuid
    SELECT
    cat.Category,
    biz.component_id AS businessservice_id,
    biz.bsname as businessservice_name,
    biz.description,
    itowner.itowner_name,
    busowner.busown_name
    INTO dm_amd_business_services --New table
    FROM comp_BusinessService biz
    LEFT JOIN itowner ON itowner.businessserviceid = biz.component_id
    LEFT JOIN busowner ON busowner.businessserviceid = biz.component_id
    LEFT JOIN cat ON cat.businessserviceid = biz.component_id;

  • Create table from external data with dates

    I have a CSV that looks somewhat like this:
    abcuser,12345,5/12/2012,5,250.55
    xyzuser,67890,5/1/2012,1,50
    ghjuser,52523,1/1/1900,0,0
    When I create the external table, then query it I get a date error:
    CREATE TABLE xtern_ipay
    userid VARCHAR2(50),
    acctnbr NUMBER(20, 0),
    datelastused DATE,
    number_rtxns NUMBER(12, 0),
    amtused NUMBER(12, 0)
    organization external ( TYPE oracle_loader DEFAULT directory "XTERN_DATA_DIR"
    ACCESS parameters (
    records delimited BY newline fields terminated BY "," )
    location ('SubscriberStatistics.csv') ) reject limit UNLIMITED;
    Error I see in the reject log:
    Field Definitions for table XTERN_IPAY
    Record format DELIMITED BY NEWLINE
    Data in file has same endianness as the platform
    Rows with all null fields are accepted
    Fields in Data Source:
    USERID CHAR (255)
    Terminated by ","
    Trim whitespace same as SQL Loader
    ACCTNBR CHAR (255)
    Terminated by ","
    Trim whitespace same as SQL Loader
    DATELASTUSED CHAR (255)
    Terminated by ","
    Trim whitespace same as SQL Loader
    NUMBER_RTXNS CHAR (255)
    Terminated by ","
    Trim whitespace same as SQL Loader
    AMTUSED CHAR (255)
    Terminated by ","
    Trim whitespace same as SQL Loader
    error processing column DATELASTUSED in row 1 for datafile g:\externaltables\SubscriberStatistics.csv
    ORA-01858: a non-numeric character was found where a numeric was expected
    error processing column DATELASTUSED in row 2 for datafile g:\externaltables\SubscriberStatistics.csv
    ORA-01858: a non-numeric character was found where a numeric was expected
    error processing column DATELASTUSED in row 3 for datafile g:\externaltables\SubscriberStatistics.csv
    ORA-01858: a non-numeric character was found where a numeric was expected
    Any ideas on this? I know I need to tell oracle the format of the date on the external file, but I can't figure it out.

    Try this:
    CREATE TABLE xtern_ipay
       userid         VARCHAR2 (50)
    , acctnbr        NUMBER (20, 0)
    , datelastused   DATE
    , number_rtxns   NUMBER (12, 0)
    , amtused        NUMBER (12, 2)
    ORGANIZATION EXTERNAL
        ( TYPE oracle_loader DEFAULT DIRECTORY "XTERN_DATA_DIR"
    ACCESS PARAMETERS (
    RECORDS DELIMITED BY NEWLINE FIELDS TERMINATED BY "," MISSING FIELD VALUES ARE NULL
    (   userid
      , acctnbr
      , datelastused DATE 'mm/dd/yyyy'
      , number_rtxns
      , amtused)
    location ('SubscriberStatistics.csv') ) reject LIMIT unlimited;
    select * from xtern_ipay;
    USERID                                                ACCTNBR DATELASTU NUMBER_RTXNS    AMTUSED
    abcuser                                                 12345 12-MAY-12            5     250.55
    xyzuser                                                 67890 01-MAY-12            1         50
    ghjuser                                                 52523 01-JAN-00            0          0
    {code}
    Sorry I had to correct the previous statement again for the date format and for the column amtused that was defined without decimals.
    Regards
    Al
    Edited by: Alberto Faenza on May 31, 2012 6:34 PM
    wrong date format mm/dd/yy instead of dd/mm/yy
    Edited by: Alberto Faenza on May 31, 2012 6:40 PM
    Fixed again the date format and the amtused defined with 2 decimals                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Creating an auto incrementing field with CREATE TABLE from Java

    I'm using the "sun.jdbc.odbc.JdbcOdbcDriver" to get a connection towards an ODBC data source that's linked to a Access (.mdb) database.
    I've tried various combinations in my CREATE TABLE statement execution in order to create a table with an auto incrementing integer but neither of them work, not even the most obvious one:
    stmt.executeUpdate("CREATE TABLE mytable(uid integer AUTO_INCREMENT PRIMARY KEY);");
    I always get this runtime exception: *java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in field definition*; and AUTO_INCREMENT is the problem. I've tried all variations like AUTO, INCREMENT, AUTOINCREMENT and such, but nothing works.
    I've looked everywhere but couldn't find an answer to this. Thanks for the help.

    You used MySQL syntax. I think you agree with me that Access isn't a MySQL database. Either use MySQL with a real JDBC driver (recommended) or use Access syntax.
    That said, creating databases and tables using Java is a bad idea. The database and table must be already there. With Java you just do the usual table operations like select, insert, update and delete. Nothing more is needed.

  • Getting error while creating table from one database to other.

    Hi,
    We are getting below error while creating the table from one database to other.
    SQL> create table fnd_lobs parallel compress as select * from [email protected];
    create table fnd_lobs parallel compress as select * from [email protected]
    ERROR at line 1:
    ORA-01555: snapshot too old: rollback segment number 28 with name "_SYSSMU28$"
    too small
    ORA-02063: preceding line from EEXIT2TEST
    ORA-01555: snapshot too old: rollback segment number 28 with name "_SYSSMU28$"
    too small
    ORA-02063: preceding line from EEXIT2TEST
    ORA-01555: snapshot too old: rollback segment number 28 with name "_SYSSMU28$"
    too small
    ORA-02063: preceding line from EEXIT2TEST
    ORA-01555: snapshot too old: rollback segment number 28 with name "_SYSSMU28$"
    too small
    Regards,
    Bhatia

    hi
    what are the apps version local and remote database???
    Snapshot too old errors occur because Oracle can 't reconstruct a consistent
    image of a block for the purposes of a consistent read.
    I feel at remote database, you are using UNDO, it will be rather easy to iincrease the undo retention time or increase the undo tablespace size.. if you are dealing with roll back segments, you may have rollback segments whose optimal values are too small...
    increase roll back segments size and select again then
    the following metalink notes might be helpful
    ORA-01555 "Snapshot too old" - Detailed Explanation Doc ID: 40689.1
    How To Avoid ORA-01555: Snapshot Too Old When Running PAAPIMP Doc ID: 603259.1
    OERR: ORA 1555 "snapshot too old (rollback segment too small)" Doc ID: 18954.1

  • Returning newly created IDs from View with Instead Of

    Hi All,
    I have the following table:
    CREATE TABLE TBLSIM_SUPPLIER_H
        "SS_ID" NUMBER(10,0) NOT NULL ENABLE,
        "SS_GUID" NVARCHAR2(36) NOT NULL ENABLE,
        "SS_NAME" NVARCHAR2(50) NOT NULL ENABLE,
        "SS_H_IS_ACTIVE" NUMBER(1,0) DEFAULT 1 NOT NULL ENABLE,
        "SS_H_RE_ID"     NUMBER(10,0) NOT NULL ENABLE,
        "SS_H_DATE" DATE DEFAULT SYSDATE NOT NULL ENABLE,
        "SS_H_MASTER_ID" NUMBER(10,0),
        CONSTRAINT "TBLSIM_SUPPLIER_PK" PRIMARY KEY ("SS_ID") ENABLE,
        CONSTRAINT "TBLSIM_SUPPLIER_FK_M_ID" FOREIGN KEY ("SS_H_MASTER_ID") REFERENCES "TBLSIM_SUPPLIER_H" ("SS_ID") ENABLE
      )on which is enabled this trigger
    CREATE OR REPLACE TRIGGER TBLSIM_SUPPLIER_H_TRG BEFORE
      INSERT ON TBLSIM_SUPPLIER_H FOR EACH ROW BEGIN <<COLUMN_SEQUENCES>> BEGIN IF :NEW.SS_ID IS NULL THEN
      SELECT TBLSIM_SUPPLIER_H_SEQ.NEXTVAL INTO :NEW.SS_ID FROM DUAL;
    END IF;
    IF :NEW.SS_GUID IS NULL THEN
      :NEW.SS_GUID  := UTILITYPKG.formatted_guid;
    END IF;
    END COLUMN_SEQUENCES;
    END;UTILITYPKG.formatted_guid returns a standard 36chr GUID
    I then created a view
    CREATE OR REPLACE FORCE VIEW TBLSIM_SUPPLIER
    AS
      SELECT SS_ID,
        SS_GUID,
        SS_NAME,
        SS_H_IS_ACTIVE,
        SS_H_RE_ID,
        SS_H_DATE
      FROM TBLSIM_SUPPLIER_H
      WHERE (ss_h_is_active = 1);on which I enabled the trigger
    CREATE OR REPLACE TRIGGER TBLSIM_SUPPLIER_INS INSTEAD OF
      INSERT ON TBLSIM_SUPPLIER FOR EACH ROW
        BEGIN
      INSERT INTO TBLSIM_SUPPLIER_H (ss_name, ss_h_is_active, ss_h_re_id, ss_h_date)
        VALUES (:NEW.ss_name, 1, :NEW.ss_h_re_id, SYSDATE);
    END TBLSIM_SUPPLIER_INS;I then have a stored Procedure
    PROCEDURE SimSupplier_Create(
          cur_tblresource_id_in IN tblresource.re_id%TYPE
        , ss_name_in IN tblsim_supplier.ss_name%TYPE
        , ss_id_out OUT tblsim_supplier.ss_id%TYPE
        , ss_guid_out OUT tblsim_supplier.ss_guid%TYPE
      ) AS
      BEGIN
        INSERT INTO tblsim_supplier (
          , ss_name
          , ss_h_re_id
        VALUES ( 
          , ss_name_in
          , cur_tblresource_id_in
       RETURNING ss_id, ss_guid INTO ss_id_out, ss_guid_out;
      END SimSupplier_Create; What happens is that the RETURNING clause is not available.
    Any way of getting the ID & GUID of the just inserted record out of the prcedure?
    Thanks
    Andrea

    Why do you need this instead of trigger? Can't you simply insert into the view? Maybe enable WITH CHECK OPTION to prevent wrong values beeing entered via the view. Or simply insert into the table and not the view. As long as it is done in the procedure, you are safe that there is no priviledge confict.
    Edited by: Sven W. on Oct 17, 2012 5:38 PM

  • Can we create table maintence generator with out key field

    Hi,
    I have created a ztable in that client is the primary key as I don't want any other field as primary key.
    For this  i have created table maintenace generator but when i open it in sm30 blnak screen is coming.
    Here my question is can we create a table maintenace generator with out key field other than MANDT.
    If it's possible please let me know.
    Regards
    hari

    >
    Mathews Joseph wrote:
    > I agree to the above points , but you can try one thing.
    >
    > When you create the table maintenance screen , from SE11 you assign a function group.
    >
    > Double click on the function group and you can go to the main program and open that in SE80, take screen generated and try manually adjusting the screen and putting the non key field details...
    >
    > Not sure this will work , but may be you can give it a try.
    >
    > Mathews
    But the table could hold at most a single record (per client). The design is lacking.
    Rob

  • Create table from DBMS_SHARED_POOL.SIZES output

    How can I create a table from the output of DBMS_SHARED_POOL.SIZES output ... If possible at all?
    Thank you !

    Your conclusion is just wrong. dbms_shared_pool.keep is geared at procedures and functions which you are calling over and over again, and which you can't afford to be reloaded often.
    The only thing you avoid by pinning a procedure is the overhead of reloading.
    Secondly in both cases you perform 10000000 inserts instead of 1 bulk insert and this is taking time.
    What you should do is
    SQL> l
    1 insert into scott.test
    2 select trunc(dbms_random.value(10,40)), trunc(dbms_random.value(10,40))
    3 from dual
    4* connect by level <= 1000000
    I can insert 1 million rows in 14.51 seconds
    Your method is the slowest possible.
    And yes, you always should use a spfile, but this has nothing to do with the problem at hand.
    Sybrand Bakker
    Senior Oracle DBA

  • How to create table from method

    Hello -
    Could anyone please tell me how can I create af:table with more than one column from an AppsModule method.
    When I have a 1d array return eg:
    public String[] createTable(){
    String[] str = new String[1];
    return str;
    I can drop it as a table and one column gets created. But how can I get mutiple columns in a table. I want to write a method, which when dropped on jsp page create table with multiple columns.
    I am using ADF 11g.
    Please suggest.
    Regards -
    Rohit

    Hi,
    for this you use an array or array list of objects. The object represent the row content, e.g. Person. The Person class then has setter/getter for each of the properties that you want to show in a column
    Frank

  • Creating Tables From a Master Table?

    Hi all,
    I am trying to create tables that are generated from a master table. The reason behind this is I want to easily be able to modify this master table and then be able to print a well laid out invoice without all the extraneous information. I'm not really explaining this well so here is an example.
    My Master Table is on it's own sheet and has a categorized listing of products like so:
    Fruit
    Bananas, 5 units, $1.00
    Apples, 3 units, $0.50
    Peaches, 0 units, $2.00
    Grains
    Bread, 0 units, $1.00
    Oatmeal, 0 units, $2.00
    Vegetables
    Lettuce, 4 units, $2.00
    Celery, 6 units, $1.50
    Carrots, 2 units, $3.50
    On a seperate invoice sheet I would have multiple tables laid out to print. It will have a summary table like this:
    Summary
    Fruit, Subtotal $6.50
    Vegetables, Subtotal $24.00
    Total $30.50
    and seperate tables for each category:
    Fruit
    Bananas, 5 units, $1.00
    Apples, 3 units, $0.50
    Subtotal $6.50
    Vegetables
    Lettuce, 4 units, $2.00
    Celery, 6 units, $1.50
    Carrots, 2 units, $3.50
    Subtotal $24.00
    Notice it does not include the peaches or grains since I didn't actually sell any units of those.
    Is this possible? Can anyone point me in the right direction? Thanks.

    Most of this looks possible. The most obvious exception is not showing the separate table for grains when no grains are shown.
    A table has a defined number of rows and columns. That number may be changed manually, but I know no way of either adding or removing rows (or columns) through the use of formulas. If you want to use separate tables for each of these, you will need to set up four separate tables, each with the number of columns needed and, assuming there is a possibility that any particular order may include all items in at least one category, each with as many rows as there are items in the category for that table.
    If you are willing to forego separate tables on the Invoice, then an outcome similar to what you ask is likely possible.
    In your example, you have listed the subtotals for each category in which there has been an order at the top of the page, then have repeated those subtotals in a second line in each separate table. Why?
    Regards,
    Barry

  • Create table from user scott

    Hi,
    Can you help me with this?
    I wrote this
    {declare
    cursor c1 is
    select *
    from
    all_objects
    where lower(owner) like 'scott'
    and lower(object_type)='table';
    i varchar2(50);
    begin
    for i in c1
    loop
    execute immediate 'create table '||i.object_name|| ' as select *
    from ' ||i.object_name;
    end loop;
    close c1;
    end;
    and I have the following errors:
    ERROR at line 1:
    ORA-00942: table or view does not exist
    ORA-06512: at line 12
    Thank you

    Could you please show output of your generated code using dbms_output.put_line command?
    declare
    cursor c1 is
    select *
    from
    all_objects
    where lower(owner) like 'scott'
    and lower(object_type)='table';
    i varchar2(50);
    begin
    for i in c1
    loop
    dbms_output.put_line('create table '||i.object_name|| ' as select *
    from ' ||i.object_name);
    end loop;
    close c1;
    end;
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com

  • How to see DDL script(create table) from view

    i want to view create table script(DDL command)
    can u suggest me any view for that.

    Hi
    There's no view where the DDL statement is directly available. It must be reconstructed from many views...
    If you use 9i the simpler way to do that is with DBMS_METADATA. Below and example....
    SQL&gt; SET LONG 1000000
    SQL&gt; SELECT dbms_metadata.get_ddl('TABLE','EMP') FROM dual;
    DBMS_METADATA.GET_DDL('TABLE','EMP')
    CREATE TABLE "SCOTT"."EMP"
    ( "EMPNO" NUMBER(4,0) NOT NULL ENABLE,
    "ENAME" VARCHAR2(10),
    "JOB" VARCHAR2(9),
    "MGR" NUMBER(4,0),
    "HIREDATE" DATE,
    "SAL" NUMBER(7,2),
    "COMM" NUMBER(7,2),
    "DEPTNO" NUMBER(2,0),
    CONSTRAINT "EMP_PK" PRIMARY KEY ("EMPNO")
    USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS" ENABLE,
    CONSTRAINT "EMP_DEPT_FK" FOREIGN KEY ("DEPTNO")
    REFERENCES "SCOTT"."DEPT" ("DEPTNO") ENABLE
    ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS"
    Chris

  • Create table from view giving error

    i am trying to creating a table from view it is giving following error. can you please help
    create table jd as
    select * from A.ab_v where 1=2;
    error
    ORA-01723
    zero columns not allowed

    As others already pointed out you have NULL as view column(s). You need to either modify view and use CAST(NULL AS desired-type). For example:
    SQL> create or replace
      2    view v1
      3      as
      4        select  null new_date
      5          from dual
      6  /
    View created.
    SQL> create table tbl
      2    as
      3      select  *
      4        from  v1
      5  /
        select  *
    ERROR at line 3:
    ORA-01723: zero-length columns are not allowed
    SQL> create or replace
      2    view v1
      3      as
      4        select  cast(null as date) new_date
      5          from dual
      6  /
    View created.
    SQL> create table tbl
      2    as
      3      select  *
      4        from  v1
      5  /
    Table created.
    SQL> drop table tbl
      2  /
    Table dropped.
    SQL> create or replace
      2    view v1
      3      as
      4        select  cast(null as number) new_number
      5          from  dual
      6  /
    View created.
    SQL> create table tbl
      2    as
      3      select  *
      4        from  v1
      5  /
    Table created.
    SQL>  Or list individual view columns with NULL CASTing in CTAS:
    SQL> create or replace
      2    view v1
      3      as
      4        select  null new_date
      5          from dual
      6  /
    View created.
    SQL> create table tbl
      2     as
      3       select  cast(new_date as date) new_date
      4         from  v1
      5  /
    Table created.
    SQL> desc tbl
    Name                                      Null?    Type
    NEW_DATE                                           DATE
    SQL> set null NULL
    SQL> select  *
      2    from  tbl
      3  /
    NEW_DATE
    NULL
    SQL> SY.

  • Creating Table from Multiple Colon Separated Values

    I have a DB table with a field that stores values that may be colon separated as resulting from a checkbox page item.
    1:2
    3:4
    5:6
    My ultimate goal is to turn those values into a table of singular values.
    1
    2
    3
    4
    5
    6
    I've gotten close, but can't figure out how to finish the last step. My first step was to create a single query that concatenated all values into one long string. I am able to get
    1:2:3:4:5:6
    as a result of using the LISTAGG function in the query. My next step was to use a function, STRTAB, that I sourced from this forum to convert the colon delimited string into a result set using the query:
    select * from table( strtab( '1:2:3:4:5:6' ))
    where the string was derived from the LISTAGG query. The query works when I pass the above string, but if I try to insert the actual LISTAGG query it fails with missing expression. My actual query looks like this:
    select * from table( strtab(
    select listagg( RESTRICTED, ':' ) WITHIN GROUP ( order by RESTRICTED ) as ID
    from SZ_LINKED_PROFILES
    where RESTRICTED is not null
    and PROFILE in ( select ID
    from SZ_PROFILES
    where ACCOUNT = :APP_ACCOUNT )))
    Anyone know how I can complete the last step? I know I can do this with pl/sql, but I need this to be a single query as I'm using it as the criteria in an IN expression of a larger query.
    Thanks in advance for your help!
    -Jeff

    Hi
    This should be a lot quicker than using piplelined functions (or any PL/SQL for that matter)...
    CREATE TABLE str2tbl
    AS SELECT '1:2' str
       FROM dual
       UNION ALL
       SELECT '3:4'
       FROM dual
       UNION ALL
       SELECT '5:6'
       FROM dual;
    WITH t_str AS
    SELECT  str||':'                                     AS str,
             (LENGTH(str) - LENGTH(REPLACE(str,':'))) + 1 AS no_of_elements
    FROM    str2tbl
    ),   t_n_rows AS
    SELECT  LEVEL AS i
    FROM    dual
    CONNECT BY LEVEL <= (SELECT SUM(no_of_elements) FROM t_str)
    SELECT RTRIM(str,':')                               AS original_string,
           SUBSTR(str,start_pos,(next_pos - start_pos)) AS single_element,
           element_no
    FROM   (
            SELECT t_str.str,
                   nt.i AS element_no,
                   INSTR(t_str.str,':',DECODE(nt.i,1,0,1),
                                       DECODE(nt.i,1,1,nt.i - 1)) + 1 AS start_pos,
                   INSTR(t_str.str,':',1,DECODE(nt.i,1,1,nt.i))       AS next_pos
            FROM   t_str JOIN t_n_rows nt
                           ON nt.i <= t_str.no_of_elements
    ORDER BY 1, 3;
    Table created.
    ORIG SINGLE_ELEME ELEMENT_NO
    1:2  1                     1
    1:2  2                     2
    3:4  3                     1
    3:4  4                     2
    5:6  5                     1
    5:6  6                     2
    6 rows selected.?
    Cheers
    Ben

  • Create Table from XML Data

    XML info: D:\XMLDATA\mytable.xml
    create directory XML_dir as 'D:\XMLDATA';
    <INFO>
    <Column_Name>Col1</Column_Name>
    <Data_Type>Char(1)</Data_Type>
    </INFO>
    <INFO>
    <Column_Name>Col2</Column_Name>
    <Data_Type>VARCHAR2(50)</Data_Type>
    </INFO>
    I need to create a table based on the XML data.
    Create Table mytable
    Col1 Char(1),
    Col2 Varchar2(50)
    How to read and execute the xml data to create a table.
    Thanks!    

    Something like this :
    SQL> declare
      2 
      3    v_xmlinfo      clob;
      4    v_ddl          varchar2(32767) := 'CREATE TABLE mytable ( #COLUMN_LIST# )';
      5    v_column_list  varchar2(4000);
      6 
      7  begin
      8 
      9    v_xmlinfo := dbms_xslprocessor.read2clob('TEST_DIR', 'info.xml');
    10 
    11    select column_list
    12    into v_column_list
    13    from xmltable(
    14           'string-join(
    15              for $i in /INFO
    16              return concat($i/Column_Name, " ", $i/Data_Type)
    17            , ", "
    18            )'
    19           passing xmlparse(content v_xmlinfo)
    20           columns column_list varchar2(4000) path '.'
    21         ) ;
    22 
    23 
    24    v_ddl := replace(v_ddl, '#COLUMN_LIST#', v_column_list);
    25    --dbms_output.put_line(v_ddl);
    26 
    27    execute immediate v_ddl;
    28 
    29  end;
    30  /
    PL/SQL procedure successfully completed
    SQL> select * from mytable;
    COL1 COL2

Maybe you are looking for

  • Itunes will not recognize my ipod and now it is frozen. what do i do?, itunes will not recognize my ipod and now it is frozen. what do i do?

    The past few days when i connect my iPod to my computer it gets frozen and wont connect to itunes. my computer doesnt even recognize my iPod is connected but it has to be the Ipod because all my other divices are workin with my computer. what do i do

  • What's wrong with my NVRAM

    please could anyone help me? - kt3 ultra mainboard, RAM 512 MB PC 2700, and Athlon XP 1800. - 2 Harddrive - 2 optical drive. 1 is a CD-ROM and the other is CD writer - ATI Radeon 9500 - PSU 350W i think there's something wrong with my NVRAM or BIOS.

  • Putting a ruler in an image

    Hi forum, Does anyone know how to put a scale/ruler in an image? I do macro and would like to show the size of my objects with a ruler. Koen

  • IPhone 6+ Controls Itself..?

    Hi! In December, I received and iPhone 6+ for Christmas. It was a really expensive gift, and it's frustrating that I'm already having a major problem with it. Everything that I try to do on my phone is interrupted! It operates on iOS 8.1.2, which I'v

  • [SOLVED] KDE 4.8 crash!

    Hi! Yesterday, I updated my system, and installed the KDE 4.8. Today, when I started my computer, the KDE was with a grey wallpaper and big red squares, showing that the widgets was crashed too. I couldn't take screenshots, but I took some photos to