Problem inserting new line in a VO with SQL functions and subqueries

Hello

I use JDeveloper 10.1.3.4 and and stuck with insertion of a new line when the values to insert into some fields of the new line are returns of SQL functions and subqueries.

At the sqlplus prompt, the following sql statement is tested and developed successfully:
insert into VALIDATIONS values (
   '111223333', 'JANE', 'DOE',
   SYSDATE,
   (select to_char(sysdate, 'yymmdd') from dual)||
   (select to_char(count(TRANSACTION_DATE)+1,'fm0999') from VALIDATIONS
      where trunc(TRANSACTION_DATE) = to_char(sysdate))
);
Note that the values for the fields of 4th and 5th are returns of subqueries and SQL functions.

Ideally, it would be simple to assemble a SQL and executed him as he did to the old way of servlet:
String sql = "insert into VALIDATIONS values ('" + id + "', '" + firstName + "', '" + lastName + "', SYSDATE, (select to_char( ......)))";
statement.executeUpdate(sql);
I'm not sure it can be done in JDeveloper, and it was not found in the developer's guide. What I found was rather:
// 1. Find the ServiceRequests view object instance.
ViewObject svcReqs = am.findViewObject("ServiceRequests");
// 2. Create a new row and insert it into the row set
Row newSvcReq = svcReqs.createRow();
svcReqs.insertRow(newSvcReq);
// 3. Show effect of entity object defaulting for Status attribute
System.out.println("Status defaults to: "+newSvcReq.getAttribute("Status"));
// 4. Set values for some of the required attributes
newSvcReq.setAttribute("CreatedBy",308); // Nancy Greenberg (user)
Date now = new Date(new Timestamp(System.currentTimeMillis()));
newSvcReq.setAttribute("RequestDate",now);
newSvcReq.setAttribute("ProdId",119); // Ice Maker
newSvcReq.setAttribute("ProblemDescription","Cubes melt immediately");
// 5. Commit the transaction
am.getTransaction().commit();
In my case, it would be OK for the first three fields as shown below (in the code of transactionsRecords is a display object). But what about the 4th and 5th fields?
Row newTransaction = transactionsRecords.createRow();
transactionsRecords.insertRow(newTransaction);
newTransaction.setAttribute("StudentId", id);
newTransaction.setAttribute("FirstName", firstName);
newTransaction.setAttribute("LastName", lastName);

newTransaction.setAttribute("TransactionDate", <how to put "SYSDATE" here?>);
newTransaction.setAttribute("ConfirmNumber", <how to put subqueries here?>);
A big thank you to those who know or have experience before!


Newman

Newman,
You can do this via a procedure call. This technique is described here
I guess you can't do this directly in the EO or VO.
You can do it the old way to create a prepared directly query and call it as you described. To get the declaration use getDBTransaction () .createPreparedStatement (...) method available in the module of your application.
Be aware of the implications using the given solution. The framework doesn't know anything of what you are doing. So to see the changes that you used to update the tables that you change.

Timo

Tags: Java

Similar Questions

  • I want to go back to the previous version of 2014.2.  .3 is far too buggy and full of error messages. Create problems because I'm on a timeline with my client and I don't have time to fool around with all the problems.

    2014.3 is far too buggy and full of error messages. Create problems because I'm on a timeline with my client and I don't have time to fool around with all the problems.

    You don't mention what you have encountered errors? Workaround for the problem more frequently reached here is Re: error in Muse: object UID:U6875 has two (or more) owners: U3633 and U3165

    If you have a copy of your .muse file that has not been saved by using 2014.3, you can downgrade by uninstalling Muse, and then choose the previous Version in the drop-down list of filters in the Panel of Apps from the desktop creative cloud application. There will be a popup next to the Muse, where you can select a version prior to install.

  • problem when inserting new line

    Hello
    I create a new table table1 (attr1 (primary key), atrrib2, attrib3)
    and I tried to do an insert,
    insert into table1 (atrrib2, attrib3) values (val2, val3);
    I am also a trigger on the table to generate the primary key:

    CREATE OR REPLACE TRIGGER TIB_TABLE1 before INSERT
    Table 1 FOR each line
    declare
    integrity_error exception;
    all errno;
    ErrMsg tank (200);
    entire dummy;
    found in the BOOLEAN;
    Start
    SELECT SEQ_Table1.NEXTVAL IN: double new.attr1;
    exception
    When integrity_error then
    raise_application_error (errno, errmsg);
    end;

    but when I try to do an insert, it returns this error:

    ORA-00001: unique constraint (PK_TABLE1) violated
    ORA-06512: at "dispatch_trt", line 14
    someone has an idea?

    Thank you
    Concerning
    Laes_

    No he used. You must set the start value of the sequence as a Max value of existing data so that you don't get duplicate data.

  • Insert new line in VO, engaging, and then call vo.executeQuery () does not display the newly created line.

    Hi guys

    I use jdev 12.1.2.

    I have a question about stale view object and entity data object.  My use case is: I have an af:table bound to data that I use to insert a new row in the database.  I create the line with a call from createWithParams, and everything works fine with it.  I call commit on the application module that contains the view object, and the data is correctly inserted in the database table.  Then, as part of my needs, I call vo.executeQuery () on the view object, however the newly inserted row is not present in the af: table or view object.  The line does not appear until I leave my application and return to it.  Once I do this, the line is in the object view and appears correctly in the table.

    It is not enough that I need the view object to be aware of the new line (s) without having to restart the application.  Y at - it a setting I am missing in my display object?  I guess my entity object contains stale data, but I don't know how to refresh its data.  Thanks for reading.

    Lance

    Hello

    you use a viewCriteria, so the value of this method of execution both (database and memory) in the Panel of viewCriteria

    try it once

    Thank you

  • ODI - Type 2 SCD - Insert new line error

    Hi all

    For the size, I have a surrogate key, a touch of natural and a column with 'Overwrite the change', start_date, end_date, current_record_ind. When I run the interface with the default CPC Type 2 for SQl server, it works fine. But when I change only one column of ' crush on the evolution of the "to"insert a new line", it fails at the stage of the update. This who should I look for the attachment of the anf.

    Thanks for your time and your help.

    On the left side, in the designer, your project, you have the list of your KM. To add a new option, right-click on the name KM and select the Add option. You can expand the KM (+) to display the current options.

    I'll do a printscreen tonight if you can't find it.

  • Interlink with Sql server and Oracle

    Hello

    We have some data in SQL Server.
    We need to link SQL Server and Oracle Database. To make reports in Oracle Apex.

    Please someone guide me to interconnect with Oracle database

    Kind regards
    Thérèse

    Therese,
    You can find more information on gateways in this available in My Oracle Support note-

    Note to master for the Oracle Gateway (Doc ID 1083703.1) products

    Kind regards
    Mike

  • Need to create a new line in the table with the same data as the primary key, but new PK

    Hello gurus,

    I have a table with a column as a primary key, I need to create a new row in the table, but with the same data in one of the lines, but with different primary keys, focus a double row with key primary diferent...

    Any ideas of how it can be done without much complication?

    Thanks in advance for your answer.

    Agress,
    Karim idrissi

    user9970447 wrote:
    Hello gurus,

    I have a table with a column as a primary key, I need to create a new row in the table, but with the same data in one of the lines, but with different primary keys, focus a double row with key primary diferent...

    Any ideas of how it can be done without much complication?

    Thanks in advance for your answer.

    Agress,
    Karim idrissi

    something like

    insert into mytable values ('literal for new pk',
                                           select non-pk-1,
                                                    non-pk-2,
                                                    non-pk-n
                                           from mytable
                                           where pk-col = 'literal for existing pk')
    
  • 2.1.0.62: problem with Package.Functions and Unit Tests

    I like the new Sqldeveloper - I startet try Unit Tests as described here: link: [http://www.oracle.com/technology/obe/11gr2_db_prod/appdev/sqldev/sqldev_unit_test/sqldev_unit_test.htm#t4]

    He has worked with a test procedure. Now I'm testing my package functions, but all I get is the following:

    ---------
    Die Prozedur ausgeführt wurde following.

    Ausfuhrungsaufruf
    BEGIN
    : 1: = "PKG_MYPACK". "CREATEFUNCTION"(IN_PROGRAMMEID = >: 2,) "
    IN_AMOUNT = >: 3,.
    (IN_SWS = >: 4);
    END;

    Bind-variables verwendet
    1 WHOLE (NULL)
    INTEGER 2 IN 1
    INTEGER FROM 3 TO 10
    INTEGER 4 TO 11

    Ausfuhrungsergebnisse
    ERROR
    Ungultige conversion angefordert
    oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
    oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:110)
    oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:171)
    oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227)
    oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:439)
    oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:7723)
    oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7496)
    oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7978)
    oracle.jdbc.driver.OracleCallableStatement.setObject(OracleCallableStatement.java:4063)
    oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject(OraclePreparedStatementWrapper.java:221)
    oracle.dbtools.raptor.datatypes.strategies.callablestatement.CallableBindingDatum.customBindIN(CallableBindingDatum.java:135)
    Oracle. ...
    ------

    What can I do?

    Created
    Bug 8976245 - EA1: UNIT_TEST: CONVERSION not VALID ERROR with the HELP of the INTEGER PARAMETER
    and asked the answering machine of bug to keep you informed about the situation here in the forum.

    Bad news, it is that any INTEGER type parameter for which you specify a non-null value will fail.

    Possibly useful new, is that if you create a "clone" of you the function using NUMBER as the data type, you can continue to experiment how unit tests can be useful for you.

    Answer no sorry moment. :(

    Brian
    SQL development team

  • Help with SQL (sum and last key of table)

    I have a cust_transaction of the table (see def. below)

    The data are:
    CUST_ID TIMESTAMP PP_KEY TRANS
    * 39384 2009-10-08 2229345-2 *.
    * 39384 2009-10-09 2229346-1 *.
    * 39384 2009-10-20 2229345-1 *.

    What I want is a select statement that sum (trans) but get the last PP_KEY by customer_id.
    So, the result would be:
    * 39384 2229345 2 *.

    I tried som on patrition stuff but I saw not just.

    Any ideas?

    -Table def: +.
    CREATE TABLE TB. CUST_TRANSACTIONS
    +(+
    CUSTOMER_ID NUMBER,
    DATE TIME STAMP,
    NUMBER OF PP_KEY
    NUMBER OF TRANS
    +)+
    TABLESPACE TB
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE)
    64K INITIALS
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    PCTINCREASE 0
    DEFAULT USER_TABLES
    +)+
    Logging
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    NOMONITORING;

    -INSERTS +.
    TOGETHER TO DEFINE
    Insert into CUST_TRANSACTIONS
    + (CUSTOMER_ID, TIMESTAMP, PP_KEY, TRANS) +.
    Values
    + (39384, TO_DATE (OCTOBER 20, 2009 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 2229345, 1); +
    Insert into CUST_TRANSACTIONS
    + (CUSTOMER_ID, TIMESTAMP, PP_KEY, TRANS) +.
    Values
    + (39384, TO_DATE (9 OCTOBER 2009 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 2229346, - 1); +
    Insert into CUST_TRANSACTIONS
    + (CUSTOMER_ID, TIMESTAMP, PP_KEY, TRANS) +.
    Values
    + (39384, TO_DATE (8 OCTOBER 2009 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 2229345, 2); +
    COMMIT;
     SELECT customer_id,
      SUM(trans)       ,
      MAX(pp_key) KEEP (DENSE_RANK FIRST
    ORDER BY TIMESTAMP )
       FROM cust_transactions
    GROUP BY customer_id
    

    Ravi Kumar

    Published by: ravikumar.sv on December 4, 2009 16:10

  • Failed to insert a new line with a column generated sequence id

    Hello

    I'm trying to insert a new row in a table containing a column of sequence according to db, used as the primary key.

    Here is the code for the custom method of the corresponding AM I use to insert the new line:

    Line row2 = getCaAppointments1 () .createRow ();
    row2.SetAttribute ("Member ID", Member ID);
    row2.SetAttribute ("Status", "Planned");
    row2.SetAttribute ("CreatedBy", coachId);
    row2.SetAttribute ("CreationDate", date);
    AppointmentId will be generated by the sequence
    DBSequence newId = row2.getAttribute("AppointmentId") (DBSequence);
    SequenceImpl s = new SequenceImpl ("XX_CA_APPOINTMENT_ID", getDBTransaction());
    Long next = newId.getSequenceNumber () .longValue ();
    System.out.println ("Got sequence as id:" + newId);
    row2.SetAttribute ("AppointmentId", newId);
    row2.SetAttribute ("CoachId", coachId);
    row2.SetAttribute ("Type", "0");
    row2.SetAttribute ("AppointmentNumber", 0);
    row2.SetAttribute ("PlannedDate", Department of justice);
    getCaAppointments1 (.insertRow (row2));

    I put the attribute EO 'AppointmentId' to use a DBSequence. I tried different combinations to get the sequence Id and insert a line. Nothing worked well and I'm unable to insert a new line.

    If I avoid using the attribute 'AppointmentId' and that you try to insert a row, it will fail with the error below:

    ORA-01400: cannot insert NULL into ('APPS'. "" "" XX_CA_APPOINTMENTS '. "" APPOINTMENT_ID") ORA-06512: at line 1

    Tried to insert the new row using BCTester but I am struck by the same error it (I was unable to change the value of the "AppointmentId" column when inserting the line because this column is read-only and it showed as - 2 value).

    I guess, since the attribute of column/is already marked to use a DBSequence, the value should be assigned by default and I shouldn't hit "cannot insert the value NULL to the column.
    Did I miss something necessary to trigger the sequence to automatically generate new Id and assign it to the new line before it is created?

    Please let me know the fix.

    Thanks in advance
    Rouhaud

    Hello

    Oracle changes this behavior each version, so I hope that its still OK.
    If you have a trigger on the table that inserts the value of the id if none is preset, then mark it as DBSequence, or be it the number.

    Now for your entity, just generate the impl class and override the method create, kind of old school, I know, but it never fails.
    In the create just add the code to your sequence you had:

    SequenceImpl seqImpl = new SequenceImpl("", thisTransaction);
    Number idValue= s.getSequenceNumber();
    setAttribute("Id", idValue);
    

    -Anton

  • The documents that I have inserted with SQL do not appear in table form

    Hi all -
    I have not tried to reproduce this on apex.oracle.com yet, as I think that this may be a question easily answered:

    I have a page with an LOV, a graphic and a shape table all based on the same table. Everything has been working fine without any problems. Today, I updated the table using SQL Developer and introduced a few new lines in the table. The LOV and the graphic on my page reflect the new lines that were inserted through SQL, but the tabular form is not seeing them. When I select a value LOV that must return some new lines, my tabular report shows simply no found data. If I copy the SQL of the tabular report definition and run it in SQL Developer, all the appropriate lines are returned.

    Maybe I don't understand tabular forms. Any way to solve this problem or do I need to refresh the Page? Is the problem with the ID of the LINE or something?

    All ideas are as much appreciated - thank you.
    John

    Useful is fine. I don't know if these things can be changed.

    Well, they say: ' it's always the last place you want! "? Some of them can make you tear your hair out.

    My approach is 1) to display as much data as possible to ensure that data values are what you think they are. Often, they are not. And, (2) 'believe the error message.

    Best wishes
    Howard

  • new line added at the top of advancetable

    Hello

    IAM trying to add the line in a table dynamically so i have used adds the concept of line in the table advance.

    But while trying to add new lines they are added to the top of the current line is not the bottom of the current line.

    can someone help me please how to reach this.i want to add new lines to the bottom of the current line.

    Hello

    When inserting new line in take VO control in the last row and try to add a new line after the last of them.

    Below the code could help.

    public void InsertRecord() {}

    TempVOImpl vo = getTempVO1();

    vo.setMaxFetchSize (0);

    Line TempVORowImpl = (TempVORowImpl) vo.createRow ();

          VO. Last();

    VO. Next();

    vo.insertRow (row);

    row.setNewRowState (rank. STATUS_INITIALIZED);

    }

    BR, 906099

  • Is it possible to have a button that will insert a line of table rather than add at the end?

    I have a button Add line that works correctly using addinstance, but I would like to have the line button Add at the end of each line, if a user can insert a line in the middle of the existing/fiilled of lines.  Is this possible?  I would like to be able to do this using Formcalc because that's what my script in the form currently complies.

    Hello

    Yes, it is possible, but actually doing just that the script is to add a new line at the end of the table AND then move the line to the appropriate position.

    See examples here: http://assure.ly/gk8Q7a. Table 5 is a Table object, while table 6 is constructed using subforms. In both cases, the Index number is a button, which adds a line below the existing one clicked.

    See who helps me to,.

    Niall

  • New line - mailto:

    I use the getURL() method to open a new window for the user's e-mail message.
    It works very well, creating the e-mail window w / pre-populated subject and body values, but I need to insert new lines to separate a few fields.
    I've tried \n, \r, and line break, which none work for me. Here is my current code
    [as]
    getURL ("mailto:[email protected]?subject=SUBJECT & body = your name: \nYour company :"); ")
    [/ ACE]
    Any ideas?
    I lost too much time on this seemingly simple task.
    It really makes enamel forthcoming crap, if!
    BH

    Found my answer on the forums of http://ActionScript.org .
    Including a '% 0' in your text of chain force a newline after having opened the e-mail window. In Outlook Express, if I find the source, the s of '0% ' have been converted to
    Tags.
    What a pain! I lost at least 3 hours on it!

  • the new lines UTL_FILE replacement original lines

    Hello

    I try inserting new lines in my file TEST.csv but when I used this code, it is just erased all the lines at the origin of this file and write new lines. How am I suppose to write new lines, but still have my original disks in the files?

    Here is my code:
      l_file := utl_file.fopen('UTL_TMP_DIR','TEST.csv', 'w' );
       FOR p IN C5 LOOP
       Utl_File.Put_Line(l_File,p.customer_id);
       END LOOP;
       Utl_File.Fclose(l_File);

    If you try to add data to the file, you must open the file in Add mode, not writing mode, i.e.

    l_file := utl_file.fopen('UTL_TMP_DIR','TEST.csv', 'a' );
    

    All of [modes, you can open a file in | http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#sthref11829] are documented in the documentation of UTL_FILE.

    Justin

Maybe you are looking for

  • Tip for 3.5 mm headphones, stuck in jack

    I don't know how to solve this problem at all, I found an alternative and I use an external sound card to hear my music but its so annoying not being able to use my headset. Please help me solve this, what can I do? Also, I don't know how much apple

  • Satellite C50-A-1 - white screen after update Win 10

    Hello I have a c50-A-1 satellite and my screen keeps going blank and I have to wait for it to come back on which is really annoying.I continue to by pressing the keys and the mouse, and it does nothing. In my power settings, it should not turn off. I

  • Satellite A55-S326 product specification

    Hello. I can't find on the website of toshiba Satellite A55-S326 notebook loads. Could someone copy - paste the link for me please? Or, at least, does anyone know if it is possible to increase the RAM of 1 GB or more? Thank you Marek

  • Unable to install printer Deskjet F4280 all-in-one Windows Pro 8.1

    A week ago my laptop with Windows Pro 8.1 was a significant error and he stopped, then I restarted the operating system with a previous image of the hard drive C. I reinstalled another printer and I tried very time to reinstall the HP Deskjet F4280 a

  • Subvi behaves like the dialog box

    Hello LV'ers. I have a problem in my program of LV: 'I need my Subvi to behave like a dialog box. Design: if I call this Subvi (through the server VI - FPopen of the property node), my mainVI should NOT be controlled until the end of the Subvi. I thi