Create Table As select from a PLSQL Package

Hello

I'm trying to use an Assignment statement in a stored procedure using Execute Immediate.

I first create the script in a variable:

v_sql: = 'CREATE TABLE ' | v_archive_partition_name |
"TABLESPACE TBS_ARCHIVE |
"STORAGE (INITIAL 20 M) |
"AS COMPRESS |
' SELECT *' |. '
'FROM ' | v_table_name |
«PARTITION (' |)» v_archive_partition_name | ' ) ' ||
"ORDER BY". v_sort_order | '';

Then I run:

EXECUTE IMMEDIATE v_sql;

When I run the present, I get an error of incorrect permissions, but if I run the SQL that is created manually by using the same user it creates the table correctly.

Can someone tell me what grants should I apply for my procedure create this table correctly?

Can someone tell me what grants should I apply for my procedure create this table correctly?

acquired through ROLE privileges do not apply in the PL/SQL procedure named.
GRANT must be explicitly made

IMO, application should NOT do the DOF between application version releases.

Tags: Database

Similar Questions

  • Create the table in select * from the other table

    DB: 11.2.0.2

    How to create a table with structure only not empty the data that we do not generally create table in select * from... But the command will pull the data also. How to create without data?

    create table foo
    in select * bar
    where 1 = 0

  • create table as select or parallel table / * + parllel() * /.

    Dear Experts,


    I have two huge table almost 300 GB each.
    create table as 
    select * from table t1 ,t2
    where t1.row_id=t2.row_id
    How to run this query in parllelism. Withou Parlell, it takes too much time.

    as it should be
    create table parallel 15 as 
    select * from t1,t2;
    or in another way

    and if it was it y 3 table to join to

    My * wrote:
    Dear Experts,

    I have two huge table almost 300 GB each.

    create table as
    select * from table t1 ,t2
    where t1.row_id=t2.row_id
    

    How to run this query in parllelism. Withou Parlell, it takes too much time.

    as it should be

    create table parallel 15 as
    select * from t1,t2;
    

    or in another way

    and if it was it y 3 table to join to

    What happens if the slowdown occurs on SELECT it & not create?

  • Create table as select execution Issues

    I have a table that is 190 million lines (TableA). The database is on the storage of very old and slow. I'll try the following: create table TableB in the select * from TableA where field1 < 10000 [this should translate into about 36 million lines for the new table]

    The problem is: I started this work at 20:00 and 02:00 is still not create the table. My thoughts are that it accumulates the lines into a temporary table, initially based on the where clause and then it goes to create the table. fix? That being said, the customer has a problem with the execution of this request during the opening hours, BUT it does start in writing during the outage window (20:00-02:00) and, in fact, I never get to this point. In fact, the early stages making the ETG is not this CPU intensive, I should be able to start the ETG before 20:00 without too much grumbling and I hope that the part of writing occurs during the window [i.e.: start the ETG at 14:00]. Is there a way to determine how long a DEC will take before you actually create the table?

    Anyone know if I'm wrong about the way that Oracle treats this type of DEC?

    Thank you

    To speed up the DEC options

    (1) NOLOGGING
    (2) PARALLEL

    http://download.Oracle.com/docs/CD/E11882_01/server.112/e25523/parallel003.htm#BEIFIDIE

    How useful PARALLEL might be depends on your environment (in particular, the number of processors).

    Werner

  • Create Table As Select Select

    Table_2
    ----------------------

    CREATE TABLE TABLE_2
    (
    'ID' VARCHAR2 (10),
    VARCHAR2 (10) "OFF."
    "SEQ" NUMBER (10)
    );

    Inserts
    ---------------------
    INSERT IN TABLE_2 (ID, EXCL, SEQ) VALUES ('123456', ", 1);
    INSERT IN TABLE_2 (ID, EXCL, SEQ) VALUES ('123456', 'EX', 2);
    INSERT IN TABLE_2 (ID, EXCL, SEQ) VALUES ('123456', ", 3);
    INSERT IN TABLE_2 (ID, EXCL, SEQ) VALUES ('321654' ", 4);
    INSERT IN TABLE_2 (ID, EXCL, SEQ) VALUES ('123798', 'EX', 5);
    INSERT IN TABLE_2 (ID, EXCL, SEQ) VALUES ('123785' ", 6);
    INSERT IN TABLE_2 (ID, EXCL, SEQ) VALUES ('654787', ", 7);
    INSERT IN TABLE_2 (ID, EXCL, SEQ) VALUES ('654787', ", 8);
    INSERT IN TABLE_2 (ID, EXCL, SEQ) VALUES ('654787', ", 9);
    INSERT IN TABLE_2 (ID, EXCL, SEQ) VALUES ('985217', 'EX', 10);
    INSERT IN TABLE_2 (ID, EXCL, SEQ) VALUES ('985217', ", 11);
    INSERT IN TABLE_2 (ID, EXCL, SEQ) VALUES ('937158' ", 12);
    INSERT IN TABLE_2 (ID, EXCL, SEQ) VALUES ('937158' ", 13);

    Select *.
    ------------------------
    EXCL SEQ ID
    1 123456
    123456 EX 2
    3 123456
    321654 4
    123798 EX 5
    123785 6
    654787 7
    654787 8
    654787 9
    985217 EX 10
    985217 11
    937158 12
    937158 13






    I need to create a table based on for all records that are not null - EXC, but I need to bring through all the records that have the same ID as the EXC not null field.

    Desired output: -.
    ------------------

    EXCL SEQ ID
    1 123456
    123456 EX 2
    3 123456
    123798 EX 5
    985217 EX 10
    985217 11

    The ideas people?

    Hello

    Here's one way:

    CREATE     TABLE     table_x
    AS
    SELECT     *
    FROM     table_2
    WHERE     id     IN (
                     SELECT  id
                     FROM    table_2
                     WHERE   excl     IS NOT NULL
                 )
    ;
    

    Furthermore, whenever you post the text formatted (for example, the results of the query) on this site, type the 6 characters:

    \

    (small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    You'll get better answers quicker if people can read:
    

    EXCL SEQ ID
    1 123456
    123456 EX 2
    3 123456
    123798 EX 5
    985217 EX 10
    985217 11

    (for example) rather than
    
    

    Deeds_2001 wrote:
    ...
    ID EXCL SEQ
    123456 1
    123456 EX 2
    123456 3
    123798 EX 5
    985217 EX 10
    985217 11

    		   
  • Specify the type of data when using the "CREATE TABLE AS SELECT"?

    In the table creation code I'm trying to create a DATE column called DOB below. However, the resulting DOB column in the condamnes2 table is a Varchar2. How can I specify that I want to be a DATE field DOB? (I know that I can create the structure first and then fill it but this isn't what I want.)

    create the table condamnes2
    SELECT Person_ID,
    decode (year of BIRTH, null, null, to_date (nvl(BIRTHMONTH,1) |)) » /'|| NVL(Birthday,1) | » /'|| NVL (BIRTHYEAR, 1500), ' MM/DD/YYYY')) DOB
    Among the people

    Thank you

    Use the CAST function in your decoding:

    SQL> create table Persons2 as
      2  SELECT Person_ID,
      3         decode(BIRTHYEAR
      4               ,null, cast(null as date)
      5               ,to_date(nvl(BIRTHMONTH,1)||'/'||nvl(birthday,1)||'/'||nvl(BIRTHYEAR,1500),'MM/DD/YYYY')) DOB
      6  from   persons
      7  ;
    
    Table created.
    
    SQL> desc persons2
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     PERSON_ID                                          NUMBER
     DOB                                                DATE
    
  • Create table in Select...

    Hi all

    I need to run the statement below create a PL SQL, but his return from a mistake. Can someone help on the same.

    sqlstmt: = ' create table f0006_new in select * from f0006 where mcrp02 in ('PAV","OTH")';
    run immediately sqlstmt;

    Error: ORA-00904: "OTH" is not a valid identifier

    Thank you
    Amit.

    Instead of using the quotes to quote your list, use two single quotes:

    this
    (''PAV'',''OTH'')
    not this
    ("PAV","OTH")
    
  • create table as select the number of lines

    Hi s/n,.

    IM using create table select this option to copy the table of which 400 million rows.is there anyway to watch how many lines it is actually processing (copied) as we do by using a query in import.

    You can see if there is something in v$ session_longops.

    You can also monitor the space consumed as dba_segments or dba_extents.

  • Problem with create table as select (DEC)

    Hello

    We try to data cleaning of huge tables. And a customer of guise is reanme main table to the backup table. Then create a master table in select * backup table with some test.

    Now the problem with create table select, is that it creates the table without indexes and constraints. Is it possible to use the ETG (create the select table) with the same structure that he was the (all index, constriaints).

    Or any other solution to solve this problem?

    Thanks in advance

    Sweety wrote:
    Hello

    We try to data cleaning of huge tables. And a customer of guise is reanme main table to the backup table. Then create a master table in select * backup table with some test.

    Now the problem with create table select, is that it creates the table without indexes and constraints. Is it possible to use the ETG (create the select table) with the same structure that he was the (all index, constriaints).

    Or any other solution to solve this problem?

    Thanks in advance

    No, this is not possible. You need to get the manuscript of dependent object and create it manually.

  • Create table as select statement (ETG) takes a long time.

    Hi all

    One of my procedure launched a table create as select statement each month.
    Usually it ends in 20 minutes. for 6172063 records and 1 hour in 13699067.
    But this time it never even takes to 38076 records.
    When I checked everything he does is the CPU usage. No e/s.
    I did a count (*) using the query, it has brought very good results.
    BUT guard going on DEC.
    I use Oracle 10.2.0.4.
    temp_ip of the main table has 38076
    table nhs_opcs_hier has 26769 records.
    and table nhs_icd10_hier 49551 records.
    -------------------
    Query is:
    create the table analytic_hes.temp_ip_hier as
    Select b.*, (select nvl (max (hierarchy), 0))
    of ref_hd.nhs_opcs_hier one
    where fiscal_year = b.hd_spell_fiscal_year
    and a.code in
    (primary_PROCEDURE, secondary_procedure_1, secondary_procedure_2,
    secondary_procedure_3, secondary_procedure_4, secondary_procedure_5,
    secondary_procedure_6, secondary_procedure_7, secondary_procedure_8,
    secondary_procedure_9, secondary_procedure_10,
    secondary_procedure_11, secondary_procedure_12)) as hd_procedure_hierarchy,
    (select nvl (max (hierarchy), 0) for ref_hd.nhs_icd10_hier one)
    where fiscal_year = b.hd_spell_fiscal_year
    and a.code in
    (primary_diagnosis, secondary_diagnosis_1,
    secondary_diagnosis_2, secondary_diagnosis_3,
    secondary_diagnosis_4, secondary_diagnosis_5,
    secondary_diagnosis_6, secondary_diagnosis_7,
    secondary_diagnosis_8, secondary_diagnosis_9,
    secondary_diagnosis_10, secondary_diagnosis_11,
    secondary_diagnosis_12, secondary_diagnosis_13,
    secondary_diagnosis_14)) as hd_diagnosis_hierarchy
    of analytic_hes.temp_ip b
    -----------------

    Any help would be greatly appreciated

    Hello

    It is a bit of a wild card, I think because it will require 14 scans to fill the table temp_ip to unpivot codes diagnostic and procedure, so this lilkely things are moving slower than the original. However, as it is a temporary table, I guess you could have some control over its structure, or at least be able to dismiss it and try something else. If you are able to change the structure of this table, you could make the application much simpler and probably much faster. I think that you need a list of codes of procedure for the year and a list of diagnosis for fiscal codes. I do this through the large list of UNION all THE INSTRUCTIONS, but you can have a more efficient way to do according to the base tables you are people temp_ip of. In any case, it's here (as far as I can tell this will do the same job)

    WITH codes AS
    (   SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            primary_PROCEDURE       procedure_code,
            primary_diagnosis       diagnosis_code,
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_1    procedure_code,
            secondary_diagnosis_1    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_2    procedure_code ,
            secondary_diagnosis_2    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_3    procedure_code,
            secondary_diagnosis_3    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_4    procedure_code,
            secondary_diagnosis_4    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_5    procedure_code,
            secondary_diagnosis_5    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_6    procedure_code,
            secondary_diagnosis_6    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_7    procedure_code,
            secondary_diagnosis_7    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_8    procedure_code,
            secondary_diagnosis_8    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_9    procedure_code,
            secondary_diagnosis_9    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_10  procedure_code,
            secondary_diagnosis_10    diagnosis_code
        FROM
            temp_ip
        UNION ALL
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_11  procedure_code,
            secondary_diagnosis_11    diagnosis_code
        FROM
            temp_ip
        SELECT
            bd.primary_key_column_s,
            hd_spell_fiscal_year,
            secondary_procedure_12  procedure_code,
            secondary_diagnosis_12    diagnosis_code
        FROM
            temp_ip
    ), hd_procedure_hierarchy AS
    (   SELECT
            NVL (MAX (a.hierarchy), 0) hd_procedure_hierarchy,
            a.fiscal_year
        FROM
            ref_hd.nhs_opcs_hier a,
            codes pc
        WHERE
            a.fiscal_year = pc.hd_spell_fiscal_year
        AND
            a.code = pc.procedure_code
        GROUP BY
            a.fiscal_year
    ),hd_diagnosis_hierarchy AS
    (   SELECT
            NVL (MAX (a.hierarchy), 0) hd_diagnosis_hierarchy,
            a.fiscal_year
        FROM
            ref_hd.nhs_icd10_hier a,
            codes pc
        WHERE
            a.fiscal_year = pc.hd_spell_fiscal_year
        AND
            a.code = pc.diagnosis_code
        GROUP BY
            a.fiscal_year
    )
    SELECT b.*, a.hd_procedure_hierarchy, c.hd_diagnosis_hierarchy
      FROM analytic_hes.temp_ip b,
           LEFT OUTER JOIN hd_procedure_hierarchy a
              ON (a.fiscal_year = b.hd_spell_fiscal_year)
           LEFT OUTER JOIN hd_diagnosis_hierarchy c
              ON (c.fiscal_year = b.hd_spell_fiscal_year)
    

    HTH

    David

  • syntax error in create table

    Could someone help me please as to what's wrong in the creation under the structure of the table:

    create table test (select * from schema.tablename where 1 = 2)
    TABLESPACE PCR_ARCHIVE_DATA_04
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE)
    64K INITIALS
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    PCTINCREASE 0
    DEFAULT USER_TABLES
    )
    NOLOGGING
    COMPRESS
    NOCACHE
    PARALLEL (INSTANCES OF 6 1 DEGREE)
    MONITORING;

    SELECT AS comes after the physical attributes, such as

    create table test TABLESPACE PCR_ARCHIVE_DATA_04
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    )
    NOLOGGING
    COMPRESS
    NOCACHE
    PARALLEL ( DEGREE 6 INSTANCES 1 )
    MONITORING
    as (select * from schema.tablename where 1=2)
    

    Best regards

    Maxim

  • create the table in SELECT (question)

    Hello

    In regards to create the table as subquery, I read that:

    The data type of column definitions and the NOT NULL constraint are passed to the new table. Note that only the explicit NOT NULL constraint is inherited. The PRIMARY KEY column will not function NOT NULL column null. Any other rule of constraint is not passed to the new table. However, you can add constraints in the column definition.

    Can someone explain to me how to do this? Or, how we need to specify the constraints (and also the default values for columns, because it is possible) for the columns in the column definition?

    In addition, I do not understand this: the PRIMARY KEY column will not function NOT NULL column zero.
    Can someone give me some small examples regarding these?
    For example, it generates an error:
    create table test1 (a, b, c default sysdate) 
    as 
    select 1, 'b' from dual
    Thank you!

    Edited by: Roger22 the 01.09.2011 11:37

    Hello

    When you set a primary key consists of a unique constraint and a constraint not null, but they are both implicit with the primary key. When you create the table because it will copy only the explicitly declared NOT NULL constraints so it isn't look upward than the implicit NOT NULL primary key.

    SQL> create table dt_pk
      2  (   id      number primary key,
      3      col1    number not null,
      4      col2    number
      5  )
      6  /
    
    Table created.
    
    SQL> desc dt_pk
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     ID                                        NOT NULL NUMBER
     COL1                                      NOT NULL NUMBER
     COL2                                               NUMBER
    
    SQL> create table dt_pk2 as select * from dt_pk;
    
    Table created.
    
    SQL> desc dt_pk2;
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     ID                                                 NUMBER
     COL1                                      NOT NULL NUMBER
     COL2                                               NUMBER
    
    SQL> select constraint_name,constraint_type from user_constraints where table_name='DT_PK'
      2  /
    
    CONSTRAINT_NAME                C
    ------------------------------ -
    SYS_C006935772                 C
    SYS_C006935773                 P
    
    SQL> select constraint_name,constraint_type from user_constraints where table_name='DT_PK2'
      2  /
    
    CONSTRAINT_NAME                C
    ------------------------------ -
    SYS_C006935774                 C
    

    However, a primary key can reuse existing constraints and indexes instead of declaring new. For example, we can explicitly declare a constraint not null on the column id and then create a primary key. This means that we will now inherit the constraint not null in the ETG, as it has been explicitly declared and is a constraint separate in there own right that has been 'borrowed' by the pk constraint.

    SQL> create table dt_pk3 (id number not null, col1 number not null, col2 number);
    
    Table created.
    
    SQL> alter table dt_pk3 add constraint dt_pk3_pk primary key (id);
    
    Table altered.
    
    SQL> select constraint_name,constraint_type from user_constraints where table_name='DT_PK3'
      2  /
    
    CONSTRAINT_NAME                C
    ------------------------------ -
    SYS_C006935775                 C
    SYS_C006935776                 C
    DT_PK3_PK                      P
    
    SQL> create table dt_pk4 as select * from dt_pk3;
    
    Table created.
    
    SQL> desc dt_pk3;
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     ID                                        NOT NULL NUMBER
     COL1                                      NOT NULL NUMBER
     COL2                                               NUMBER
    
    SQL> desc dt_pk4;
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     ID                                        NOT NULL NUMBER
     COL1                                      NOT NULL NUMBER
     COL2                                               NUMBER 
    

    Regarding the definition of the default values, you must always specify the column in the select, but doing so means follow you the semantics of a default in a standard INSERT statement, i.e. you specified the column, you must provide a value, in which case even if the value is null, the default value will not be used. However, the new inserted rows where the column with the default value is not specified will revert to the default.

    SQL> create table test1 (a, b, c default sysdate)
      2  as
      3  select 1, 'b' from dual
      4  /
    create table test1 (a, b, c default sysdate)
                        *
    ERROR at line 1:
    ORA-01730: invalid number of column names specified
    
    SQL> create table test1 (a, b, c default sysdate)
      2  as
      3  select 1, 'b', null c from dual
      4  /
    select 1, 'b', null c from dual
                   *
    ERROR at line 3:
    ORA-01723: zero-length columns are not allowed
    
    SQL> create table test1 (a, b, c default sysdate)
      2  as
      3  select 1, 'b', cast(null as date) c from dual
      4  /
    
    Table created.
    
    SQL> select * from test1;
    
             A B C
    ---------- - ---------
             1 b
    
    SQL> insert into test1(a,b) values(2,'b');
    
    1 row created.
    
    SQL> select * from test1;
    
             A B C
    ---------- - ---------
             1 b
             2 b 01-SEP-11
    

    To create a constraint, you must list all columns without the data types and constraints list online.

    SQL> create table dt_cons (id number, col1 number, col2 number, constraint chk2 check(col2 IS NULL or col2>10))
      2  as select * from dt_pk3
      3  /
    create table dt_cons (id number, col1 number, col2 number, constraint chk2 check(col2 IS NULL or col2>10))
                          *
    ERROR at line 1:
    ORA-01773: may not specify column datatypes in this CREATE TABLE
    
    SQL> create table dt_cons (constraint chk2 check(col2 IS NULL or col2>10))
      2  as select * from dt_pk3
      3  /
    create table dt_cons (constraint chk2 check(col2 IS NULL or col2>10))
                         *
    ERROR at line 1:
    ORA-00904: : invalid identifier
    
    SQL> create table dt_cons (col2 constraint chk2 check(col2 IS NULL or col2>10))
      2  as select * from dt_pk3
      3  /
    create table dt_cons (col2 constraint chk2 check(col2 IS NULL or col2>10))
                          *
    ERROR at line 1:
    ORA-01730: invalid number of column names specified
    
    SQL> create table dt_cons (id,col1,col2 constraint chk2 check(col2 IS NULL or col2>10))
      2  as select * from dt_pk3
      3  /
    
    Table created.
    
    SQL> desc dt_cons
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     ID                                        NOT NULL NUMBER
     COL1                                      NOT NULL NUMBER
     COL2                                               NUMBER
    
    SQL> insert into dt_cons values(2,2,2);
    insert into dt_cons values(2,2,2)
    *
    ERROR at line 1:
    ORA-02290: check constraint (JJACOB_APP.CHK2) violated
    
    SQL> insert into dt_cons values(2,2,10);
    insert into dt_cons values(2,2,10)
    *
    ERROR at line 1:
    ORA-02290: check constraint (JJACOB_APP.CHK2) violated
    
    SQL> insert into dt_cons values(2,2,11);
    
    1 row created.
    
    SQL> insert into dt_cons values(2,2,null);
    
    1 row created.
    
    SQL>
    

    HTH

    David

  • Having trouble selecting from a table function

    Need a function to return an array in the following format:
    WEEK_NBR               START_DATE END_DATE  
    ---------------------- ---------- --------- 
    0                      29-JAN-09  25-NOV-09 
    1                      26-NOV-09  02-DEC-09 
    2                      03-DEC-09  09-DEC-09 
    3                      10-DEC-09  16-DEC-09 
    6                      26-NOV-09  16-DEC-09 
    7                      29-JAN-09  16-DEC-09 
    The following error after the selection of a function that returns the table:
    select * from table(get_cwsr_ranges)
    Error from the 1 in the command line:
    Select * from table (get_cwsr_ranges)
    Error report:
    SQL error: ORA-06504: PL/SQL: return variables of the game results or the query types do not match
    ORA-06512: at "GET_CWSR_RANGES", line 23
    06504 00000 - "PL/SQL: return of the variable result set or query types do not match.
    * Cause: Numbers or types of columns in a query is not declared
    return type of a variable result is defined or declared two result types
    Set of variables do not match.
    * Action: Change the program or the declaration statement. Verify that the query variable
    actually we want during execution.
    >

    DDL:
    CREATE TYPE typ_date_range AS OBJECT
           (week_nbr                number,
            start_date              date,
            end_date                date   
          );
    /
    
     CREATE TYPE typ_tbl_date_ranges AS TABLE OF typ_date_range;
    /
    
    
    CREATE OR REPLACE FUNCTION get_cwsr_ranges()
    RETURN typ_tbl_date_ranges PIPELINED IS
    v_dates_table  typ_tbl_date_ranges;
    
    p_cursor     sys_refcursor;
    rec  typ_date_range := typ_date_range(NULL,NULL,NULL); 
    
    BEGIN
           
         open p_cursor for
         with sample_data as 
         (
             select 0 as  week_nbr , '29-JAN-09' as  start_date , '25-NOV-09' as end_date from dual union all                                         
             select 1 as  week_nbr , '26-NOV-09' as  start_date , '02-DEC-09' as end_date from dual union all                                         
             select 2 as  week_nbr , '03-DEC-09' as  start_date , '09-DEC-09' as end_date from dual union all                                         
             select 3 as  week_nbr , '10-DEC-09' as  start_date , '16-DEC-09' as end_date from dual union all                                         
             select 6 as  week_nbr , '26-NOV-09' as  start_date , '16-DEC-09' as end_date from dual union all                                         
             select 7 as  week_nbr , '29-JAN-09' as  start_date , '16-DEC-09' as end_date from dual  
       )
       select * 
       from sample_data;
        
    LOOP
        FETCH p_cursor INTO rec;
        EXIT WHEN p_cursor%NOTFOUND;
        PIPE ROW(Rec);
    END LOOP;
    CLOSE p_cursor;
    RETURN;
    
    END get_CWSR_Ranges;
    Any suggestions?
    create or replace FUNCTION get_cwsr_ranges
    RETURN typ_tbl_date_ranges PIPELINED
    IS
    
    BEGIN
    
      for rec in
      (
         with sample_data as
         (
             select 0 as  week_nbr , to_date('29-JAN-09', 'dd-mon-yy') as  start_date , to_date('25-NOV-09', 'dd-mon-yy') as end_date from dual union all
             select 1 as  week_nbr , to_date('26-NOV-09', 'dd-mon-yy') as  start_date , to_date('02-DEC-09', 'dd-mon-yy') as end_date from dual union all
             select 2 as  week_nbr , to_date('03-DEC-09', 'dd-mon-yy') as  start_date , to_date('09-DEC-09', 'dd-mon-yy') as end_date from dual union all
             select 3 as  week_nbr , to_date('10-DEC-09', 'dd-mon-yy') as  start_date , to_date('16-DEC-09', 'dd-mon-yy') as end_date from dual union all
             select 6 as  week_nbr , to_date('26-NOV-09', 'dd-mon-yy') as  start_date , to_date('16-DEC-09', 'dd-mon-yy') as end_date from dual union all
             select 7 as  week_nbr , to_date('29-JAN-09', 'dd-mon-yy') as  start_date , to_date('16-DEC-09', 'dd-mon-yy') as end_date from dual
        )
       select typ_date_range(week_nbr, start_date, end_date) the_type
       from sample_data
      )
      loop
        pipe row (rec.the_type);
      end loop;
    
    END get_CWSR_Ranges;
    

    and then...

    select *
    from table(cast(get_cwsr_ranges as typ_tbl_date_ranges))
    

    Published by: Tubby on December 26, 2009 19:05

    Remove the implicit conversion using explicit TO_DATE... you should always do :)

  • Select from another table, when the query returns no result

    Hello

    I have a question where I'm supposed to retrieve the address of an account id-based billing. However, the table of billing may not have an address. There is a table of addresses that always has an address for an account. If the billing address exists, it should be used, so I can't use the address table. Is it possible in a select statement to query to the billing address and if it does not exist, use the address table.

    SELECT * FROM accounts a, b billings WHERE a.accountid = b.accountid

    Any help will be greatly appreciated.

    Thank you.

    user10407139 wrote:
    Hello

    I have a question where I'm supposed to retrieve the address of an account id-based billing. However, the table of billing may not have an address. There is a table of addresses that always has an address for an account. If the billing address exists, it should be used, so I can't use the address table. Is it possible in a select statement to query to the billing address and if it does not exist, use the address table.

    SELECT * FROM accounts a, b billings WHERE a.accountid = b.accountid

    Any help will be greatly appreciated.

    I think you need to explain more clearly if

    -you only have a couple of "billing" columns which is empty and in this case, you want to use the columns from the table 'accounts '.

    - or you have a join with another table that doesn't return data, for example a foreign key "address_id" "billing" is zero and therefore the join to other tables 'address' will return all the data

    In the first case, you have already been provided with some examples here, how to use NVL or similar functions to achieve, even if the first post first evaluates the information of 'accounts' and if it is white using information from "billing". According to your description you need the other way around. The second post a subquery recursive useless in my opinion.

    In the latter case, you should probably use an "outer" join so that the data in your table "bills" are returned, even if the join to another table is not at all the lines.

    SELECT
    NVL(AD1.ADDRESS_ATTR1, AD2.ADDRESS_ATTR1) as ADDRESS_ATTR1,
    NVL(AD1.ADDRESS_ATTR2, AD2.ADDRESS_ATTR2) as ADDRESS_ATTR2,
    NVL(AD1.ADDRESS_STREET, AD2.ADDRESS_STREET) as ADDRESS_STREET,
    ...
    FROM accounts a
    INNER JOIN billings b
    ON a.accountid = b.accountid
    LEFT OUTER JOIN address ad1
    ON b.address_id = ad1.address_id
    INNER JOIN address ad2
    ON a.address_id = ad2.address_id;
    

    In this way you pick up the address stored in the "invoices" table, if it existed, otherwise you pick up the address assigned to the "accounts" table I used an inner for the second address join join because you said that the account always has an assigned address.

    Kind regards
    Randolf

    Oracle related blog stuff:
    http://Oracle-Randolf.blogspot.com/

    SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676 /.
    http://sourceforge.NET/projects/SQLT-pp/

  • confusion on the clause nologging - for create table

    Hi guys,.

    just 1 simple question.

    T1) when I create a table with no record, is the CREATION of the table not connected as well?


    Kind regards
    Noob

    OracleWannabe wrote:
    T1) when I create a table with no record, is the CREATION of the table not connected as well?

    If the table is created empty (as do not use a create table as select or DEC) then there is no difference in the design stage. The difference between REGISTRATION and NOLOGGING intervenes for direct path operations.

    The Oracle documentation provides a very good explanation:
    http://download.Oracle.com/docs/CD/B28359_01/server.111/b28313/usingpe.htm#i1009116

    Kind regards
    Greg Rahn
    http://structureddata.org

Maybe you are looking for