Exception No_data_found to insert into... select statement

Hai,
I have a doubt in plsql exceptions. In the sub program mentioned plsql.

Start

insert into select abc * xyz a, b of cdf where a.c1 = b.c2;

exception
When no_data_found then
do some operations

end;

In the pl/sql block above, if the select statement returns no rows, whether or not the exception is triggered? If not, how do the same. Any available alternative.

Thanks in advance.

Concerning
Sridhar

You would get an error no_data_found triggered at that time there, because it's perfectly valid to insert rows 0.

You will need to check SQL ROWCOUNT % and raise the no_data_found if it is equal to 0.

Tags: Database

Similar Questions

  • How to INSERT a SELECT statement with a GROUP BY clause on a table with an IDENTITY column?

    n an application, I intend to truncate and insertion on a 12 c Oracle database, but have found this problem with a IDENTITY column. Even if the INSERT... SELECT statement works on most SELECT uses I tried, if this statement was also a GROUP BY clause, it does not work, delivering a "ORA-00979: not a GROUP BY expression ' complaint. Some examples of code:

    create table aux ( owner_name varchar2(20), pet varchar2(20) ); 

    insert into aux values ('Scott', 'dog');

    insert into aux values ('Mike', 'dog');

    insert into aux values ('Mike', 'cat');

    insert into aux values ('John', 'turtle'); 


    create table T1 (

    id number generated always as identity,

    owner_name varchar2(20),

    pet_count number );

    select owner_name, count(*) as pet_count from aux group by owner_name; -- works just fine

    insert into T1 (owner_name, pet_count) select owner_name, count(*) as pet_count from aux group by owner_name; -- doesn't work

    The select statement works by itself, but it fails as an INSERT... SELECT statement.

    Appreciate the help!

    Looks like a bug. You must open the SR with Oracle. Meanwhile, you could materialize select:

    SQL > insert into T1 (owner_name, pet_count)
    2 with t as (select / * + materialize * / owner_name, count (*) as pet_count to the owner_name group)
    3. Select owner_name, pet_count t
    4.

    3 lines were created.

    SQL > select * from t1;

    ID OWNER_NAME PET_COUNT
    ---------- -------------------- ----------
    1 John                          1
    Scott 2 1
    3 Mike                          2

    SQL >

    Keep in mind index THAT MATERIALIZE is undocumented.

    SY.

  • issue: sql insert into select

    which is wrong with this query?

    insert into m_payment_option (p_type, m_fulfillment)

    values ('DIRECT_DEBIT', (select id from M_FULFILLMENT whose id not in (select m_fulfillment from M_PAYMENT_OPTION)));

    SQL-Fehler: ORA-01427: Unterabfrage fur eine liefert mehr als eine line line

    01427 00000 - "einreihig subquery returns several lines.

    the subquery returns:

    SELECT id from M_FULFILLMENT whose id not in (select m_fulfillment from M_PAYMENT_OPTION)

    47113

    47182

    47183

    ..

    Hallo,

    Try this

    insert into m_payment_option (p_type,m_fulfillment)
    select 'DIRECT_DEBIT', id from M_FULFILLMENT  where id not in (select m_fulfillment from M_PAYMENT_OPTION));
    

    The subquery in your statement offers several lines and failed to insert 2 or more values in your m_fulfillment column at a time.

    But I think you want to insert several lines. Otherwise, you need to change your subquery to offer that one value, maybe a max or min function will help.

    Grüße aus Bonn

    Kay

  • CAPTURE THE OUTPUT IN INSERT INTO SELECT AND DELETE

    Hi all


    INSERT into employee_history_arch select * from employee_history where employee_status = 'CP' and action_dt < (sysdate-32);
    commit;

    delete from employee_history where employee_status = 'CP' and action_dt < (sysdate-32);
    commit;

    I must capture both the output of the insert and delete the sql query and compare the two values for validation. I shouldn't use select count (*) before the delete statement. I shud exactly capture the output... How to do? Please help me

    We will have ' 30 deleted rows' or ' 30 inserted rows"in our tool... I need to capture that 'put out' in a variable and validate against the other

    This should be easy.

    SQL> set serverout on
    SQL> DECLARE
      2    v_rows_inserted PLS_INTEGER;
      3    v_rows_deleted  PLS_INTEGER;
      4  BEGIN
      5    INSERT INTO emp_temp
      6      SELECT * FROM emp WHERE deptno = 20;
      7    v_rows_inserted := SQL%ROWCOUNT;
      8    dbms_output.put_line('Rows Inserted: ' || v_rows_inserted);
      9    DELETE FROM EMP WHERE deptno = 20;
     10    v_rows_deleted := SQL%ROWCOUNT;
     11    dbms_output.put_line('Rows Deleted: ' || v_rows_deleted);
     12    IF v_rows_inserted = v_rows_deleted THEN
     13      dbms_output.put_line('They are same!');
     14    ELSE
     15      dbms_output.put_line('They are NOT same!');
     16    END IF;
     17  END;
     18  /
    Rows Inserted: 7
    Rows Deleted: 7
    They are same!
    
    PL/SQL procedure successfully completed.
    
  • Insert into select * from table 3. -is on the agenda by the needless?

    I've got an example of script, it will work for any table, so I don't bother with the full ddl.

    ----------------------------------------------------------------------------
    create table test in select * from hotels where 1 = 2;

    Insert into test select * from Hotels by city;

    Select the city from the trial;

    -drop table test is serving;
    -----------------------------------------------------------------------------

    The amazing thing is, that the city is ordered alphabetically,
    but you would say it is that an operation order is irrelevant.

    Any ideas on that?

    This will still work?

    Edited by: FourEyes on December 8, 2008 22:55

    Edited by: FourEyes on 8 December 2008 22:56

    Edited by: FourEyes on 8 December 2008 22:56

    Hello

    The [SQL Oracle 10 language reference | http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9014.htm#sthref9371] manual says:

    «In regards to the ORDER BY clause from the subquery in the DML_table_expression_clause, you place your order is guaranteed only for the inserted rows and only within each extension table.» Orders new lines with regard to existing lines is not guaranteed. »

  • Function of package of call per line in the statement INSERT INTO SELECT

    Hello

    I wrote the following SQL insert.

    INSERT the Table_A (Col_A, Col_B, Col_C)

    SELECT Col_A, Col_B, (SELECT PACKAGE1. DOUBLE FUNC())

    FROM Table_A

    WHERE Col_A = "AAA".

    PACKAGE1. Func() is a function to create numbers using the sequence.

    The result is

    Col_a Col_B, Col_C

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

    C003 AAA B1

    C003 AAA B2
    C003 AAA B3

    What I want is as follows:

    Col_a Col_B, Col_C

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

    C003 AAA B1

    AAA B2 C004
    AAA B3 C005

    I want different values per line in Col_C. is it possible to do this?

    I think the fact that you put the function call in a subquery is why he executed only once (which is a useful thing to know if you want this feature). To get executed for each line, you only need to do this:

    INSERT the Table_A (Col_A, Col_B, Col_C)

    SELECT Col_A, Col_B, PACKAGE1. FUNC()

    FROM Table_A

    WHERE Col_A = "AAA".

    However, as others have said, there is no reason to wrap a sequence.nextval in a function.

  • Insert the select statement result in CLOB

    Hi, I would like to insert the result of a statement select into a CLOB with a trigger.

    Whevner a number is registered my research to trigger how often the number is used in several objects and now my problem I also would like to know the record ID where the number is used.

    SELECT 'ITEXT '.
    OF 'CHECK_INR '.
    WHERE 'USE' > 1

    This select records of results 2 How can I insert the result into a CLOB with my trigger?

    Thanks in advance

    Steven,

    It's really a question better suited for another forum because it is not really associated with ApEx. Also, something tells me that you really want to do an UPDATE not an insert. However, here's a quick example...

    DECLARE
    
       l_orders VARCHAR2(4000);
    
    BEGIN
    
       FOR x IN (
          SELECT *
          FROM my_orders_table
       )
       LOOP
          l_orders := l_orders || ', ' || x.order_data_column;
       END LOOP;
    
       l_orders := l_trim(l_orders, ', ');
    
       UPDATE some_table
       SET some_column = l_orders
       WHERE id = some_id;
    
    END;
    

    That's the key. Use VARCHAR2 unless you need CLOB.

    Kind regards
    Dan

    http://danielmcghan.us
    http://sourceforge.NET/projects/tapigen

  • Insert into MDQ_OLD select * from table (lt_monitorMdq);

    I'm trying to insert into a table that has only a single column, which is a column of a user defined type (UDT). The UDT is nested, that is one of the attributes of the UDT is an another UDT.

    I aim to insert into the table like this pseudo-code:

    INSERT INTO T1 SELECT * FROM THE UDT;

    CREATE TABLE MDQ_OLD (myMDQ UDT_T_MONITOR_MDQ)

    NESTED TABLE myMDQ

    (T1_NEW) ACE STORE

    THE NESTED TABLE MONITOR_MDQ_PRIM_RIGHTS

    STORE AS T2_NEW);

    The MONITOR_MDQ_CLI procedure. Read below returns the parameter lt_monitorMdq which is a UDT type as announced. The statement "insert into select MDQ_OLD * table (lt_monitorMdq);" fails, while the second insert statement works.

    Is it possible to get the first statement of work?

    I'm on Oracle 11 g 2.

    DECLARE

    lt_monitorMdq UDT_T_MONITOR_MDQ;

    BEGIN

    MONITOR_MDQ_CLI. Reading (TRUNC (SYSDATE),

    TRUNC (SYSDATE),

    NULL,

    NULL,

    "MILLION BTU.

    lt_monitorMdq); -Note lt_monitorMdq is an OUT parameter

    -This insert does not work

    Insert into MDQ_OLD select * from table (lt_monitorMdq);

    BECAUSE me in 1... lt_monitorMdq.count

    LOOP

    Dbms_output.put_line ('lt_monitorMdq: ' | .mdq_id lt_monitorMdq (i));

    -This integration works

    INSERT INTO MDQ_OLD (MYMDQ)

    VALUES (UDT_T_MONITOR_MDQ (UDT_R_MONITOR_MDQ)

    lt_monitorMdq (i) .gasday,

    1,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    () UDT_T_MONITOR_MDQ_PRIM_RIGHT

    () UDT_R_MONITOR_MDQ_PRIM_RIGHT

    1,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    (NULL)));

    END LOOP;

    END;

    have you tried:

    INSERT INTO MDQ_OLD (myMDQ) VALUES (lt_MonditorMDq);

    curiosity:

    Is there a particular reason, why you have created a table with a single column of type UDT instead of:

    CREATE TABLE... OF UDT_T_MONITOR_MDQ;

    I can tell you from experience that using a nested table, you can easily query the data in the nested table.

    MK

  • Long time, buffer with an insert and select through a dblink

    I do a fairly simple ' insert into select from "statement through a dblink, but something is seriously wrong across the link. I am a huge buffer time in terms of the command explain (line 9) and I don't know why. When I try to run sql tuning on it across the dblink, I get an ora-600 error "ORA-24327: need explicit attach before authenticating a user.
    Here's the original sql:

    INSERT INTO PACE_IR_MOISTURE@PRODDMT00 (SCHEDULE_SEQ, LAB_SAMPLE_ID, HSN, SAMPLE_TYPE, MATRIX, SYSTEM_ID)
    SELECT DISTINCT S.SCHEDULE_SEQ, PI. LAB_SAMPLE_ID, PI. HSN, SAM. SAMPLE_TYPE, SAM. MATRIX: B1 S SCHEDULES
    JOIN THE PERMANENT_IDS ' X '. HSN = S.SCHEDULE_ID
    JOIN SAM SAMPLES WE PI. HSN = SAM. HSN
    JOIN PROJECT_SAMPLES ON PS PS. HSN = SAM. HSN
    JOIN PROJECTS P ON PS. PROJECT_SEQ = PS. PROJECT_SEQ
    WHERE S.PROC_CODE = 'DRY WEIGHT' AND S.ACTIVE_FLAG = 'C' AND S.COND_CODE = 'CH' AND P.WIP_STATUS IN ('WP', 'HO')
    AND SAM. WIP_STATUS = "WP";

    Here's the sql code, as it appears on proddmt00:

    INSERT INTO 'PACE_IR_MOISTURE' ('SCHEDULE_SEQ', 'LAB_SAMPLE_ID', 'HSN","SAMPLE_TYPE","MATRIX","SYSTEM_ID")
    SELECT 'A6' DISTINCT '. SCHEDULE_SEQ', 'A5 '. "' LAB_SAMPLE_ID ', 'A5 '. "" HSN ","A4 ". "" SAMPLE_TYPE ","A4 ". "" MATRIX ": B1
    "SCHEDULES" @! "A6", "PERMANENT_IDS" @! "A5", "SAMPLES" @! "A4", "PROJECT_SAMPLES" @! "A3", "PROJECTS" @! "A2".
    WHERE "A6". «PROC_CODE ' = 'DRY WEIGHT' AND 'A6'.» ' ACTIVE_FLAG '= 'C' AND "A6". "COND_CODE" = "CH", ("A2" ".") " WIP_STATUS '= 'WP' OR 'A2'.' WIP_STATUS "=" HO") AND"A4 ". "WIP_STATUS"= "WP" AND "A3". "PROJECT_SEQ"= "A3". "" PROJECT_SEQ "AND"A3 ". "HSN"= "A4". "" HSN ' AND 'A5 '. "HSN"= "A4". "" HSN ' AND 'A5 '. "HSN"= "A6". "" SCHEDULE_ID. "

    Here is the plan of the command explain on proddmt00:

    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    SQL_ID, cvgpfkhdhn835, number of children 0
    -------------------------------------
    INSERT INTO 'PACE_IR_MOISTURE' ('SCHEDULE_SEQ', 'LAB_SAMPLE_ID', 'HSN","SAMPLE_TYPE","MATRIX","SYSTEM_ID")
    SELECT 'A6' DISTINCT '. SCHEDULE_SEQ', 'A5 '. "' LAB_SAMPLE_ID ', 'A5 '. "" HSN ","A4 ". "" SAMPLE_TYPE ","A4 ". "" MATRIX ": B1
    "SCHEDULES" @! "A6", "PERMANENT_IDS" @! "A5", "SAMPLES" @! "A4", "PROJECT_SAMPLES" @! "A3", "PROJECTS" @! "A2".
    WHERE "A6". «PROC_CODE ' = 'DRY WEIGHT' AND 'A6'.» ' ACTIVE_FLAG '= 'C' AND "A6". "COND_CODE" = "CH" AND "
    ("A2". "WIP_STATUS"= "WP" OR "A2". ("" WIP_STATUS "=" HO ") AND"A4 ". "WIP_STATUS" = "WP" AND "
    "A3". "PROJECT_SEQ"= "A3". "" PROJECT_SEQ "AND"A3 ". "HSN"= "A4". "" HSN ' AND 'A5 '. "HSN"= "A4". "" HSN "AND
    'A5 '. "HSN"= "A6". "" SCHEDULE_ID. "

    Hash value of plan: 3310593411

    -------------------------------------------------------------------------------------------------------------------
    | ID | Operation | Name | Lines | Bytes | TempSpc | Cost (% CPU). Time | Inst | IN-OUT |
    -------------------------------------------------------------------------------------------------------------------
    | 0 | INSERT STATEMENT. 5426M (100) | |
    | 1. UNIQUE HASH | 1210K | 118 M | 262 M | 5426M (3) | 999:59:59 |
    |* 2 | HASH JOIN | 763G | 54T | 8152K | 4300M (1) | 999:59:59 |
    | 3. DISTANCE | 231K | 5429K | 3389 (2) | 00:00:41 |! | R > S |
    | 4. THE CARTESIAN MERGE JOIN. 1254G | 61T | 1361M (74). 999:59:59 |
    | 5. THE CARTESIAN MERGE JOIN. 3297K | 128 M | 22869 (5) | 00:04:35 |
    | 4 > DISTANCE | SCHEDULES | 79. 3002 | 75 (0) | 00:00:01 | | R > S |
    | 7. KIND OF BUFFER. 41830 | 122K | 22794 (5) | 00:04:34 |
    | 8. DISTANCE | PROJECTS | 41830 | 122K | 281 (2) | 00:00:04 |! | R > S |
    | 9. KIND OF BUFFER. 380K | 4828K | 1361M (74). 999:59:59 |
    | 10. DISTANCE | PROJECT_SAMPLES | 380K | 4828K | 111 (0) | 00:00:02 |! | R > S |
    -------------------------------------------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):
    ---------------------------------------------------

    2 - access("A3".") HSN '= 'A4'.' HSN' AND 'A5 '. "HSN"= "A6". ("' SCHEDULE_ID")

    Hello

    Looking at your SQL it loks like you're not joining to the PROJECT table (where the word dreaded CARTESIAN?):

    Your code:

    JOIN PROJECTS P ON PS.PROJECT_SEQ = PS.PROJECT_SEQ 
    

    ... I think this should probably be...

    JOIN PROJECTS P ON P.PROJECT_SEQ = PS.PROJECT_SEQ 
    

    ....??

  • Nothing wrong with including ORDER BY in INSERT into... SELECT statement?

    Are there implications due to the use of ORDER BY (field3 control) in bottom INSERT INTO... SELECT statement.


    insert 
    into mytable    (
            field1,
            field2,
            field3
            )        
    select         field1,
            field2,
            field3
            from source_Table
            order by field3;

    Order by is used with functions select but not a mandate. Usually people uninterested by what people order insert data in a table. We have to try to keep operations and it inserts into a table.

  • Select the statement to insert into a table by using a loop

    Hello
    create table uploadtab(
    itema varchar2(3),
    xtype varchar2(1),
    salesa number,
    margina number,
    salesb number,
    marginb number,
    salesc number,
    marginc number);
    
    insert into uploadtab
      (itema, xtype, salesa, margina, salesb, marginb, salesc, marginc)
    values
      ('abc', 'a', 100, .40, 300, .10, 450, .25);
    
    create table testinsert(itema varchar2(3),
    xtype varchar2(1),
    sales number,
    margin number);
    what I want to do is create 3 records based on this one in a loop
    so here's my desired for testinsert output
    abc  a 100  .40
    abc  a 300  .10
    abc  a 450  .25
    I don't want to use 3 insert tables if possible

    any help would be greatly appreciated
    Thanks in advance

    Published by: DM on July 7, 2010 14:22

    This gives a shot:

    INSERT INTO testinsert
    ( itema
    , xtype
    , sales
    , margin
    )
    SELECT  itema
    ,       xtype
    ,       DECODE
            ( RN
            , 1,salesa
            , 2,salesb
            , 3,salesc
            )
    ,       DECODE
            ( RN
            , 1,margina
            , 2,marginb
            , 3,marginc
            )
    FROM            uploadtab
    CROSS JOIN      (
                            SELECT ROWNUM RN
                            FROM   dual
                            CONNECT BY LEVEL <= 3
                    )
    ;
    
  • Select dynamic in - insert into SQL

    Hello

    I need some advice on how can I change my dynamic SQL code (select in - insert in) to manage changes to the underlying tables.

    My apologies for the long post - I tried to put a minimum, but all the details necessary to explain my situation.

    I have several tables who are employed (pl/sql package) purge [all lines that are three months – based on the value of creation_date]. For example, DDL for tables of the sample and its ARCHIVE for:
    create table actual_table (col1 varchar2(100),
        col2 varchar2(100),
        col3 varchar2(100),
        creation_date date)            
                
    create table actual_table_arc (col1 varchar2(100),
        col2 varchar2(100),
        col3 varchar2(100),
        creation_date date,
        archive_date   date) 
    This work of purging archives also some data according to the needs of the company. Archiving is done using a dynamic sql as below:
    v_arc_sql_stmt := ' INSERT INTO  actual_table_arc'
                    || ' SELECT '|| get_column_name_list('ACTUAL_TABLE') ||', sysdate  FROM actual_table ' 
                    || ' WHERE  col1 = :a';
    
    EXECUTE IMMEDIATE DBMS_LOB.SUBSTR (v_arc_sql_stmt, 32000, 1) USING v_some_id;    
    Note: Please note that I use sysdate in select above to populate the archive_date column.


    Code for the get_column_name_list() function is below:
       FUNCTION get_column_name_list (p_table_name    VARCHAR2)
       RETURN CLOB
       IS
          CURSOR col_name_cur IS
              SELECT a.column_name
                FROM all_tab_columns a
               WHERE a.table_name =  UPPER(p_table_name)||'_ARC'
                   AND EXISTS (SELECT 'Y'
                                        FROM all_tab_columns b
                                       WHERE b.table_name = UPPER(p_table_name)
                                           AND b.column_name = a.column_name)
                ORDER BY a.column_id;
           v_column_list    CLOB;
      BEGIN
          FOR rec IN col_name_cur
          LOOP
             v_column_list := v_column_list || rec.column_name ||',' ;
          END LOOP;
          v_column_list := SUBSTR(v_column_list, 0, LENGTH(v_column_list)-1);
          RETURN v_column_list;
    END get_column_name_list;
    Now: it is necessary to add a new column to the ACTUAL_TABLE table. So new table looks like this:
    actual_table :
       col1 varchar2(100),
       col2 varchar2(100),
       col3 varchar2(100),
       creation_date date,
       new_column varchar2(100)            
    The table of ARC after changing to include the new column looks like this:
    actual_table_arc :
       col1 varchar2(100),
       col2 varchar2(100),
       col3 varchar2(100),
       creation_date date,
       archive_date   date,
       new_column varchar2(100)
    Now the dynamic SQL above won't work because of the order of the columns in the table of ARC and SELECT it.

    Please tell us how I can change the dynamic SQL to absorb this change [and all these changes in the future].

    Thank you

    Published by: Amer-user12033597 22-Aug-2011 08:06

    Hello

    I think that partitioning is included in enterprise edition, you can check which features that you can use with

    select * from v$option
    

    Of what you said

    I have several tables who are employed (pl/sql package) purge [all lines that are three months – based on the value of creation_date].

    You could split the actual_table the date of creation to give monthly partitions - daily or weekly depending on how often you plan to run the purge job. When the job runs, you would identify all partitions of the table that contains data is superior to 3 months - personally I use a naming convention to do it like this.

    DTYLER_APP@pssdev2> CREATE TABLE dt_acutal_table
      2  (   col1 varchar2(100),
      3      col2 varchar2(100),
      4      col3 varchar2(100),
      5      creation_date date
      6  )
      7  PARTITION BY RANGE (creation_date)
      8  (   PARTITION ptn_201101 VALUES LESS THAN (TO_DATE('01/02/2011','dd/mm/yyyy')),
      9      PARTITION ptn_201102 VALUES LESS THAN (TO_DATE('01/03/2011','dd/mm/yyyy')),
     10      PARTITION ptn_201103 VALUES LESS THAN (TO_DATE('01/04/2011','dd/mm/yyyy')),
     11      PARTITION ptn_201104 VALUES LESS THAN (TO_DATE('01/05/2011','dd/mm/yyyy')),
     12      PARTITION ptn_201105 VALUES LESS THAN (TO_DATE('01/06/2011','dd/mm/yyyy')),
     13      PARTITION ptn_201106 VALUES LESS THAN (TO_DATE('01/07/2011','dd/mm/yyyy')),
     14      PARTITION ptn_201107 VALUES LESS THAN (TO_DATE('01/08/2011','dd/mm/yyyy')),
     15      PARTITION ptn_201108 VALUES LESS THAN (TO_DATE('01/09/2011','dd/mm/yyyy')),
     16      PARTITION ptn_201109 VALUES LESS THAN (TO_DATE('01/10/2011','dd/mm/yyyy')),
     17      PARTITION ptn_201110 VALUES LESS THAN (TO_DATE('01/11/2011','dd/mm/yyyy')),
     18      PARTITION ptn_201111 VALUES LESS THAN (TO_DATE('01/12/2011','dd/mm/yyyy')),
     19      PARTITION ptn_201112 VALUES LESS THAN (TO_DATE('01/01/2012','dd/mm/yyyy')),
     20      PARTITION ptn_MaxValue VALUES LESS THAN (MAXVALUE)
     21  )
     22  /
    
    Table created.
    
    DTYLER_APP@pssdev2> CREATE TABLE dt_acutal_table_arc
      2  (   col1 varchar2(100),
      3      col2 varchar2(100),
      4      col3 varchar2(100),
      5      creation_date date
      6  )
      7  PARTITION BY RANGE (creation_date)
      8  (   PARTITION ptn_201101 VALUES LESS THAN (TO_DATE('01/02/2011','dd/mm/yyyy')),
      9      PARTITION ptn_201102 VALUES LESS THAN (TO_DATE('01/03/2011','dd/mm/yyyy')),
     10      PARTITION ptn_201103 VALUES LESS THAN (TO_DATE('01/04/2011','dd/mm/yyyy')),
     11      PARTITION ptn_201104 VALUES LESS THAN (TO_DATE('01/05/2011','dd/mm/yyyy')),
     12      PARTITION ptn_201105 VALUES LESS THAN (TO_DATE('01/06/2011','dd/mm/yyyy')),
     13      PARTITION ptn_201106 VALUES LESS THAN (TO_DATE('01/07/2011','dd/mm/yyyy')),
     14      PARTITION ptn_201107 VALUES LESS THAN (TO_DATE('01/08/2011','dd/mm/yyyy')),
     15      PARTITION ptn_201108 VALUES LESS THAN (TO_DATE('01/09/2011','dd/mm/yyyy')),
     16      PARTITION ptn_201109 VALUES LESS THAN (TO_DATE('01/10/2011','dd/mm/yyyy')),
     17      PARTITION ptn_201110 VALUES LESS THAN (TO_DATE('01/11/2011','dd/mm/yyyy')),
     18      PARTITION ptn_201111 VALUES LESS THAN (TO_DATE('01/12/2011','dd/mm/yyyy')),
     19      PARTITION ptn_201112 VALUES LESS THAN (TO_DATE('01/01/2012','dd/mm/yyyy')),
     20      PARTITION ptn_MaxValue VALUES LESS THAN (MAXVALUE)
     21  )
     22  /
    
    Table created.
    
    DTYLER_APP@pssdev2> CREATE TABLE dt_acutal_table_exch
      2  (   col1 varchar2(100),
      3      col2 varchar2(100),
      4      col3 varchar2(100),
      5      creation_date date
      6  )
      7  /
    
    DTYLER_APP@pssdev2> insert
      2  into
      3      dt_acutal_table
      4      (   col1,
      5          col2,
      6          col3,
      7          creation_date
      8      )
      9  SELECT
     10      TO_CHAR(rownum),
     11      TO_CHAR(rownum),
     12      TO_CHAR(rownum),
     13      SYSDATE - ROWNUM
     14  FROM
     15      dual
     16  CONNECT BY
     17      LEVEL <= 365
     18  /
    
    365 rows created.
    
    DTYLER_APP@pssdev2> commit;
    
    Commit complete.
    
    DTYLER_APP@pssdev2> CREATE OR REPLACE FUNCTION f_Get_Partition
      2  (   ad_PurgeDate    IN DATE,
      3      as_Table        IN VARCHAR2
      4  )
      5  RETURN user_tab_partitions.partition_name%TYPE
      6  IS
      7
      8      ls_Partition        user_tab_partitions.partition_name%TYPE;
      9  BEGIN
     10
     11      SELECT
     12          partition_name
     13      INTO
     14          ls_Partition
     15      FROM
     16          user_tab_partitions
     17      WHERE
     18          partition_name =    'PTN_'|| TO_CHAR
     19                                      (   ad_PurgeDate,
     20                                          'YYYYMM'
     21                                      )
     22      AND
     23          table_name = UPPER(as_Table);
     24
     25      RETURN ls_Partition;
     26
     27  EXCEPTION
     28      WHEN NO_DATA_FOUND THEN
     29          RAISE_APPLICATION_ERROR
     30          (   -20001,
     31              'Partition could not be found for table '||as_Table||' and date '||TO_CHAR(ad_PurgeDate)
     32          );
     33  END;
     34  /
    
    Function created.
    
    DTYLER_APP@pssdev2> CREATE OR REPLACE PROCEDURE p_Arc
      2  (   ad_PurgeDate    IN DATE,
      3      as_SourceTable  IN VARCHAR2
      4  )
      5  IS
      6
      7      ls_ExchSQL          VARCHAR2(4000);
      8      ls_ArcSQL           VARCHAR2(4000);
      9      ls_ArcTable         user_tables.table_name%TYPE;
     10      ls_ExchTable        user_tables.table_name%TYPE;
     11      ls_PartitionName    user_tab_partitions.partition_name%TYPE;
     12
     13  BEGIN
     14
     15      ls_PartitionName := f_Get_Partition
     16                          (   ad_PurgeDate,
     17                              as_SourceTable
     18                          );
     19
     20      ls_ArcTable     := as_SourceTable||'_arc';
     21      ls_ExchTable    := as_SourceTable||'_exch';
     22
     23      ls_ExchSql := ' ALTER TABLE '||as_SourceTable||'
     24                      EXCHANGE PARTITION '||ls_PartitionName||'
     25                      WITH TABLE '||ls_ExchTable
     26                     ;
     27
     28      EXECUTE IMMEDIATE ls_ExchSql;
     29
     30      ls_ArcSql := '  ALTER TABLE '||ls_ArcTable||'
     31                      EXCHANGE PARTITION '||ls_PartitionName||'
     32                      WITH TABLE '||ls_ExchTable
     33                     ;
     34
     35      EXECUTE IMMEDIATE ls_ArcSql;
     36
     37  END;
     38  /
    
    Procedure created.
    
    DTYLER_APP@pssdev2> exec p_Arc(TO_DATE('01/06/2011','dd/mm/yyyy'),'dt_acutal_table')
    
    PL/SQL procedure successfully completed.
    
    DTYLER_APP@pssdev2> select count(*) from dt_acutal_table partition( ptn_201106);
    
      COUNT(*)
    ----------
             0
    
    1 row selected.
    
    DTYLER_APP@pssdev2> select count(*) from dt_acutal_table_arc partition( ptn_201106);
    
      COUNT(*)
    ----------
            30
    
    1 row selected.
    
    DTYLER_APP@pssdev2> alter table dt_acutal_table add (newcol number);
    
    Table altered.
    
    DTYLER_APP@pssdev2> alter table dt_acutal_table_exch add (newcol number);
    
    Table altered.
    
    DTYLER_APP@pssdev2> alter table dt_acutal_table_arc add (newcol number);
    
    Table altered.
    
    DTYLER_APP@pssdev2> exec p_Arc(TO_DATE('01/05/2011','dd/mm/yyyy'),'dt_acutal_table')
    
    PL/SQL procedure successfully completed.
    

    HTH

    David

  • A weird exception in 12 c (ORA-01461: can bind to a LONG value only for insert into a LONG column)

    I have a Windows application that accesses a database of 12 c Oracle via ODBC (driver version is 12.01.00.01).

    I have a table with a column of key named REGION_ID (NVARCHAR2 (9)) and a dozen other columns, of which three are named region1 and region.2 elle3, all of type NVARCHAR2 (40).

    When I try to insert a string in the scope of the region1 is longer than 9 characters (length of REGION_ID), I get an error ORA-01461 (' can bind to a LONG value only for insert into a LONG column). If I set the length of REGION_ID be NVARCHAR2 (15), so I can add channels to the region1 in length up to 15 field until I get ORA-01461 exception again. Curiously, if I change the name of column region1 to REGIONONE, I don't get any errors, and everything works fine. It's almost as if the column name region1 is being confused with REGION_ID backstage.

    Any ideas? I am using SQLBindParameter to bind the columns, and all calls are successful. I get the exception when I run the insert statement. This same code worked for previous versions of Oracle (9i, 10g and 11g). And if I use a driver of client 11g against the 12 c server, I do not receive the exception.

    Thank you!

    It is a component of ODBC driver bug in 12 c and it is fixed. You can download and install the fix for bug 18232462 or the last window for 12 c patch cumulative/bundle.

    Thank you

    Spengler

  • missing parenthesis in insertion into separate lines select the table from the other table

    Hello

    could you help me with the following question?

    I have the following tables

    CREATE TABLE table1)

    ID varchar (12),

    col2 varchar (10),

    COL3 varchar (10),

    level varchar (10))

    CREATE TABLE table2)

    Id2 varchar (12)

    A varchar (10),

    B number (1)

    CONSTRAINT PRIMARY KEY PK (ID2, is));

    INSERT INTO table2 (ID2, A, B) SELECT ID, col2

    MAX (CASE WHEN level = "level 1" then 1

    level = 'level 2' then 2

    Level = 3 then 'niveau3') as colIN3)

    FROM table1 GROUP BY ID2, a.;

    the first table have duplicates as follows:

    Id2 COL2 COL3 level

    A1 pepe football level1

    A1 pepe football level2

    A1 pepe football level1

    A1 pepe basket level2

    A1 pepe pingpong level3

    the output should be selected with unique key (ID2, col3) lines and the level must be the greatest.

    Id2 COL2 COL3 level

    A1 pepe football level2

    A1 pepe basket level2

    A1 pepe pingpong level3

    The output of the script tells me the following messages:

    -lack of right parenthesis referring to the max function.

    Thanks adavance.

    Kind regards

    Hello

    Remember the ABC's of the GROUP BY:

    When you use a GROUP BY clause or in an aggregate function, then all in the SELECT clause must be:

    (A) a ggregate function,

    (B) one of the expressions "group By."

    (C) adding to C, or

    (D) something that Depends on the foregoing.  (For example, if you "GROUP BY TRUNC (dt)", you can SELECT "TO_CHAR (TRUNC (dt), 'Mon - DD')").

    To ask him, there are 5 columns in the SELECT clause.  The last one is a function MAX (...); It is an aggregate, is not serious.

    The first 2 columns are also named in the GROUP BY clause, so that they are well.

    The other 2 columns, country and internal_Id do not match any of the above categories.  These 2 columns cause the error.

    There are many ways to avoid this error, each producing different results.  You could

    • remove these 2 columns in the SELECT clause
    • Add these 2 columns in the GROUP BY clause
    • use the aggregation such as MIN, 2-column functions
    • remove the country from the SELECT clause and add internal_id to the GROUP BY clause
    • remove the internal_id from the SELECT clause, and add countries to the GROUP BY clause
    • ...

    What are the results you want?

    Whenever you have a question, please post a small example of data (CREATE TABLE and INSERT statements) for all the tables involved, so people who want to help you can recreate the problem and test their ideas.  Also post the results you want from this data, as well as an explanation of how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • Error PLS-00428: an INTO clause in this SELECT statement

    Dear Experts,

    I'm new to PL/SQL programming

    I try to run the following query, I get the error message.

    Please help me solve the error.

    declare

    var_cd number (20);

    Start

    If: P1_TYP_CAT is not null then

    SELECT max (CAT_cd + 1) as var_cd from IM_AST_CAT by CAT_cd;

    insert into IM_AST_CAT (CAT_NM, CAT_CD) values ((upper (:P1_TYP_CAT)),(:var_cd));

    on the other

    RAISE_APPLICATION_ERROR ('-20001,' both Department and location must be provided ");

    end if;

    end;

    In PL/SQL, must be used IN the clause when using SELECT statements.

    SELECT max (CAT_cd + 1) as var_cd

    in variable - it is missing in your code

    from IM_AST_CAT by CAT_cd;

    Your code should be

    declare

    var_cd number (20);

    Start

    If: P1_TYP_CAT is not null then

    SELECT max (CAT_cd + 1).
        in var_cd
    of IM_AST_CAT
    order of CAT_cd;

    insert into IM_AST_CAT (CAT_NM, CAT_CD) values (upper(:P1_TYP_CAT), var_cd);

    on the other

    RAISE_APPLICATION_ERROR ('-20001,' both Department and location must be provided ");

    end if;

    end;

    For example:

    DECLARE

    l_first_name varchar2 (100);

    BEGIN

    Select first_name

    in l_first_name

    employees

    where employee_id = 100;

    END;

    Post edited by: Suri

Maybe you are looking for

  • WAG320N abandoned DSL connection whenever I connect to its Web page

    It is a bit of pain the behaiviour is inconsistent. whenever I connect to the Web page of the device a certain number of things may happen 1. There is no connection - trying to load the page, but never does. During this time the router gives up the A

  • The photo management and photo programs

    I have pictures in my 'photo' folder, Windows Photo Gallery, Picasa, and Kodak Easyshare.  I love all of these, but am myself confused.  I'm looking for an easy (and I say layman easy) way to view and work with any photo given from any given program.

  • Problems opening folder

    Well, I downloaded a file recently, and when I tried to open it, he said that he did not know what program to use. So, I went to choose the appropriate program and guess what happened? I chose the wrong program, and now it will not work. The biggest

  • Why I can't install Chrome or Firefox on Windows 8?

    Whenever I try to install the aforementioned browsers, I am told that the system is unable to complete the installation.

  • Auto boot esxi 5

    Salve, ho due dei to each su esxi 5 free e una macchina virtuale Windows 2003 R2 due. Ho impostato auto start my both funziona su no; Quale it could be the cause? Grazie