For the Primary Key Field with the combination of other fields

Hai
I Have a problem in creating trigger for the following
the problem goes like this..
i have a table with the fields
fld1 (varchar2(6) fld2(varchar2(20)) fld3 (number)
the fld1 is a primary key.
here in this table i am inserting the values ..
At the time of inserting the fld1 should get the part value of fld2
say if new value for fld2 is "SAM & CO" then
it should take the first letter and then followed by the sequence..
i.e., the fld1 is the combination of a
letter + firt letter of the fld2 + sequence
fld1 fld2 fld3
CS001 SSSSS 324234
CP001 PPPPP 5345435
CS002 SSSS 53543543
Here the Sequence should vary depending on the alphabet of the fld1
if P the the Sequence should be the next number of fld1 to P
i.e.,
if i add the value like this
insert into tname(fld2,fld3) values('PQQQQ',34343)
then it should be inserted as
CP002 PQQQQ 34343
I need the solution for this..
Thanx
Gaya3
thanx
gaya3

There are not enough details to be sure since you have not provided the mappings. From just the error, it looks like you are using the tableC.tableA_ID field as the foreign key in the ManyToOne relationship to A, but have marked it as insertable=false, writeable=false, meaning that it cannot be updated or used for inserts.
Either make it writable (set the settings to true), or add another basic mapping/attribute in the entity for TableC that maps to the field which you can use to set when you insert a new tableC entity. A simple example is available at
http://wiki.eclipse.org/EclipseLink/Examples/JPA/2.0/DerivedIdentifiers
Best Regards,
Chris

Similar Messages

  • Knowing the primary key columns of the given table

    Hi,
    How can I get the primary key columns of the given table?
    Regards,
    Sachin R.K.

    You can find the constraint_name from all_constraints/user_constraints for constraint_type = 'P' (which is the primary key constraint).
    And then see which columns are in for the constriant_name
    in all_cons_columns/user_cons_columns view.
    Below is the example
    select acc.column_name from
    all_cons_columns acc, all_constraints ac
    where acc.constraint_name = ac.constraint_name
    and acc.table_name = 'DEPT' AND acc.owner = 'SCOTT'
    and ac.constraint_type = 'P'
    Hope this helps
    Srinivasa Medam

  • Batch processing problem: Seeing the primary key (id) in the test cases...

    Another problem we seem to be having is how to read the primary key into a base attribute of an entity.
    In batch processing, we may define the "id" as the primary key on the table. We need to get that id and the foreign key ids into the base attributes in the rule set...
    How do we go about doing that?

    Perhaps better, if you could give me a sample xml config with global and one entity. The only attribute in the entity should be the id... The id should be the primary key in both OPA and Oracle...
    The global table in oracle would contain a single column with the global id.
    The child table in oracle would contain 2 columns -> one for the global ref id and one for the child key...
    I think you will find problems.
    As a note we have duct-tape solved this by creating views and making column copies in the views of the child id and then mapping the id in oracle to the duplicate column in the view.
    So our child view contains the child table with the child id repeated twice so that we can map...

  • Help me to return the primary key after insert the row

    Hi
    I am using JDBC, with oracle database. i have welformed normalization tables .i am inserting parent table with dynamic sequence number as primary key .after inserting i need inserted row primary key .how to get the inserted row primary key with out using select statement
    please help me
    Thanks in advance
    Edited by: 849614 on Apr 4, 2011 5:41 AM
    Edited by: 849614 on Apr 4, 2011 5:54 AM

    Hello
    If I undestand you, I think you should do this:
    Connection conexion = dataSource.getConnection();
    int idCenter=-1;
    String query = "Begin Insert into CENTER (NAME_CENTER) values (?) returning ID_CENTER into ?; end";
    callableStatement = conexion.prepareCall(query.toString());     
         callableStatement.setString(1, "Center name");               
         callableStatement.registerOutParameter(2, java.sql.Types.INTEGER);
              callableStatement.executeUpdate();
              idCenter=callableStatement.getInt(2);
    This way, you have in idCenter the primary key of the line that has just been inserted.
    Edited by: cris on 05-abr-2011 5:28

  • Every 2 days i lose connection to home network and when i put the network key in (with the caps) it dismisses it

    every 2 days i lose connection ,since they did software upgrade in oct. now it just dismisses me when i insert the network key for password. i am using the caps

    Look at iOS Troubleshooting Wi-Fi networks and connections  http://support.apple.com/kb/TS1398
    iPad: Issues connecting to Wi-Fi networks  http://support.apple.com/kb/ts3304
    Additional things to try.
    Try this first. Turn Off your iPad. Then turn Off (disconnect power cord) the wireless router & then back On. Now boot your iPad. Hopefully it will see the WiFi.
    Change the channel on your wireless router. Instructions at http://macintoshhowto.com/advanced/how-to-get-a-good-range-on-your-wireless-netw ork.html
    How to Quickly Fix iPad 3 Wi-Fi Reception Problems
    http://osxdaily.com/2012/03/21/fix-new-ipad-3-wi-fi-reception-problems/
    If none of the above suggestions work, look at this link.
    iPad Wi-Fi Problems: Comprehensive List of Fixes
    http://appletoolbox.com/2010/04/ipad-wi-fi-problems-comprehensive-list-of-fixes/
    Fix iPad Wifi Connection and Signal Issues  http://www.youtube.com/watch?v=uwWtIG5jUxE
     Cheers, Tom

  • Having issues with populating a Text Field with data from 2 other fields

    I have 3 fields Tools_1a_pri, Tools_1a_pri_other, Tools_1a_pri_txt.
    Tools_1a_pri is a drop down combo with a predefined list. One of the options is "Other".  When "Other" is selected, the text field Tools_1a_pri_other becomes visible for users to enter the name of the other tool.
    The Tools_1a_pri_txt is a text field with a calculation that shows either text stating that no tool has been selected or the Tools_1a_pri & or Tools_1a_pri_other.
    When I select one of the predefined tools, everything works.  When I select other, it appears that nothing has changed.  It requires that I click on another field before it populates.  This is confusing to the user.
    Tools_1a_pri   Validate code
    this.getField("Tools_1a_pri_Other").display = event.value=="Other" ? display.visible : display.hidden;
    Tools_1a_pri_txt  Calculation code
    //if nothing is selected, do the following
    if (getField("Tools_1a_pri").value.length < 2) {
    event.target.textColor = color.red
    event.value = "No primary tool identified";
    }else if (getField("Tools_1a_pri").value != "Other") {
    //otherwise do this if other is selected
    event.target.textColor = color.black
    event.value = getField("Tools_1a_pri").value;
    }else if (getField("Tools_1a_pri").value = "Other") {
    //otherwise do this if other is not selected
    event.target.textColor = color.black
    event.value = getField("Tools_1a_pri").value + " - " + getField("Tools_1a_pri_Other").value;

    You made the classic mistake of using the assignment operator in an if-statement instead of the comparison operator. Change this line:
    } else if (getField("Tools_1a_pri").value = "Other") {
    To this:
    } else if (getField("Tools_1a_pri").value == "Other") {

  • How to get the PRIMARY KEY of a table at runtime ???

    Hi everybody,
    My requirement is to update a z-table at runtime according to the data given ata runtime. So the main difficulties for me is that whenever I tried to update the table based on the data given in UI many rows are getting updated as these fields are not unique. So I think if I can get the PRIMARY KEY along with these given fields then I can update only one row at a time.
    So Can anyone suggest me how to get PRIMARY KEY of a table based on the data in UI..??
    Any suggestions will be appreciated..
    Thanks,
    Sekhar

    U will get primary keys of transparent tables using FM "REUSE_FIELDCALATLOG_MERGE".
    pass tyour table name and u will get fieldcatalog filled. In tht their is a field called "KEY" if it has 'X' then tht field is a primary key of transparent tables & if it has "space" then it is not a primary key...
    Or else you can try with 'DDIF_TABT_GET'
    Or try this code
    PARAMETERS: p_table TYPE tabname OBLIGATORY.
    DATA: go_strucdescr   TYPE REF TO cl_abap_structdescr,
          gt_tab_fields   TYPE ddfields.
    FIELD-SYMBOLS: <gwa_tab_field> TYPE dfies.
    TRY .
    *   Get the details of the DDIC table
        go_strucdescr ?= cl_abap_elemdescr=>describe_by_name( p_table ).
      CATCH cx_sy_move_cast_error .
        MESSAGE 'Error while casting' TYPE 'S'. RETURN.
    ENDTRY.
    * Check if input is a DDIC table
    CHECK go_strucdescr->is_ddic_type( ) = 'X'.
    * Get the details of the table fields
    gt_tab_fields = go_strucdescr->get_ddic_field_list( ).
    * Display the Key fields of the table
    LOOP AT gt_tab_fields ASSIGNING <gwa_tab_field> WHERE keyflag = 'X'.
      WRITE: / <gwa_tab_field>-fieldname.
    ENDLOOP.

  • Key value does not currently exist in the primary key table error

    Im testing out a form and creating a new insert once all the fields are filled in it wont allow me to move on and comes up with this error message;
    key value does not currently exist in the primary key table
    Is this becuase the form contains foriegn keys which reference different tables which fields are not dispalyed on this form?
    If so how to I link the other forms together so that when i create a new record in this form it will automaticaly create the primary key entry in the other form to allow the insert of the referenced foreign key in this form?
    does this make sense?

    It seems that it has the table in which you'r inserting is a foreign key table.
    Take the emp& dept table example in the schema scott/tiger.
    Say we have deptno 10, 20, 30, 40 in the dept table.
    We make a form for emp table and insert into this form.
    Now, we'r bound to insert deptno 10, 20, 30, 40 into this emp form. This form will not allow us to insert deptno 50 as it doesn't exist in the primary key column in dept table.
    Obviously if a department doesn't exist in the company, it doesn't make sense to assign the employees to that department.
    So for this purpose, we need to add a department in the dept table then we can insert values in the emp table for that department.
    For this purpose, I suggest to make a button on the mp form and invoke the dept form and add a new department to it and then insert into emp table.
    The same scenario can be applied in your case.

  • How to find out the primary key column of a database table?

    Hi
    Given the following scenario :
    Given an inputfield, the user can enter a table name. The code behind will base on the table name given and extract out the fieldname of the primary key and concatenate the two field to become a unique string.
    Eg. Order ID and Product ID make out a primary key.
    How do i achieve that? Any code sample?
    Regards,
    Rayden

    Check the below code :
    REPORT zTest no standard page heading.
    data : i_DD03P like DD03P occurs 0 with header line.
    data v_table like DCOBJDEF-NAME.
    parameters : p_table like dd02l-tabname.
    start-of-selection.
    v_table = p_table.
    CALL FUNCTION 'BDL_DDIF_TABL_GET'
      EXPORTING
        NAME                = v_table
       STATE               = 'A'
       LANGU               = 'E'
    IMPORTING
      GOTSTATE            =
      DD02V_WA            =
      DD09L_WA            =
    TABLES
       DD03P_TAB           = i_DD03P
      DD05M_TAB           =
      DD08V_TAB           =
      DD12V_TAB           =
      DD17V_TAB           =
    EXCEPTIONS
       ILLEGAL_INPUT       = 1
       OTHERS              = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    loop at i_DD03P.
    if i_dd03p-KEYFLAG = 'X'.
    write:/ 'Key fields', i_dd03p-FIELDNAME.
    endif.
    endloop.
    Thanks
    Seshu

  • Primary key column as the key of the cache

    Hi All,
    I am implementing a cache backed by HibernateCacheStore for a table. Cache contains key as the primary key of the table and value as the entire row in object format. the primary key is generated by hibernate.
    when i am inserting new rows through coherence (i.e cahce.put) what persistence strategy should is use to set the cache entries.
    I cannot use cache.put (key, value) because key is the primary key of the table which is not generated yet.
    and if i use the session.save(value) the persisted value is not in the cache.
    is there any mechanism to map the cache key as the primary key column of the table.
    Regards
    S

    Hi -
    Using Hibernate as a CacheStore for Coherence, the key of the cache entry is also the key of the entity
    being stored via Hibernate. For this reason keys for new cache entries must be generated ahead of time.
    A UUID can be used. The commons component of the Incubator project has a key generation utility that
    might be worth looking at.
    /Mark

  • How to khow how many foreign key are referenceing the primary key

    sir i would like to know that how many foreign key are referencing the primary key of a table
    is any command to know the table name
    please suggest
    thanks in advance..

    In the query below, table_name is the name of the table whose primary key is referenced.
    SELECT b.owner owner
    ,b.constraint_name foreign_key
    ,b.constraint_type constraint_type
    ,b.table_name referencing_table
    ,b.r_constraint_name primary_key
    ,c.table_name referenced_table
    ,c.column_name referenced_column
    FROM all_constraints a
    ,all_constraints b
    ,all_cons_columns c
    WHERE a.owner = b.owner
    AND a.table_name = :table_name
    AND a.constraint_type = 'P'
    AND b.r_constraint_name = a.constraint_name
    AND b.constraint_type = 'R'
    AND c.constraint_name = a.constraint_name
    AND c.owner = a.owner;
    If the name of the primary key is known, the query below
    select * from all_constraints where constraint_type = 'R' and r_constraint_name = :pk_name

  • Primary Key Issue With Creating Tables

    Hi,
    I have the following scripts to create my two tables in oracle 10g, i was wondering wether or not i had correctly set up my primary key or if there is a better way of doing it than the way i have.
    Here are my two scripts for my tables:
    CREATE TABLE CUSTOMER (
    fname varchar2(15) NOT NULL,
    lname varchar2(20) NOT NULL,
    age varchar2(3) NOT NULL,
    custAreaCode number(5) NOT NULL,
    custNumber number(6) NOT NULL,
    constraint cust_pk PRIMARY KEY (custAreaCode),
    constraint cust_pk2 PRIMARY KEY (custNumber),
    constraint age_chk CHECK (age >=18 AND age <150)
    CREATE TABLE PHONECALL (
    startDateTime smalldatetime NOT NULL,
    custAreaCode number(5) NOT NULL, ---Reference PK From Customer Table
    custNumber number(6) NOT NULL, ---Reference PK From Customer Table
    dialledAreaCode number(5) NOT NULL,
    dialledNumber number(6) NOT NULL,
    crgPerMinute number number (3,1) NOT NULL,
    endDateTime smalldatetime NOT NULL));
    I am not sure if i have referenced the primary keys correctly in the PHONECALL table.
    Thanks in advance :)

    Hi,
    You want like this below ? I think that smalltime data type is not a valid type. Other thing, this is not a rule, but I advice you to put the primary key columns as the first columns of your table. One question: There is no PK on the phonecall table ?
    SGMS@ORACLE10> create table customer (
      2  custareacode number(5) not null,
      3  custnumber number(6) not null,
      4  fname varchar2(15) not null,
      5  lname varchar2(20) not null,
      6  age varchar2(3) not null,
      7  constraint cust_pk primary key (custareacode),
      8  constraint cust_uk unique (custnumber),
      9  constraint age_chk check (age >=18 and age <150)
    10  );
    Table created.
    SGMS@ORACLE10> create table phonecall (
      2  custareacode number(5) not null constraint fk_phone_cusarecode_customer references customer,
      3  custnumber number(6) not null constraint fk_phone_custnumber_customer references customer,
      4  startdatetime date not null,
      5  dialledareacode number(5) not null,
      6  diallednumber number(6) not null,
      7  crgperminute number (3,1) not null,
      8  enddatetime date not null);
    Table created.
    SGMS@ORACLE10> select table_name,constraint_name,constraint_type from user_constraints
    2 where table_name in ('CUSTOMER','PHONECALL') and constraint_type in ('P','U','R');
    TABLE_NAME                     CONSTRAINT_NAME                C
    CUSTOMER                       CUST_PK                        P
    CUSTOMER                       CUST_UK                        U
    PHONECALL                      FK_PHONE_CUSARECODE_CUSTOMER   R
    PHONECALL                      FK_PHONE_CUSTNUMBER_CUSTOMER   RCheers

  • Exception: non-read-only mapping defined for the primary key field

    Hello.
    I'm new to Oracle and I created Java EE Web Project.
    And I created entities from tableA, tableB, tableC from my database.
    tableA has foreign key to tableB and has unidirectional Many-to-One relationship. tableC has two primary keys and one of these is foreign key to primary key in tableA. tableC also has unidirection Many-to-One relationship to tableA.
    Then I created session bean and data control from it, in design window, created read-only table from tableA.
    And I selected columns in tableA and also in tableB.
    I ran the application and saw the following exception in log window.
    Local Exception Stack:
    Exception [EclipseLink-46] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.DescriptorException
    Exception Description: There should be one non-read-only mapping defined for the primary key field [tableC.tableA_ID].
    Descriptor: RelationalDescriptor(mypack.tableC --> [DatabaseTable(tableC)])
    tableA_ID is a primary key in tableA.
    How can I solve this error?
    Please help me.
    Edited by: 900471 on 2011. 12. 3 오전 5:32
    Edited by: 900471 on 2011. 12. 3 오전 5:33
    Edited by: 900471 on 2011. 12. 3 오전 5:33
    Edited by: 900471 on 2011. 12. 3 오전 5:34

    There are not enough details to be sure since you have not provided the mappings. From just the error, it looks like you are using the tableC.tableA_ID field as the foreign key in the ManyToOne relationship to A, but have marked it as insertable=false, writeable=false, meaning that it cannot be updated or used for inserts.
    Either make it writable (set the settings to true), or add another basic mapping/attribute in the entity for TableC that maps to the field which you can use to set when you insert a new tableC entity. A simple example is available at
    http://wiki.eclipse.org/EclipseLink/Examples/JPA/2.0/DerivedIdentifiers
    Best Regards,
    Chris

  • How can we export the Primary key values (along with other data) from an Advantage database?

    One of our customers is moving from our application (which uses Advantage Database Server) to another application (which uses other database technology). They have asked us to help export their data, so that they can migrate it to another database system. So far, we have used the Advantage Data Architect (ARC32) "Export Table Structures as Code" functionality to generate SQL. We used the "Include existing data" option. The SQL contains the necessary code to recreate the tables and indexes. The customer's IT staff will alter the SQL statements as necessary for their new system.
    However, there is an issue with the Primary Keys in these table. The resulting INSERT statements use AutoInc as the type for the Primary Key in each Table. These INSERT statements contains "DEFAULT" for the value of each of these AutoInc fields. The customer would like to output an integer value for each of these Primary Key values in order to maintain referential integrity in their new system.
    So far, I have not found any feature of ARC32 that allows us to export the Primary Key values. We had been using an older version of ARC32, since our application does not use the latest version of ADS. I did download the latest version of ARC32 (11.10), but it does not appear to include any new functionality that would facilitate doing this sort of export.
    Can somebody tell me if there is such a feature in ARC32?
    Or, is there is another Advantage tool to facilitate what we are trying to accomplish?
    If there are no Advantage tools to provide such functionality, what else would you suggest?

    George,
      It sounds like the approach you are using is the correct one. This seems to be the cleanest solution to me especially since the customer is able to modify the generated SQL statements for their new system.
      In order to preserve the AutoInc values I would recommend altering the table and changing the field datatype from AutoInc to Integer. Then export the table as code which will export the actual values. After the tables have been created on the new system they can change the field datatype back to an AutoInc type if necessary.
    Regards,
    Chris Franz

  • How do I obtain the next number for a Primary Key using an ADF View Object?

    I have two separate View Objects (A & B) for the same Entity Object. View Object A does a SELECT on all of the fields in the table. This View Object is where I execute my adds and updates. View Object B is only used to retrieve the next number for the primary key. This is done so that when I add a row to the database, I always get the max number of the primary key and add one to it. I accomplished this by setting the SQL mode to Expert and using the SQL: "SELECT MAX(NBR) AS MAX_NUMBER FROM TABLE_1". This may be overkill having a seperate View Object for this, but so far this is the only way I have found to obtain the next number. However, I have discovered that this way does not always work.
    The problem I'm running into is when I try to add multiple records to View Object A without committing the transaction between each add. Because View Object B is disconnected from View Object A, the MAX_NUMBER of View Object B comes back with the same number for each add I do on View Object A. So I know I must retrieve the MAX_NUMBER from View Object A.
    I've tried using the following code in my Table1ViewImpl class:
    this.setQuery("SELECT MAX(Table1.NBR) AS MAX_NUMBER FROM TABLE_1 Table1");
    this.executeQuery();
    The view object now has what I want, but I have yet to figure a way to extract the MAX_NUMBER out of the View Object. I've also looked into using the method addDynamicAttribute() but I can't figure out any way to set the attribute with the MAX_NUMBER.
    I can't be the only one trying to retrieve the next number from a database table using ADF. Can anyone help me with this? FYI - I'm using JDev 10.1.3 EA.

    You missing the point.
    On a multi-user db knowing the next highest number doesn't guarantee the number will be available when it comes time to commit the record. You can prove this to yourself by opening two instances of your app and do whatever you do to add a new record to your VO. Both will assume the same number, and when you commit an error will be generated
    You must use sequences to avoid the possibility of duplicate keys. If you are trying to avoid gaps in your numbering then you need to convince yourself why this is necessary.

  • How can I obtain the primary key of a table for an entity relation?

    hello everybody
    I am doing a consultation to a table in my data base, good this table has alone two fields, the first one is the code or pk and the second one is the description, to be presisos they are names of city and code.
    From the beginning!!: This method this one in another class that is a Dialog that is going to call to the class SelecPlace ();
      SelecPlace sl = new SelecPlace();
    public void capturarLugar(){  //  Simple void method in the mentioned class
            String place = txtProcedencia.getText() ;  //  a JTextField
            sl.executeStatement(place) ;                  
        }ok, now we see part of the code of the class SelectPlace
    public class SelecPlace extends AbstractTableModel{
        Connection con = null;
        Statement sentencia = null ;
        ResultSet rs = null;
        ResultSetMetaData rsmd = null ;
        String[] nameColum = {} ;
        Vector datos = new Vector() ;
        public SelecPlace() { }
        public void executeStatement(String query){
          try{
             con = DBManager.getConnection() ;
             sentencia = con.createStatement(rs.TYPE_SCROLL_INSENSITIVE,
                                                                          rs.CONCUR_UPDATABLE) ;
             String sql = "select * from Place where descripcion like %"+query+"%'";
              rs = sentencia.executeQuery(sql) ;
              rsmd = rs.getMetaData();
              int nroColumnas = rsmd.getColumnCount() ;
              nameColum = new String[nroColumnas] ;
              //obtengo los nombres de columnas en cache
               for(int colum = 0; colum < nroColumnas; columna++){
                    nameColum[colum] = rsmd.getColumnLabel(columna + 1) ;
               datos = new Vector();
                while(rs.next()){
                    Vector newRow = new Vector();
                    for(int i = 0; i < getColumnCount(); i++){
                    newRow.addElement(rs.getObject("place_ID"));
                    newRow.addElement(rs.getObject("description"));
                    datos.addElement(nuevaFila);
                fireTableChanged(null);
            }catch(SQLException e){
                System.err.println(e);
                e.printStackTrace(System.err);
                System.out.println("error in statement");
            }catch(ClassNotFoundException cnfe){
                System.err.println(cnfe);
        }Ok, this code me works and I obtain in this case the field description of the table Place
    Now my question is, how can I obtain the primary field of my table?
    I need this value of this field that in the base of information in a bigint, and to take it to the first class before mentioned, for that I am working with a data base related

    Certain duffymo and everyone!!, good I give you my scheme:
    And generalizing my question, I want to obtain the value of the primary key of a table in the database, I obtain more values of the same row, but I need the primary key, and you see one with the primary key I want to turn a Long and it to insert with code java in foreign clave in another table of the database
    Good of this form I believe that it would not be breaking the integrity relacional of the tables

Maybe you are looking for