ORA-00001 violation, always on the 2nd insertion irrespective of the values

Connected to:

Database Oracle 12 c Enterprise Edition Release 12.1.0.2.0 - 64 bit Production

With the options of partitioning, OLAP, advanced analytics and Real Application Testing

I get a UK violation when I shouldn't be, and I'm stuck.  Where to look to figure out what is causing the problem?  Excerpts below.

I insert only two records.  The second insertion always fails, regardless of the value of LOT_NO.

I.E.

  • If the first insert is with LOT_NO 1234, the 2nd insertion with LOT_NO 1235 fails.
  • If the first insert is with LOT_NO 1235, the 2nd insertion with LOT_NO 1234 fails.


truncate table ppr_lots;


commit;


Select * from ppr_lots;  -not return any records


-alter table ppr_lots change the lot_uk disable constraint;


insert into PPR_LOTS (lot_no, lot_id, lot_type_id, lot_status_type_id, cadastral_area_id, land_tenure_type_id, land_use_type_id, lot_demarcation_type_id, the plan_id argument, address_id, lot_building_id, pid, legal_issues_yn, lot_size, area_unit_type_id, gis_data_captured_yn, short_legal_dsc, long_legal_dsc, eff_from_dtm) eff_through_dtm remarks_dsc, section_locator_no, lot_guid, logically_deleted_yn, concurrency_check_ts, log_created_by_user_id, log_created_ts, log_updated_by_user_id, log_updated_ts)

values (1234, 2, 5305, 5201, 23, 4700, 1802, 5000, 1, null, null, 1, 'n', 10, 201, 'Y', 'GAC002001234', null, null, null, null, null, null, 'n', to_timestamp (27 November 2015 09:05:42.517978', 'dd-mm-yyyy hh24:mi:ss.ff'), 1, to_timestamp (27 November 2015 09:05:42.517978', 'dd-mm-yyyy hh24:mi:ss.ff'), null, null);


insert into PPR_LOTS (lot_no, lot_id, lot_type_id, lot_status_type_id, cadastral_area_id, land_tenure_type_id, land_use_type_id, lot_demarcation_type_id, the plan_id argument, address_id, lot_building_id, pid, legal_issues_yn, lot_size, area_unit_type_id, gis_data_captured_yn, short_legal_dsc, long_legal_dsc, eff_from_dtm) eff_through_dtm remarks_dsc, section_locator_no, lot_guid, logically_deleted_yn, concurrency_check_ts, log_created_by_user_id, log_created_ts, log_updated_by_user_id, log_updated_ts)

values (1235, 3, 5304, 5201, 24, 4701, 1802, 5000, 2, null, null, 2, 'n', 104.5, 200, 'Y', 'CEC003001235', null, null, null, null, null, null, 'n', to_timestamp (27 November 2015 09:05:42.538275', 'dd-mm-yyyy hh24:mi:ss.ff'), 1, to_timestamp (27 November 2015 09:05:42.538275', 'dd-mm-yyyy hh24:mi:ss.ff'), null, null);


Error report-

SQL error: ORA-00001: unique constraint (LIS_PPR. LOT_UK) violated

00001 00000 - "forced single (s.%s) violated."

* Cause: An UPDATE or INSERT statement attempted to insert a duplicate key.

For Trusted Oracle configured in DBMS MAC mode, you can see

This message if there is an entry double at a different level.

* Action: Either remove the single restriction or not to insert the key.

BTW, if I turn off the UK, everything is fine.

-Ken

LOT_UK is defined simply as follows.

ALTER TABLE PPR_LOTS

ADD CONSTRAINT LOT_UK UNIQUE

(

LOT_NO

)

USING INDEX

(

CREATE A UNIQUE LOT_UK ON PPR_LOTS (LOT_NO CAD) INDEX

LOGGING

TABLESPACE USERS

PCTFREE 10

INITRANS 2

STORAGE

(

65536 INITIAL

NEXT 1048576

MINEXTENTS 1

MAXEXTENTS UNLIMITED

DEFAULT USER_TABLES

)

NOPARALLEL

)

ENABLE;

Found the problem.

I thought that I had disabled triggers.  Turns out I didn't, and a defective trigger is overwhelming as LOT_NO.

It's always the answer is simple.

-Ken

Tags: Database

Similar Questions

  • Error: ORA-16757: failed to get the value of this property

    Hi all
    I have an error:
    DGMGRL > see the database dbname_stb LogXptStatus;
    Error: ORA-16757: failed to get the value of this property
    I check:
    DGMGRL > see the configuration;

    Configuration - dbname_dg

    Protection mode: MaxPerformance
    Databases:
    dbname_pr - primary database
    dbname_stb - physical of the standby database

    Fast-Start Failover: DISABLED

    The configuration status:
    SUCCESS

    drcdbname_stb.log:
    RSM0: Received the request the property Get: rid = 0 x 01010000, pid = 54
    2012-10-17 15:21:14.702 of database Resource: get the LogXptStatus property
    RSM 15:21:14.702 2012-10-17 error: trying to interview a 'LogXptStatus' primary type property on a standby database resource.
    2012 10-17 error 15:21:14.702 database resource GetProperty (16501,16757)

    I don't understand this error?
    Thank you all.

    Take a look on this

    Re: ORA-00254 | Trouble with dataguard

  • CHOOSE the Menu malfunction, HP 48 G always returns the value '0', regardless of the selection

    I choose a menu with different functions which are useful when dealing with circles. I programmed on my HP 50 g and transferred directly to my HP 48 g by Kermit ASCII. The menu choose does not seem to highlight a specific choice, as it does on the HP 50 g, there is no indication of the choice is selected and jumping to menu options via defined their number also does not work. On the debugger, no matter if OK or entry is activated under any option '0' is always returned, as if I had cancled out of the menu. Any help would be appreciated. Perhaps CHOOSE menus are slightly different on the HP 48 G?

    I found the problem. The syntax to CHOOSE is slightly different than the one on the 50g. On the 50g, I used to write my statements like this

    { { ... } } CHOOSE 0

    The 48G requires it:

    { { ... } } 1. CHOOSE

  • JUCtrlHierNodeBinding.getChildren always returns the value 25 child

    The code snippet below tries to find a certain child of a node.

    However, what I've debugged the node is always maximum 25 children.

    Where on the treetable there are more than 25 children.

    I couldn't find where ADF defines this limit 25.

    All tips for me?

    ...

    child int = 0;

    If (! isMatchFound & & currentLevel.compareTo (this.searchLevel) < 0 & & traverseDown) {}

    System.out.println ("crosses down");

    Check if this node has children, in which case recursively call this method for each of them

    node.getRowCount ();

    List of children < JUCtrlHierNodeBinding > = node.getChildren ();

    If (children! = null) {}

    System.out.println ("children count =" + children.size ());

    child nodes have a type of JUCtrlHierNodeBinding

    for (JUCtrlHierNodeBinding _node: children) {}

    Each child search returns a set of keys to line which must

    Add to the set of keys of rows returned by all

    Search

    System.out.println ("child" + child +);

    RKS RowKeySet = searchTreeNode (_node, searchAttributes, this.searchType, searchString);

    If a corresponding rowKeySet is found for the child node and its

    subnodes add its content

    If (rks! = null & & rks.size () > 0) {}

    rowKeys.addAll (rks);

    }

    }

    }

    }

    ...

    The complete method is attached.

    Got blog Andrejus solution, is a limit of 25 on the treetable RangeSize property. Change it accordingly to account for the number of lines.

  • ORA-00001 on form insert, duplicate value

    Hello!
    I have 8 fields in my form. The values of 4 of them go in Table1 and Table2 others 4.
    Table 1 has a composite unique constraint based on 2 columns (which are filled with the first 2 fields in my form which are the first and last name).
    Table2 has no constraints.
    I've manually recreated my form that was originally made with the wizard block/layout of data. So now im integration with applications I've written. I have to mention everything works fine as long as im not looking to insert a record for someone who is already in Table1.

    The problem: ORA-00001 ("you tried to execute an INSERT or UPDATE statement that created a value duplicated in an area limited by a single index.") when im trying to insert a record for someone who is already in the table 1 (i.e. the name and family name combination is most unique in Table1). In Table1, I say everything is all right, because I don't want to not more than once the same person, but because of this exception ORA INSERT into Table2 also fails. How can I avoid this?

    The code is also just that INSERT INTO can get so I won't post.

    THX,
    Iulian

    If I understand the problem correctly from what you say,

    "So now im integration with applications I've written. The code is also just that INSERT INTO can get so I won't post. »

    This means that you have two table insert statements. Wrap the first statement with the Manager of exceptions as noted below. This way nothing will be inserted into table1 when there are duplicate, but you can insert into another table.

    Begin
    Begin
    Insert into table1 values...
    Exception when DUP_VAL_ON_INDEX then
    Null;
    End;
    Insert into table2 values...

    End;

    I hope this works.

  • Http post: always answer with the value 1

    Hi all

    I have this code below. I always have the value "1″ in return; No files, or other values...

    This means that the value sent by 'POST' it always set to '1 '.

    Where is the error?

    Thank you very much!

    var myFile = new File("C:/APPS/Test/temp.jpg");
    var myLine = "";
    authorization of var = "";

    length of County

    boundaryContent = "-1234\n";
    boundaryContent += ' Content-Disposition: form-data; name = "upload"; filename = "'+ MyFile.Name +'" "+"\n";
    boundaryContent += "Content-Type:"+ "image/jpeg" + "\n"; '.
    boundaryContent += "\n";
    myFile.open ("r");
    myLine = myFile.read ();
    boundaryContent += myLine;
    myFile.close ();
    boundaryContent += "\n";
    boundaryContent += "- 1234 -" + "\n";

    Alert ("calculate file size:" + boundaryContent.length);

    County of end

    conn1 = new Socket;

    If (conn1.open ('127.0.0.1:8888', 'BINARY')) {}

    conn1. Timeout = 9000;

    conn1.writeln ("POST /Enterprise/config/plugins/NoWoodwing/servlet_temp.php HTTP/1.1");
    conn1.writeln ("Host: 127.0.0.1:8888");
    conn1.writeln ("Keep-Alive: 300");
    conn1.writeln ("Connection: keep-alive");
    conn1.writeln ("Content-Length:" + boundaryContent.length);

    conn1.writeln ("Expect: 100-continue");
    conn1.writeln ("Content-Type: multipart/form-data;") Boundary = 1234");
    conn1.writeln("");
    var boundaryContent1 = conn1.writeln("--1234");
    boundaryContent1 += conn1.writeln ('Content-Disposition: form-data: name = "upload"; filename = "'+ myFile.name +'" ');
    boundaryContent1 += conn1.writeln ("Content-Type:" + "image/jpeg");
    boundaryContent1 += conn1.writeln("");
    permission = conn1.readln ();
    Alert ("Autorizzazione:" + permission);
    If (permission == ' HTTP/1.1 100 continue') {}
    If (myFile.open ("r")) {}
    myLine = myFile.read ();
    Alert ("Nuova linea:" + myLine);
    boundaryContent1 += conn1.write (myLine);
    myFile.close ();
    }
    }
    boundaryContent1 += conn1.writeln("");
    boundaryContent1 += conn1.write("--1234--");

    Alert ("development of Post size file:" + boundaryContent1);

    /*
    var reply1 = ";
    {while(!conn1.) EOF)}
    reply1 += conn1.readln ();
    };
    Alert ("back:" + reply1);
    */

    conn1. Close();

    } else {alert ("error:" + conn1.error) ;}}

    It works if you run the upload of file with another tool, such as a browser?

    conn1 = new Socket;
    if (conn1.open ("127.0.0.1:8888", "BINARY")) {
        conn1.timeout=9000;
        conn1.writeln("POST /Enterprise/config/plugins/NoWoodwing/servlet_temp.php HTTP/1.1");
    

    Well, we certainly will be able to test that. Can you find an example of a server that is accessible to the public that accepts uploads and test against that?

  • composite unique constraint on the values of parent and child?

    Is it possible to have a composite unique constraint that contains the values of the child elements? The example below has the "child" elements are offline, but it's preferred, but optional, I know that you can have a unique constraint in the set of tables without using a reference table that contains the constraint and the two columns. How xdb manages this requirement?

    permit:
    <parent ID="1">
       <child><name>test1</name></child>
       <child><name>test2</name></child>
    </parent>
    <parent ID="2">
       <child><name>test1</name></child>
       <child><name>test2</name></child>
    </parent>
    not allowed:
    <parent ID="1">
       <child><name>test1</name></child>
       <child><name>test1</name></child>
    </parent>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
               xmlns:xdb="http://xmlns.oracle.com/xdb"
               xdb:storeVarrayAsTable="true"
               elementFormDefault="qualified">
        
        <xs:element name="parent" type="Parent_T"
            xdb:columnProps="CONSTRAINT parent_pkey PRIMARY KEY (XMLDATA.ID)"
            xdb:defaultTable="PARENT"/>
    
        <xs:complexType name="Parent_T" xdb:SQLType="PARENT_T" xdb:maintainDOM="false">
            <xs:sequence>
                <xs:element name="child" type="Child_T" minOccurs="1" maxOccurs="unbounded" xdb:SQLName="CHILD"
                          xdb:SQLInline="false" xdb:defaultTable="CHILD" "/>
            </xs:sequence>
            <xs:attribute name="ID" xdb:SQLName="ID" use="required" />
        </xs:complexType>
        
        <xs:complexType name="Child_T" xdb:SQLType="CHILD_T">
           <xs:sequence>
             <xs:element name="name" type="xs:string" xdb:SQLName="NAME"/>
           </xs:sequence>
         </xs:complexType>     
    </xs:schema>
    xdb:columnProps = "CONSTRAINT parent_pkey PRIMARY KEY (XMLDATA.ID), * UNIQUE (XMLDATA.» "Child.Name) *" triggers the non-existent attribute


    A possible solution would be to copy the value of the primary key parent of the child element, then I could create a composite unique constraint using only the values of the child. However, I have this same requirement elsewhere in my lowest nested schema, and it can become messy / bad design with cascading of all primary keys on the schema. For example, I have a recursive element in which two attributes must be unique only within the parent company:
    <parent id="1">
       <child a="1" b="1">
          <child a="1" b="2">
             <child a="1" b="1" /> *not allowed
          </child>
       </child>
       <child a="1" b="2" /> *not allowed
    </parent>
    Possible solution:
    <child a="1" b="2" parent_id="1" />
    <xs:complexType name="Child_T>
       <xs:sequence>
          <xs:element name="child" xsd:SQLInline="false" xsd:columnProps="UNIQUE(XMLDATA.a,XMLDATA.b,XMLDATA.parent_id)" minOccurs="0" maxOccurs="unbounded" type="Child_T">
       </xs:sequence>
       </xs:element
    </xs:complexType>
    Is there a better design?

    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi 
    PL/SQL Release 10.2.0.4.0 - Production                           
    CORE     10.2.0.4.0     Production                                       
    TNS for Linux: Version 10.2.0.4.0 - Production                   
    NLSRTL Version 10.2.0.4.0 - Production 

    You can do something like this:

    SQL> DECLARE
      2
      3    xsd_doc xmltype := xmltype('
      4  
      5    
      6      
      7        
      8          
      9        
     10      
     11    
     12    
     13      
     14        
     15          
     16        
     17      
     18    
     19    
     20      
     21        
     22          
     23        
     24        
     25      
     26    
     27    
     28      
     29        
     30          
     31        
     32      
     33    
     34  ');
     35
     36  BEGIN
     37
     38    dbms_xmlschema.registerSchema(
     39      schemaURL => 'test_parent.xsd',
     40      schemaDoc => xsd_doc,
     41      local => true,
     42      genTypes => true,
     43      genbean => false,
     44      genTables => false,
     45      enableHierarchy => dbms_xmlschema.ENABLE_HIERARCHY_NONE
     46    );
     47
     48  END;
     49  /
    
    PL/SQL procedure successfully completed
    
    SQL> CREATE TABLE my_xml_table OF XMLTYPE
      2  XMLTYPE STORE AS OBJECT RELATIONAL
      3  XMLSCHEMA "test_parent.xsd"
      4  ELEMENT "root"
      5  VARRAY xmldata."parent" STORE AS TABLE my_parent_tab
      6  (
      7    VARRAY "child" STORE AS TABLE my_child_tab
      8  )
      9  ;
    
    Table created
    
    SQL> ALTER TABLE my_parent_tab ADD CONSTRAINT parent_uk UNIQUE (nested_table_id, "ID");
    
    Table altered
    
    SQL> ALTER TABLE my_child_tab ADD CONSTRAINT child_uk UNIQUE (nested_table_id, "name");
    
    Table altered
     
    

    Then:

    SQL> insert into my_xml_table values (
      2  xmltype('
      3     test1
      4     test2
      5  
      6  
      7     test1
      8     test2
      9  ')
     10  );
    insert into my_xml_table values (
    *
    ERREUR à la ligne 1 :
    ORA-00001: violation de contrainte unique (DEV.PARENT_UK)
    
    SQL> insert into my_xml_table values (
      2  xmltype('
      3     test1
      4     test1
      5  
      6  
      7     test1
      8     test2
      9  ')
     10  );
    insert into my_xml_table values (
    *
    ERREUR à la ligne 1 :
    ORA-00001: violation de contrainte unique (DEV.CHILD_UK)
    
    SQL> insert into my_xml_table values (
      2  xmltype('
      3     test1
      4     test2
      5  
      6  
      7     test1
      8     test2
      9  ')
     10  );
    
    1 ligne créée.
    

    http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14259/xdb06stt.htm#sthref987

  • Fill to the right of the shuttle with the value/ID pair

    I have a command shuttle (P17_RATE_SHUTTLE), which is filled by the next LOV query:
    select rt.rate_description, rt.rate_id from rate_tbl rt where rt.active = 'Y' and rt.contract_type_id = :P17_CONTRACT_TYPE_ID and rt.rate_id not in (select rate_id from project_rate_lnk_tbl where project_id = :P17_PROJECT_ID);
    I have a Source value second query that fills the right side of the shuttle:
    select rt.rate_id from project_rate_lnk_tbl prl, rate_tbl rt where prl.rate_id = rt.rate_id and prl.project_id = :P17_PROJECT_ID;
    It works, but the right side of the shuttle is only displays the ID I want to display the text of rate_description and to always maintain the value/ID pair that will allow me to record the data placed in the right part of the shuttle.

    I have an Update button in my form that sends the page and executes the folliowing code to save the data (this works).
    declare
      tab apex_application_global.vc_arr2;
      cnt number;
    begin
      tab := apex_util.string_to_table (:P17_RATE_SHUTTLE);
      delete from PROJECT_RATE_LNK_TBL where PROJECT_ID = :P17_PROJECT_ID;
      for i in 1..tab.count loop
        insert into PROJECT_RATE_LNK_TBL (PROJECT_ID, RATE_ID) 
        values (:P17_PROJECT_ID, tab(i));
      end loop;
    end;
    Thank you
    Mark

    Yes, you try something against the nature of the issue of the shuttle.

    Kind regards

  • read the values of an array element and by sending a digital output to a designated channel according to the value read from the table

    Hello world

    could someone help me before I get out of my hair. Here's my problem.

    I read 3 values of an array of 3 elements i.e. 1,2,3. These values are then compared to a constant value, example if the first element of the array is 1 and it meets the comparison condition can send a digital camera of output for that channel on data acquisition

    I want to be able to send a value from a table to its corresponding comparison and then on its designated channel on the acquisition of data, the whole point of this is due to the fact the table element will not always read the value 1,2,3 for example could be 2,3,1

    Here's one the vi I have so far

    If someone could help it would be much appreciated

    all the best

    brand

    Take time to explore the many examples included with LabVIEW that cover the basics.

    -Indexing table

    -reading a spreadsheet file

  • Change the value of the static element

    Hi all

    I hope someone can help me with the following problem...

    I want the user to confirm an action (which defines a value of an element) and then I have a conditional sequence of dynamic actions if the value of an element Y. To make things as simple as possible, suggests following situation:

    I have a blank page with a single element (static text) on it named P1_YES_NO_FLAG, default value is N, the source field is empty and a region borders with 2 attached Dynamic actions:

    1)

    Sequence - 10

    Action - set

    Set the type - static assignment

    Y - value

    Article (s) - P1_YES_NO_FLAG

    2)

    Sequence - 20

    Action - alert

    Value of P1_YES_NO_FLAG is & P1_YES_NO_FLAG.

    The problem is that even if I see in the value text box is text alert is "value of N is P1_YES_NO_FLAG" and if I use the value of an item anywhere else (in the PL/SQL code: P1_YES_NO_FLAG), it always contains the value 'n'.

    Evolution of value through sql code

    BEGIN

    P1_YES_NO_FLAG: = 'Y ';

    END;

    or

    with the APEX_UTIL API

    BEGIN

    APEX_UTIL. SET_SESSION_STATE ('P1_YES_NO_FLAG', 'Y');

    END;

    did not help either.

    So, please, can someone explain what is happening behind the hood and what I need to do to ensure that the changed value "visible"? Thank you very much in advance.

    Kind regards

    Pavel

    Hello

    When you use the dynamic action that run PL/SQL, there is option to submit the Page elements.

    Enter to that point fields value of witch name (s) you want the session state value before executing PL/SQL code.

    Kind regards
    Jari

  • AF:iterator and get the values of a particular line

    Hello

    I use af:iterator to browse a set of results in the original Version.

    < af:iterator binding = "#{backingBeanScope.backing_subscribe.i1} '"
    value = "#{bindings." SubscriptionPublicView1.collectionModel}.
    var = "row".
    ID = "i1" >

    At each iteration, I display a row of data since my VO in a box.

    Each box has a Link command.

    In general, the bean of my support, I do something like this to get an iterator attribute out of sight.

    Line currentRow = getIterator("SubscriptionPublicView1Iterator").getCurrentRow ();
    int sid = (Integer) currentRow.getAttribute ("Sid");


    However, in this case, I always get the "sid" from the first record in the collectionModel and not the "sid" which corresponds to the commandLink selected by the user.

    What is the best way to do when using an af:iterator?

    Thank you

    Joel

    Joel,
    Take a look at this video: http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/classic_api_mistakes_part2/classic_api_mistakes_part2.html
    In there, Frank shows how to use af:iterator and af:forEach and to avoid warnings.

    It seems that you do not set the current line, so that you always get the value of the first row.

    Timo

  • How to solve the error ORA-00001 in SQL Insert?

    Hi all, I need your help appreciated.

    I do a plsql procedure that inserts a line according to the value of the slider, I have error oracle ORA-00001: unique constraint (constraint_name) violated.

    This message may appear if a duplicate entry exists at a different level: in the RDBMS MySQL, I have the syntax IGNORES to solve this error of duplication... and in Oracle?

    Thanks for your time and your advice.
    Miguelito

    user6317803 wrote:
    How to solve the error ORA-00001 in SQL Insert?

    ORA-00001 means table a unique/primary key / index and you attempt to insert a row with the key value already exists in the table. I'll assume table has a primary key on COUNTRY_ID. Then modify SQL for:

    SQL = "INSERT INTO COUNTRIES (COUNTRY_ID, COUNTRY_NAME, REGION_ID) SELECT"BZ","BLZ", 3 DOUBLE WHERE DOES NOT EXIST (SELECT 1 FROM COUNTRIES WHERE COUNTRY_ID ="BZ").

    There is a good chance COUNTRY table also has unique key/index on COUNTRY_NAME. If so use:

    SQL = "INSERT INTO COUNTRIES (COUNTRY_ID, COUNTRY_NAME, REGION_ID) SELECT"BZ","BLZ", 3 DOUBLE WHERE DOES NOT EXIST (SELECT 1 FROM COUNTRIES WHERE COUNTRY_ID = 'BZ' OR 'BLZ' = COUNTRY_NAME).

    SY.

  • Insert first in the results of the empty table in ORA-00001: unique constraint

    Hi all
    We are running Oracle 10 g. I modified an Oracle stored procedure instead of using the cursor for loops or bulk collect for use INSERT with the SELECT statement. When I run this version, I get ORA-00001 on first insertion. ONCE the exception is thrown. I checked that the array is empty. I don't think the ORA-00001 is the real cause of the problem. I have a syntax problem I'm not aware of.

    Here's the script:
     
    CREATE OR REPLACE PROCEDURE SP_LOAD_TEST
     (p_rpt_month    varchar2)
    IS
    
    --===================================================
    -- define exceptions
    --===================================================
    
    DUP_VAL_ON_INDEX              EXCEPTION;
    
    --===================================================
    -- read the USER data
    --===================================================
    CURSOR c_get_USERS_TBL IS
    select DIV_CD,
             WRKR_USER_ID,
             RPT_MONTH 
    
    from  USERS_TBL
     WHERE RPT_MONTH = P_RPT_MONTH
     ORDER BY DIV_CD,
                    WRKR_USER_ID;
       
    --===================================================
    -- get the location name from the TLOC_DMSN table 
    --===================================================
    CURSOR c_wrkr_loc_name ( p_wrkr_user_id varchar2) IS
    select WRKR_LOC
    
    from  .TLOC_DMSN
     WHERE TRIM(wrkr_user_id) = TRIM(p_wrkr_user_id);
    
    --===================================================
    -- define a place holder for each row fetched from each cursor
    --===================================================
    c_get_USERS_TBL_row            c_get_USERS_TBL%ROWTYPE;
    
    --===================================================
    -- define variables
    --===================================================
    
    v_elapsed_time                  VARCHAR2(50);
    v_elapsed_time_hh             FLOAT;
    v_elapsed_time_mi             FLOAT;
    v_elapsed_time_ss             FLOAT;
    v_mod_ss                          FLOAT;
    v_mod_mi                          FLOAT;
    v_elapsed_time_minus_ss   FLOAT;
    
    v_div_cd1                            USERS_TBL.div_cd%TYPE;
    v_wrkr_user_id1                  USERS_TBL.wrkr_user_id%TYPE;
    v_rpt_month1                      USERS_TBL.wrkr_user_id%TYPE;                 
    
    v_div_cd2                           USERS_TBL.div_cd%TYPE;
    v_wrkr_user_id2                 USERS_TBL.wrkr_user_id%TYPE;
    V_rpt_month2                    USERS_TBL.rpt_month%TYPE;
    v_usage_hour                    FACT_TBL.usage_hour%TYPE;
    v_bytes_sent                      FACT_TBL.bytes_sent%TYPE;
    v_bytes_rcvd                      FACT_TBL.bytes_rcvd%TYPE;
    v_total_bytes                      FACT_TBL.total_bytes%TYPE;
    v_div_nm                           FACT_TBL.div_nm%TYPE;
    v_wrkr_loc                         .TLOC_DMSN.WRKR_LOC%TYPE;
    v_wrkr_dspl_nm                 FACT_TBL.wrkr_dspl_nm%TYPE;
    v_wrkr_ph                         FACT_TBL.wrkr_ph%TYPE; 
    v_url                                 FACT_TBL.url%TYPE;
    v_divcd_userid                  VARCHAR2(12);
    v_prev_divcd_userid          VARCHAR2(12);
    v_prev_div_cd                    USERS_TBL.div_cd%TYPE;
    v_prev_wrkr_user_id          FACT_TBL.wrkr_user_id%TYPE;
    v_date_id                            NUMBER(10);
    v_user                                CHAR(8);
    v_seq_id                          NUMBER;
    v_insert_counter               NUMBER;
    v_mmyyyy                        VARCHAR2(6);
    v_mm                              VARCHAR2(2);
    
    
    BEGIN
    
    
    
    --===================================================
    -- initialize variables
    --===================================================
    v_div_cd1 := ' ';
    v_prev_div_cd := ' ';
    v_wrkr_user_id1  := ' ';
    v_wrkr_loc := ' ';
    v_rpt_month1 := ' ';  
    v_divcd_userid := ' ';
    v_prev_divcd_userid := ' ';
    v_prev_wrkr_user_id := ' ';
    v_insert_counter := 0;
    v_seq_id := 0;
    v_mmyyyy := ' ';
    
    --===================================================
    -- build run month in mmyyyy format before writing to TLOAD_LOG table
    --===================================================
    CASE 
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'JANUARY'    THEN    v_mm := '01';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'FEBRUARY'  THEN  v_mm := '02';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'MARCH'       THEN    v_mm := '03';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'APRIL'          THEN  v_mm := '04';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'MAY'            THEN    v_mm := '05';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'JUNE'           THEN  v_mm := '06';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'JULY'            THEN    v_mm := '07';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'AUGUST'       THEN  v_mm := '08';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'SEPTEMBER'  THEN    v_mm := '09';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'OCTOBER'      THEN  v_mm := '10';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'NOVEMBER'     THEN    v_mm := '11';
            WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'DECEMBER'     THEN  v_mm := '12';                
     END CASE;
    
    v_mmyyyy := v_mm||substr(p_rpt_month,INSTRB(p_rpt_month,'-',1,1)+1,4);
    
    
    --===================================================
    -- get the name of user running this procedure
    --===================================================
    v_user  := ' ';
    select user into v_user from dual;
    
    
    --===================================================
    -- get date id for the current date
    --===================================================
    v_date_id        := 0;
    select date_id into v_date_id from  .dwtime5 where DWDATE = trunc(sysdate);
    
    
    --===================================================
    -- read each ROW IN the users TABLE
    --===================================================
    -- Open the cursor and intialize the active set
    Open c_get_USERS_TBL;
    
    -- Retrieve the first row, to setup for the WHILE loop
    FETCH c_get_USERS_TBL into c_get_USERS_TBL_row;
    
    -- Continue looping while there are more rows to fetch
    WHILE c_get_USERS_TBL%FOUND LOOP
         v_div_cd1 := c_get_USERS_TBL_row.div_cd;
         v_wrkr_user_id1 := c_get_USERS_TBL_row.wrkr_user_id;
         v_rpt_month1 := c_get_USERS_TBL_row.rpt_month;
           
        CASE
        WHEN v_div_cd1 <> v_prev_div_cd THEN
                  v_prev_divcd_userid := v_divcd_userid;
                  v_divcd_userid := v_div_cd1||v_wrkr_user_id1; 
        WHEN v_wrkr_user_id1 <> v_prev_wrkr_user_id THEN
                 v_prev_divcd_userid := v_prev_div_cd||v_prev_wrkr_user_id;
                 v_divcd_userid := v_div_cd1||v_wrkr_user_id1;
        END CASE;
        
        
        Open c_wrkr_loc_name(v_wrkr_user_id1);
         Fetch c_wrkr_loc_name INTO v_wrkr_loc;
         IF c_wrkr_loc_name%NOTFOUND THEN
             v_wrkr_loc := NULL;
         END IF;
        Close c_wrkr_loc_name ;   
     
      v_seq_id := 0;
       select SEQ_USER_ID.nextval into v_seq_id from dual; 
       
       INSERT INTO  DETAIL_TBL_TEST(DETAIL_PK_ID,  
                                    DIVCD_USERID,
                                    WRKR_USER_ID,
                                    WRKR_DSPL_NM,
                                    RPT_MONTH,
                                    USAGE_HOUR,
                                    DIV_CD,
                                    DIV_NM,
                                    WRKR_LOC,
                                    BYTES_RCVD,
                                    BYTES_SENT,
                                    TOTAL_BYTES,
                                    WRKR_PH,
                                    URL,
                                    CREATE_DT,
                                    CREATE_USER,
                                    CREATE_PGM,
                                    UPDATE_DT,
                                    UPDATE_USER,
                                    UPDATE_PGM )
                             SELECT v_seq_id,
                                    v_divcd_userid,
                                    wrkr_user_id,
                                    wrkr_dspl_nm,
                                    rpt_month,
                                    usage_hour,
                                    div_cd,
                                    div_nm,
                                    v_wrkr_loc,
                                    bytes_rcvd,
                                    bytes_sent,
                                    total_bytes,
                                    wrkr_ph,
                                    url,
                                    SYSDATE,
                                    v_user,
                                   'SP_LOAD_DETAIL_TBL',
                                    SYSDATE,
                                    v_user,
                                   'SP_LOAD_DETAIL_TBL'
                              FROM  FACT_TBL, 
                                    DUAL                                                              
                              WHERE DIV_CD = v_div_cd1
                                AND TRIM(wrkr_user_id) = TRIM(v_wrkr_user_id1)                    
                                AND rpt_month = v_rpt_month1
                              ORDER BY DIV_CD,
                                       WRKR_USER_ID; 
    
         v_insert_counter := v_insert_counter + 1;
         IF v_insert_counter >= 500 THEN
        -- commit changes
            COMMIT;
            v_insert_counter := 0;
         END IF;
         
       FETCH c_get_USERS_TBL into c_get_USERS_TBL_row;
    END LOOP;
    
    Close c_get_USERS_TBL;
    
    
    --===================================================
    -- final commit
    --===================================================
    COMMIT;
    
    
    
    EXCEPTION
    WHEN DUP_VAL_ON_INDEX THEN
             DBMS_OUTPUT.PUT_LINE('Attempting to insert a row that already exists!!!');
    WHEN OTHERS THEN RAISE;
    --END;
     
    
    
    --===================================================
    -- procedure ended.
    --===================================================
    
    END;
    Thank you for your help,


    Seyed

    Hello

    I guess that the error you receive notice when you were in that sequence was ORA-02287: unauthorized by sequence number. This is because you had the ORDER BY clause in there. If you get rid of it, you can just use the sequence number in the insert without the need first to select it...

    With ORDER BY

    
    XXXX> insert
      2  into
      3      dt_t1
      4  SELECT
      5          dt_seq.NEXTVAL,
      6          SYSDATE
      7  FROM
      8      dual
      9  CONNECT BY LEVEL
     10      <=10
     11  ORDER BY
     12          1
     13  /
            dt_seq.NEXTVAL,
                   *
    ERROR at line 5:
    ORA-02287: sequence number not allowed here
    

    No ORDER OF

    XXXX> insert
      2  into
      3      dt_t1
      4  SELECT
      5          dt_seq.NEXTVAL,
      6          SYSDATE
      7  FROM
      8      dual
      9  CONNECT BY LEVEL
     10      <=10
     11  /
    
    10 rows created.
    

    Of course, I guess you want a new id for each row, as seems to be the name of the primary key column.

    HTH

    David

    Published by: Bravid on December 19, 2011 16:07

    Published by: Bravid on December 19, 2011 16:08

  • Get ORA-00001, but couldn't find the constraint

    Hi all

    Here's the scenario that I am facing: I have a table which has no constraints, but when trying to insert data into this table, I get some PRA-00001. When I search this constraint, I couldn't find it.
    SQL> set long 9999999
    SQL> execute dbms_metadata.set_transform_param(dbms_metadata.session_transform,'SEGMENT_ATTRIBUTES', false);
    
    PL/SQL procedure successfully completed.
    
    SQL> execute dbms_metadata.set_transform_param(dbms_metadata.session_transform,'SQLTERMINATOR', TRUE);
    
    PL/SQL procedure successfully completed.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  select dbms_metadata.get_ddl('TABLE','CRT_CONTRACTOR_PARTNERS_BK',user) DDL
      2* from dual
    SQL> /
    
      CREATE TABLE "PROJ"."CRT_CONTRACTOR_PARTNERS_BK"
       (     "CRR_YEAR" NUMBER(4,0) DEFAULT NULL,
         "CRR_NO" NUMBER(6,0),
         "NO" NUMBER(6,0),
         "NAME" VARCHAR2(60),
         "OTE_CODE" VARCHAR2(5),
         "PARTNERSHIP_PERC" NUMBER(5,2),
         "CNT_CODE" VARCHAR2(5),
         "PASSPORT_NO" VARCHAR2(15),
         "FILTERED_NAME" VARCHAR2(60),
         "APP_ID" NUMBER
       ) ;
    
    
    
    SQL> show user
    USER is "PROJ"
    SQL> insert into "PROJ"."CRT_CONTRACTOR_PARTNERS_BK" select * from "PROJ"."CRT_CONTRACTOR_PARTNERS_BK";
    insert into "PROJ"."CRT_CONTRACTOR_PARTNERS_BK" select * from "PROJ"."CRT_CONTRACTOR_PARTNERS_BK"
    *
    ERROR at line 1:
    ORA-00001: unique constraint (PROJ.PARTS_PK) violated
    
    
    SQL> SELECT constraint_name FROM all_constraints WHERE table_name='CRT_CONTRACTOR_PARTNERS_BK';
    
    no rows selected
    
    SQL> ed
    Wrote file afiedt.buf
    
      1* SELECT constraint_name FROM all_constraints WHERE constraint_name='PARTS_PK'
    SQL> /
    
    no rows selected
    
    SQL> select * from v$version;
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE     10.2.0.1.0     Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Can you help me solve this mystery?

    Kind regards

    Riaz

    Hello

    You can also post the output below.

    select index_name from all_indexes where table_name = 'CRT_CONTRACTOR_PARTNERS_BK'
    

    Assumption, that you are connected to aid user proj.

    Concerning
    Anurag

  • Merger with subquery causes ORA-38101 invalid column to INSERT the VALUES C

    What follows is a slightly shortened version of a SQL statement that causes the error.
              MERGE INTO applicant_matches m_table USING
              (
                   SELECT DISTINCT
                               s.student_id,
                               a.term_scope_id,
                               a.first_name,
                             a.last_name,
                             a.ssn_visa,
                             a.birth_date,
                             ...     
                         
              ) m_list ON
              (m_list.student_id =     m_table.student_id AND
                   m_list.first_name     =     m_table.first_name AND
                   m_list.last_name =     m_table.last_name AND
                   m_list.birth_date     =     m_table.birth_date AND
                   m_list.ssn_visa =     m_table.ssn_visa AND
                   m_list.term_scope_id =     m_table.term_scope_id)
    
              WHEN NOT MATCHED THEN
                     INSERT (m_table.student_id, m_table.term_scope_id, m_table.ssn_visa, m_table.first_name, m_table.last_name,
                           m_table.birth_date, m_table.ssn_match, m_table.dob_match, m_table.soundex_match, m_table.name_match, m_table.past_present)
                     VALUES
                        (m_list.student_id, m_list.term_scope_id, m_list.ssn_visa, m_list.first_name, 
                             m_list.last_name, m_list.birth_date, m_list.ssn_match, m_list.dob_match, m_list.soundex_match, 
                             m_list.name_match, 
    
    
                             (SELECT                    
                   'A'
                        FROM  term_scope ts
                             JOIN campus_term ct ON ts.campus_term_id=ct.campus_term_id
                             WHERE
                             ts.term_scope_id = 5  )
               
               )
               
    I've simplified the request a bit to see what combination of things are the cause of the problem, that is why she always inserts 'A' in m_list.past_present (a CHAR (1)) and always use 5 for the term_scope_id.

    On the SELECT subquery I get one
    ORA-38101 invalid column in the INSERT VALUES Clause: string "ts". "" term_scope_id ".

    However, if I leave the
    JOIN the ct campus_term ON ts.campus_term_id = ct.campus_term_id
    Then, the query works fine.

    Anyway, it must be insert 'A', so I can't imagine what that JOIN has to do with anything anyone. The term_scope_id is valid. It won't let you do a join in a subquery for a merge insert?

    BTW: I'm using Oracle Database 11 g Enterprise Edition Release 11.1.0.6.0 - Production

    Try using the old join syntax

    Select 'x '.
    from t1, t2
    where t1.col = t2.col
    and t2.other_col = using_set.other_col

Maybe you are looking for