Using named parameters with an sql UPDATE statement

I am trying to write a simple? application on my Windows 7 PC using HTML, Javascript and Sqlite.  I have created a database with a 3 row table and pre-populated it with data.  I have written an HTML data entry form for modifying the data and am able to open the database and populate the form.  I am having trouble with my UPDATE function.  The current version of the function will saves the entry in the last row of the HTML table into the first two rows of the Sqlite data table -- but I'm so worn out on this that I can't tell if it is accidental or the clue I need to fix it.
This is the full contents of the function . . .
     updateData = new air.SQLStatement();
     updateData.sqlConnection = conn;
     updateData.text = "UPDATE tablename SET Gsts = "Gsts, Gwid = :Gwid, GTitle = :GTitle WHERE GId = ":GId;
          var x = document.getElementsById("formname");
          for (var i = 1, row, row = x.rows[i]; i++) {
               updateData.parameters[":GId"] = 1;
               for (var j = 0, col; col=row.cells[j]; j++) {
                    switch(j) {
                         case 0: updateData.parameters[":GTitle"] = col.firstChild.value; break;
                         case 1: updateData.parameters[":Gsts"] = col.firstChild.value; break;
                         case 2: updateData.parameters[":Gwid"] = col.firstChild.value; break;
Note: When I inspect the contents of the col.firstChild.value cases, they show the proper data as entered in the form -- it just isn't being updated into the proper rows of the Sqlite table.
Am I using the named parameters correctly? I couldn't find much information on the proper use of parameters in an UPDATE statement.

Thank you for the notes.  Yes, the misplaced quotes were typos.  I'm handtyping a truncated version of the function so I don't put too much info in the post. And yes, i = 1 'cuz the first rows of the table are titles.  So the current frustration is that I seem to be assigning all the right data to the right parameters but nothing is saving to the database.
I declare updateData as a variable at the top of the script file
Then I start a function for updating the data which establishes the sql connection as shown above.
The correctly typed.text statement is:
        updateData.text = "UPDATE tablename SET Gsts=:Gsts, Gwid=:Gwid, GTitle=:GTitle WHERE GId=:GId";
(The data I'm saving is entered in text boxes inside table cells.) And the current version of the loop is:
        myTable = document.getElementById("GaugeSts");
        myRows= myTable.rows;
          for(i=1, i<myRows.length, i++) {
               updateData.parameters[":GId"]=i;
               for(j=0; j<myRows(i).cells.length, j++) {
                    switch(y) {
                         case 0: updateData.parameters[":GTitle"]=myrows[i].cells[y].firstChild.value; break;
                         case 1: updateData.parameters[":Gsts"]=myrows[i].cells[y].firstChild.value; break;
                         case 2: updateData.parameters[":Gwid"]=myrows[i].cells[y].firstChild.value; break;
                         updateData.execute;
The whole thing runs without error and when I include the statements to check what's in myrows[i].cells[y].firstChild.value, I'm seeing that the correct data is being picked up for assignment to the parameters and the update. I haven't been able to double check that the contents of the parameters are actually taking the data 'cuz I don't know how to extract the data from the parameters. ( The only reference  I've found so far has said that it is not possible. I'm still researching that one.) I've also tried moving the position of the updateData execution statement to several different locations in the loop andstill nothing updates. 
I am using a combination of air.Introspector.Console.log to check the results of code and I'm using Firefox's SQlite manager to handle the database.  The database is currently sitting on the Desktop to facilitate testing and I have successfully updated/changed data in this table through the SQLite Manager so I don't think I'm having permission errors and, see below, I have another function successfully saving data to another table.
I currently have another function that uses ? for the parametersin the .text of a INSERT/REPLACE statement and that one works fine.  But, only one line of data is being saved so there is no loop involved.  I tried changing the UPDATE statement in this function to the INSERT/REPLACE just to make something save back to the database but I can't make that one work either.I've a (And, I've tried so many things now, I don't even remember what actually saved something --albeit incorrectly --to the database in one of my previous iterations with the for loops.)
I'm currently poring through Sqlite and Javascript tomes to see if I can find what's missing but if anything else jumps out at you with the corrected code, I'd appreciate some ideas.
Jeane

Similar Messages

  • Updates using single SQL Update statement.

    Hi Guys,
    I had an interview... and was not able to give an answer of one of the question.
    Given the emp table... need to update the salary with following requirement using one SQL statement...
    1. Update salary+1000 for those employees who have salary between 500 and 1000
    2. Update salary+500 for those employees who have salary between 1001 and 1500
    Both above requirement should be done by using only one SQL update statement... can some one tell me how to do it?

    update emp
      set salary   = case when salary between 500 and 1000
                                then salary + 1000
                                when salary between 1001 and 1500
                                then salary + 500
                          end;Regards
    Arun

  • NOT Using Named Parameters in a Native Query

    Hi!
    like it is written in the Toplink JPA Extensions reference Toplink supports using named parameters in native queries.
    See example from http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-extensions.html:
    Example 1-11 Specifying a Named Parameter With #
    Query queryEmployees = entityManager.createNativeQuery(
    "SELECT OBJECT(emp) FROM Employee emp WHERE emp.firstName = #firstname"
    queryEmployeeByFirstName.setParameter("firstName", "Joan");
    Collection employees = queryEmployees.getResultList();
    But I want to use "#" in the SQL statement so I want to disable this parameter binding somehow and let the query just execute the SELECT statement I deliver.
    I have tried to add the property
    <property name="toplink.jdbc.bind-parameters" value="false"/>
    into the persistence.xml and I have also tried to add the query hint
    query.setHint(TopLinkQueryHints.BIND_PARAMETERS, HintValues.FALSE);
    but none of them prevents the # to be uses as a paramter. this causes the exception:
    Exception [TOPLINK-6132] (Oracle TopLink Essentials - 9.1 (Build b22)): oracle.toplink.essentials.exceptions.QueryException
    Exception Description: Query argument ######' not found in list of parameters provided during query execution.
    Query: ReadAllQuery(de.merck.compas.material.SimilarLocalMaterialListItemBV)
    The SQL Statement is
    SELECT * FROM TABLE (
    CAST ( RCGC.PHA_P_COMPASMDM.LookupSimilarMats
    ( 'COC003','10021500150000000997','30','30','040','standard','','001001','001001','123456','##########','X','X','X','X','U' )
    AS RCGC.PHA_COMPAS_SIMILAR_MATS ) )
    I am using the latest Toplink essentials build together with an Oracle 9.2i DB in a Java SE web application.
    Can anyone give me a little hint what to do?
    Thanks and best regards,
    Alex

    I hope this is what you need:
    [TopLink Fine]: 2007.01.19 02:56:48.278--ServerSession(17712783)--Connection(723185)--Thread(Thread[http-8080-Processor2
    3,5,main])--SELECT APPL_CGP_MATLOC, CHANGE_REQ_MATLOC, CD_PHA_MAT_LOC, LCOMP, LOC_MAT_NAME, APPL_GDM_MATLOC, LOC_MAT_NAM
    E_SHORT, APPL_PDW_MATLOC, PHA_MAT_LOC_LCOMMENT, APPL_TP_MATLOC, DIVISION, APPL_WRS_MATLOC, ARTICLE_ID_MDA, LU_PHA_MAT_LO
    C, LOC_MAT_NAME_OLD, LDT_PHA_MAT_LOC, PHA_MAT_LOC_STATUS, CU_PHA_MAT_LOC, MAT_LOC_ID, RCOMP, MAT_ID FROM RCGC.PHA_V_COMP
    AS_MAT_MATLOC WHERE ((MAT_LOC_ID = '123456') AND (RCOMP = '001001'))
    [TopLink Fine]: 2007.01.19 02:56:48.398--ServerSession(17712783)--Connection(32404901)--Thread(Thread[http-8080-Processo
    r23,5,main])--SELECT MAT_ID, DESCRIPTION, PHA_MATERIAL_LCOMMENT, PACKSIZE, LU_PHA_MATERIAL, PACKSIZE_UNIT, LDT_PHA_MATER
    IAL, CONTAINER_NAME, CU_PHA_MATERIAL, PURPOSE, CD_PHA_MATERIAL, CONTENT, CONTAINER_ID, AI_FACTOR, PHA_MATERIAL_STATUS, C
    MG_SPEC_APP, PROD_LEVEL, PACKAGE_SIZE, PRODUCT_ID FROM RCGC.PHA_V_COMPAS_MATERIAL WHERE (MAT_ID = '10021500150000000997'
    [TopLink Fine]: 2007.01.19 02:56:48.468--ServerSession(17712783)--Connection(723185)--Thread(Thread[http-8080-Processor2
    3,5,main])--SELECT PRODUCT_ID, PROD_GRP_ID, APPL_FORM_NAME, PRODUCT_NAME, GALENIC_FORM_NAME, APPL_FORM_ID, PHA_PRODUCT_S
    TATUS, PHA_PRODUCT_LCOMMENT, GALENIC_FORM_ID, LU_PHA_PRODUCT, INN, LDT_PHA_PRODUCT FROM RCGC.PHA_V_COMPAS_PRODUCT WHERE
    (PRODUCT_ID = 'COC003')
    [TopLink Fine]: 2007.01.19 02:56:48.568--ServerSession(17712783)--Connection(32404901)--Thread(Thread[http-8080-Processo
    r23,5,main])--SELECT APPL_CGP_MATLOC, CHANGE_REQ_MATLOC, CD_PHA_MAT_LOC, LCOMP, LOC_MAT_NAME, APPL_GDM_MATLOC, LOC_MAT_N
    AME_SHORT, APPL_PDW_MATLOC, PHA_MAT_LOC_LCOMMENT, APPL_TP_MATLOC, DIVISION, APPL_WRS_MATLOC, ARTICLE_ID_MDA, LU_PHA_MAT_
    LOC, LOC_MAT_NAME_OLD, LDT_PHA_MAT_LOC, PHA_MAT_LOC_STATUS, CU_PHA_MAT_LOC, MAT_LOC_ID, RCOMP, MAT_ID FROM RCGC.PHA_V_CO
    MPAS_MAT_MATLOC WHERE (MAT_ID = '10021500150000000997')
    [TopLink Warning]: 2007.01.19 02:56:48.638--UnitOfWork(4469532)--Thread(Thread[http-8080-Processor23,5,main])--Exception
    [TOPLINK-6132] (Oracle TopLink Essentials - 9.1 (Build b22)): oracle.toplink.essentials.exceptions.QueryException
    Exception Description: Query argument ######' not found in list of parameters provided during query execution.
    Query: ReadAllQuery(de.merck.compas.material.SimilarLocalMaterialListItemBV)
    Local Exception Stack:
    Exception [TOPLINK-6132] (Oracle TopLink Essentials - 9.1 (Build b22)): oracle.toplink.essentials.exceptions.QueryExcept
    ion
    Exception Description: Query argument ######' not found in list of parameters provided during query execution.
    Query: ReadAllQuery(de.merck.compas.material.SimilarLocalMaterialListItemBV)
    at oracle.toplink.essentials.exceptions.QueryException.namedArgumentNotFoundInQueryParameters(QueryException.jav
    a:206)
    at oracle.toplink.essentials.internal.databaseaccess.DatasourceCall.getValueForInParameter(DatasourceCall.java:6
    86)
    at oracle.toplink.essentials.internal.databaseaccess.DatasourceCall.getValueForInOutParameter(DatasourceCall.jav
    a:704)
    at oracle.toplink.essentials.internal.databaseaccess.DatasourceCall.translateQueryString(DatasourceCall.java:630
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseCall.translate(DatabaseCall.java:850)
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQuer
    yMechanism.java:212)
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQuer
    yMechanism.java:199)
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCa
    llQueryMechanism.java:270)
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQu
    eryMechanism.java:600)
    at oracle.toplink.essentials.queryframework.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:302)
    at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:
    709)
    at oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery.java:609)
    at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:677)
    at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:7
    31)
    at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2218)
    at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:937)
    at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:909)
    at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:346)
    at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.getResultList(EJBQueryImpl.java:447)
    at de.merck.compas.material.SimilarLocalMaterialListItemBC.selectList(SimilarLocalMaterialListItemBC.java:40)
    at de.merck.compas.material.SimilarLocalMaterialListItemBC.selectSimilar(SimilarLocalMaterialListItemBC.java:53)
    at de.merck.compas.material.MaterialMaintainFS.init(MaterialMaintainFS.java:158)
    at de.merck.compas.material.MaterialListSV.startMaterialMaintain(MaterialListSV.java:186)
    at de.merck.compas.material.MaterialListSV.processPage(MaterialListSV.java:97)
    at de.merck.jsfw.servletFramework.AbstractServlet.processPage(AbstractServlet.java:141)
    at de.merck.jsfw.servletFramework.ControllerServlet.processLastPage(ControllerServlet.java:240)
    at de.merck.jsfw.servletFramework.ControllerServlet.processRequest(ControllerServlet.java:206)
    at de.merck.jsfw.servletFramework.ControllerServlet.doGet(ControllerServlet.java:181)
    at de.merck.jsfw.servletFramework.ControllerServlet.doPost(ControllerServlet.java:191)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at de.merck.comp.ntml.NTLMFilter.negotiate(NTLMFilter.java:384)
    at de.merck.comp.ntml.NTLMFilter.doFilter(NTLMFilter.java:165)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java
    :664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Thread.java:595)
    The Toplink manifest file with version number:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.6.5
    Created-By: 1.5.0_09-b03 (Sun Microsystems Inc.)
    Specification-Title: Java Persistence API
    Specification-Vendor: Sun Microsystems, Inc., Oracle Corp.
    Specification-Version: 1.0
    Implementation-Title: TopLink Essentials
    Implementation-Vendor: Sun Microsystems, Inc., Oracle Corp.
    Implementation-Version: 9.1 build: b22
    Thanks again for your help!

  • Named parameters in Native SQL

    A little background first:
    Our website uses Hibernate as it's JPA provider, but we've run into several issues with it, one of which they actively refuse to fix out of pure arrogance, even when we gave them a good patch for it. The other one is a performance issue that can be greatly improved by passing arrays as parameters, which I've read rumours is supported in EclipseLink. I first tried implementing a Hibernate UserType as they've specified and it turns out they never read them into the Map that looks-up parameter types during binding, even though it's loaded from their hibernate.cfg.xml. In other words, they're only pretending to support custom user types, but unless you're writing-out the full manual loading of their configuration, there's no way to do it.
    After a day of trying to fix all the relation annotations that EclipseLink finds unacceptable in our project (which only uses native SQL and EntityManager.find for selects) I finally got it running and came to discover you don't support named parameters in native SQL. That was really disappointing, because a few months ago we migrated all our queries to named parameters, because positioning ones were too difficult to track and caused more bugs when we had to add more criterias.
    My questions are these:
    Are named parameters for native SQL not supported by JPA specifications or because they are considered low priority?
    Would you accept a patch that supports them?
    Can we really use arrays and/or lists as parameters in queries like this "SELECT * FROM some_table WHERE my_column_a IN ? AND my_column_b NOT IN ?"
    If yes to above, would it still work if the first one is an array of integers and the second is an array of strings?
    Would it work if it's in native SQL and the column types cannot be resolved due to query complexity?

    A little background first:
    Our website uses Hibernate as it's JPA provider, but we've run into several issues with it, one of which they actively refuse to fix out of pure arrogance, even when we gave them a good patch for it. The other one is a performance issue that can be greatly improved by passing arrays as parameters, which I've read rumours is supported in EclipseLink. I first tried implementing a Hibernate UserType as they've specified and it turns out they never read them into the Map that looks-up parameter types during binding, even though it's loaded from their hibernate.cfg.xml. In other words, they're only pretending to support custom user types, but unless you're writing-out the full manual loading of their configuration, there's no way to do it.
    After a day of trying to fix all the relation annotations that EclipseLink finds unacceptable in our project (which only uses native SQL and EntityManager.find for selects) I finally got it running and came to discover you don't support named parameters in native SQL. That was really disappointing, because a few months ago we migrated all our queries to named parameters, because positioning ones were too difficult to track and caused more bugs when we had to add more criterias.
    My questions are these:
    Are named parameters for native SQL not supported by JPA specifications or because they are considered low priority?
    Would you accept a patch that supports them?
    Can we really use arrays and/or lists as parameters in queries like this "SELECT * FROM some_table WHERE my_column_a IN ? AND my_column_b NOT IN ?"
    If yes to above, would it still work if the first one is an array of integers and the second is an array of strings?
    Would it work if it's in native SQL and the column types cannot be resolved due to query complexity?

  • Regex help for SQL update statement

    Hello,
    need help from IPS regex guru - trying to build the signature to detect SQL update statement in HTTP requests.
    1) Am I correct with regex below specified as Request-Regex?
    [Uu][Pp][Dd][Aa][Tt][Ee]([%]20|[+])[\x20-\x7e]+[Ss][Ee][Tt]([%]20|[+])[\x20-\x7e]+=
    2) How do I make sure that it detects 'Update' in URI and Arguments only and not in the body on entire webserver response (currently looks like the case)?

    1) It looks correct to me
    2) Typically, the "service HTTP" engine is used to inspect requests and the "TCP string" engine is used to inspect HTTP server responses. If you only want to inspect requests, use the service HTTP engine.

  • SQL UPDATE Statement Explaination (urgent please...)

    Hi,
    Could anyone explain for me what this statement will do:
    update KPIR KR
    set ( CA ) = (
    select sum(sl.RRC_CONN_STP_ATT) CA
    from PV_WCEL_SERVICE_LEVEL sl, UTP_MO um
    where sl.GLOBAL_ID = um.CO_GID
    group by sl.STARTTIME, um.OBJECT_INSTANCE
    I could not understand how the mapping between the two tables will be ("um" clause is not used in the select statement and it is used only in the "where" and "group by" arguments) What does this mean?.
    The actual problem is that when I execute the above SQL statement, it was take around just 3 minutes to be implemented. But after we upgrade from Oracle 8 to Oracle 9, this statement is taking around 3 hours to be implemented.
    Anyone have any idea what is the problem?

    Below is the plan:
    KPIR table:
    RNC_ID (str), PST ('YYYYMMDD_HH24'), CA (Numner)
    1, 20061105_13, 0
    1, 20061105_14, 0
    1, 20061105_15, 0
    2, 20061105_13, 0
    2, 20061105_14, 0
    2, 20061105_15, 0
    3, 20061105_13, 0
    3, 20061105_14, 0
    3, 20061105_15, 0
    4, 20061105_13, 0
    4, 20061105_14, 0
    4, 20061105_15, 0
    PV_WCEL_SERVICE_LEVEL table:
    GLOBAL_ID (str), STARTTIME ('YYYYMMDD_HH24'), RRC_CONN_STP_ATT (Number)
    A1, 20061101_00, 9
    A1, 20061101_01, 4
    A1, 20061101_23, 3
    A1, 20061130_23, 4
    A2, 20061101_00, 3
    A2, 20061101_01, 4
    A2, 20061101_23, 1
    A2, 20061130_23, 5
    UTP_MO table;
    RNC_ID (str), GLOBAL_ID (str), OBJECT_INSTANCE (str)
    1, A1, <A1_NAME>
    1, A2, <A2_NAME>
    1, A9, <A9_NAME>
    2, B1, <B1_NAME>
    2, B2, <B2_NAME>
    2, B9, <B9_NAME>
    3, C1, <C1_NAME>
    3, C2, <C2_NAME>
    3, C9, <C9_NAME>
    4, D1, <D1_NAME>
    4, D2, <D2_NAME>
    4, D9, <D9_NAME>
    Now, I want to update the value of CA in table KPIR:
    For instance, for RNC_ID='1' and at PST='20061105_13', the CA should equals to the sum of value RRC_CONN_STP_ATT for all GLOBAL_IDs under RNC_ID='1' and at STARTTIME '20061105_13'.
    So, is this SQL UPDATE statement will do it?
    update KPIR kr
    set ( CA ) = (
    select sum(sl.RRC_CONN_STP_ATT) CA
    from PV_WCEL_SERVICE_LEVEL sl, UTP_MO um
    where sl.GLOBAL_ID = um.GLOBAL_ID and kr.RNC_ID = um.RNC_ID and kr.PST = sl.STARTTIME
    group by sl.STARTTIME, um.OBJECT_INSTANCE
    And if so, why it is taking around 3 hours to be implemented? This issue is happened after upgrading from Oracle 8 to 9.
    Really appreciate your help and thanks in advance.

  • I've deleted Adobe Reader 11 and rebooted and reinstalled Adobe Reader 11 and I still get the error message that 'Adobe Reader is blocked because it is out of date'. Using Windows XP with the latest updates (SP3).

    I've deleted Adobe Reader 11 and rebooted and reinstalled Adobe Reader 11 and I still get the error message that 'Adobe Reader is blocked because it is out of date'. Using Windows XP with the latest updates (SP3).

    Screenshots attached to email replies will not make it back to the forum; you need to login to the forum and post it in your topic using the camera icon in the editor.
    Google Chrome is a problem:
    if you use Chrome's own PDF viewer, the results are unpredictable.
    if you use the Adobe Reader plugin with Chrome, it may reject (block) it if it is not the latest version.  Reader 11.0.08 is the latest version for Windows XP, but Chrome may insist on the current version 11.0.10.
    My suggestion; use a different browser!

  • How to Unpivot, Crosstab, or Pivot using Oracle 9i with PL/SQL?

    How to Unpivot, Crosstab, or Pivot using Oracle 9i with PL/SQL?
    Here is a fictional sample layout of the data I have from My_Source_Query:
    Customer | VIN | Year | Make | Odometer | ... followed by 350 more columns/fields
    123 | 321XYZ | 2012 | Honda | 1900 |
    123 | 432ABC | 2012 | Toyota | 2300 |
    456 | 999PDQ | 2000 | Ford | 45586 |
    876 | 888QWE | 2010 | Mercedes | 38332 |
    ... followed by up to 25 more rows of data from this query.
    The exact number of records returned by My_Source_Query is unknown ahead of time, but should be less than 25 even under extreme situations.
    Here is how I would like the data to be:
    Column1 |Column2 |Column3 |Column4 |Column5 |
    Customer | 123 | 123 | 456 | 876 |
    VIN | 321XYZ | 432ABC | 999PDQ | 888QWE |
    Year | 2012 | 2012 | 2000 | 2010 |
    Make | Honda | Toyota | Ford | Mercedes|
    Odometer | 1900 | 2300 | 45586 | 38332 |
    ... followed by 350 more rows with the names of the columns/fields from the My_Source_Query.
    From reading and trying many, many, many of the posting on this topic I understand that the unknown number or rows in My_Source_Query can be a problem and have considered working with one row at a time until each row has been converted to a column.
    If possible I'd like to find a way of doing this conversion from rows to columns using a query instead of scripts if that is possible. I am a novice at this so any help is welcome.
    This is a repost. I originally posted this question to the wrong forum. Sorry about that.

    The permission level that I have in the Oracle environment is 'read only'. This is also be the permission level of the users of the query I am trying to build.
    As requested, here is the 'create' SQL to build a simple table that has the type of data I am working with.
    My real select query will have more than 350 columns and the rows returned will be 25 rows of less, but for now I am prototyping with just seven columns that have the different data types noted in my sample data.
    NOTE: This SQL has been written and tested in MS Access since I do not have permission to create and populate a table in the Oracle environment and ODBC connections are not allowed.
    CREATE TABLE tbl_MyDataSource
    (Customer char(50),
    VIN char(50),
    Year char(50),
    Make char(50),
    Odometer long,
    InvDate date,
    Amount currency)
    Here is the 'insert into' to populate the tbl_MyDataSource table with four sample records.
    INSERT INTO tbl_MyDataSource ( Customer, VIN, [Year], Make, Odometer, InvDate, Amount )
    SELECT "123", "321XYZ", "2012", "Honda", "1900", "2/15/2012", "987";
    INSERT INTO tbl_MyDataSource ( Customer, VIN, [Year], Make, Odometer, InvDate, Amount )
    VALUES ("123", "432ABC", "2012", "Toyota", "2300", "1/10/2012", "6546");
    INSERT INTO tbl_MyDataSource ( Customer, VIN, [Year], Make, Odometer, InvDate, Amount )
    VALUES ("456", "999PDQ", "2000", "Ford", "45586", "4/25/2002", "456");
    INSERT INTO tbl_MyDataSource ( Customer, VIN, [Year], Make, Odometer, InvDate, Amount )
    VALUES ("876", "888QWE", "2010", "Mercedes", "38332", "10/13/2010", "15973");
    Which should produce a table containing these columns with these values:
    tbl_MyDataSource:
    Customer     VIN     Year     Make     Odometer     InvDate          Amount
    123 | 321XYZ | 2012 | Honda      | 1900          | 2/15/2012     | 987.00
    123 | 432ABC | 2012 | Toyota | 2300 | 1/10/2012     | 6,546.00
    456 | 999PDQ | 2000 | Ford     | 45586          | 4/25/2002     | 456.00
    876 | 888QWE | 2010 | Mercedes | 38332          | 10/13/2010     | 15,973.00
    The desired result is to use Oracle 9i to convert the columns into rows using sql without using any scripts if possible.
    qsel_MyResults:
    Column1          Column2          Column3          Column4          Column5
    Customer | 123 | 123 | 456 | 876
    VIN | 321XYZ | 432ABC | 999PDQ | 888QWE
    Year | 2012 | 2012 | 2000 | 2010
    Make | Honda | Toyota | Ford | Mercedes
    Odometer | 1900 | 2300 | 45586 | 38332
    InvDate | 2/15/2012 | 1/10/2012 | 4/25/2002 | 10/13/2010
    Amount | 987.00 | 6,546.00 | 456.00 | 15,973.00
    The syntax in SQL is something I am not yet sure of.
    You said:
    >
    "Don't use the same name or alias for two different things. if you have a table called t, then don't use t as an alais for an in-line view. Pick a different name, like ordered_t, instead.">
    but I'm not clear on which part of the SQL you are suggesting I change. The code I posted is something I pieced together from some of the other postings and is not something I full understand the syntax of.
    Here is my latest (failed) attempt at this.
    select *
      from (select * from tbl_MyDataSource) t;
    with data as
    (select rownum rnum, t.* from (select * from t order by c1) ordered_t), -- changed 't' to 'ordered_t'
    rows_to_have as
    (select level rr from dual connect by level <= 7 -- number of columns in T
    select rnum,
           max(decode(rr, 1, c1)),
           max(decode(rr, 2, c2)),
           max(decode(rr, 3, c3)),
           max(decode(rr, 4, c3)),      
           max(decode(rr, 5, c3)),      
           max(decode(rr, 6, c3)),      
           max(decode(rr, 7, c3)),       
      from data, rows_to_have
    group by rnumIn the above code the "select * from tbl_MyDataSource" is a place holder for my select query which runs without error and has these exact number of fields and data types as order shown in the tbl_MyDataSource above.
    This code produces the error 'ORA-00936: missing expression'. The error appears to be starting with the 'with data as' line if I am reading my PL/Sql window correctly. Everything above that row runs without error.
    Thank you for your great patients and for sharing your considerable depth of knowledge. Any help is gratefully welcomed.

  • Use of ROWID in SQL Update Statement

    Hi All,
    I have an update statement which uses the rowid column to perform the selection on the target table. Given that a rowid represents the physical location of a row on disk we know that this reference can change when various activities are performed on the database/table/row etc...
    Here is an example of the statement I am issuing:
    UPDATE tabA outertab SET col1 = 'Value'
    WHERE EXISTS (SELECT 1 FROM tabA innertab WHERE outertab.ROWID = outertab.ROWID AND ...)
    Obviously the inner query is more complicated and uses other tables etc... but for the purposes of the example we dont need to include the detail.
    My question is: When using rowid in a single SQL statement as a reference from a subquery to the outer statement is there a risk that external activities can change the rowid and those changes be reflected within the database session that my query is executing thus causing an inconsistency between the inner and outer SQL clause?
    In response to the question which will follow this post: "Why don't you just use a PK", We would like to avoid maintaining a PK on the table as we are talking about very large volumes of data and we dont want to have to issue a call to a sequence if we can avoid it when we are inserting the data. If however there is a risk that this Update statement could fail or update the wrong rows then we may have to use a PK.
    I know there is a lot of threads about this but I havnt been able to find one that someone has answered with any kind of confidence or clarity, any help would be much appreciated.
    Thanks
    Keith
    Edited by: The Turtle on Mar 5, 2009 5:24 AM

    When using rowid in a single SQL statement as a reference from a subquery to the outer statement is there a risk that external activities can change the rowid and those changes be reflected within the database session that my query is executing thus causing an inconsistency between the inner and outer SQL clause?No, it's safe to use rowid in this type of query. Docs
    A row's assigned rowid remains unchanged unless the row is exported and imported using the Import and Export utilities. When you delete a row from a table and then commit the encompassing transaction, the deleted row's associated rowid can be assigned to a row inserted in a subsequent transaction.

  • How to use lexical parameters with Sql Server Stored Procedure?

    Hi,
    I'm developing a BI Publisher report on a sql server database. I need to execute a stored procedure to dynamically build the query by replacing the lexical parameters with the values of varaibles of the stored procedure. With Oracle stored procedures, I have used data template and had reference the varaiable in SP by prefixing it with '&'.
    It doesn't work if I try to do the same thing with SQL server. Is there anyone who has come across the similar situation? Please let me know if anyone has got any ideas...
    Thanks in Advance
    Rag

    TopLink currently doesn't support multiple ResultSets. Multiple ResultSets support is considered for a future release.

  • Problem with a sqlite update statement using variables

    Flash Builder/Flex 4
    I'm trying to create a routine that will allow me to change the name of an author in a sqlite table.
    I have this update statement which works with hardcoded data:
    //trace("updateName function newAuthorName: " + newAuthorName (returns Dusty));
    //trace("updateName function oldAuthorName: " + oldAuthorName (returns Kristin));
    updateStmt = new SQLStatement();
    updateStmt.sqlConnection = conn;
    var sql:String = "UPDATE tableName SET authorNameColumn = 'Dusty' WHERE authorNameColumn = 'Kristin' ";
    updateStmt.text = sql;
    updateStmt.execute();
    If I change the statement to
    "UPDATE tableName SET authorNameColumn  =" +  newAuthorName +  "WHERE authorNameColumn =" + oldAuthorName;
    I get SELECT error: SQLError: 'Error #3115: SQL Error.', details:'near 'authorNameColumn': syntax error'
    I've tried changing many things about this statement trying to isolate the problem, but it seems to not like the variables.

    Lee;
    Thanks for your help.
    I'm relatively new to this Flex stuff.
    I've been trying to fix this problem for hours and you know how it is when you keep looking at the same thing for too long.
    The article you linked to helped. I finally just copied the text from it and changed the variable name to my own.
    FINALLY!! I can go do something else now.
    Grins
    Kristin

  • Sql Update Statement (complex)

    Hi ,
    A very good morning to all.
    I am stuck in a problem , and i really hope for solutiion.
    I have a dimension table (DIM_CAR) for which i need to write a update statement.
    My table structure is :
    C_ID           Startdate                       EndDate
    7546343    2012-05-29 00:00:00    NULL
    7546343    2012-05-18 00:00:00    2012-05-29 00:00:00
    7546343    2012-05-14 00:00:00    2012-05-18 00:00:00
    7546343    2012-05-10 00:00:00    2012-05-10 00:00:00
    7546343    2012-05-10 00:00:00    2012-05-14 00:00:00
    7546343    2012-03-22 00:00:00    2012-03-22 00:00:00
    7546343    2012-03-15 00:00:00    2012-03-22 00:00:00
    7546343    2012-02-02 00:00:00    2012-03-15 00:00:00
    7546343    2012-01-31 00:00:00    2012-02-02 00:00:00
    Now the scenario is Whenever any update comes in car , then it closes the previous record and open a new record(SCD)
    For e.g the 1st update comes on 2012-02-02 , so it closes the last record (by putting 2012-02-02) in end date and open a new record by putting 2012-02-02 in startdate. Then update comes in 2012-03-15 and so on. The last record is for 2012-05-29 which is
    still open as there is no update after that,
    so whenever any update come it opens a new record with startdate value is extract date and enddate value NULL and closes the previous. Then  after another update , that NULL value is replace by the new date and another record opens.
    My prob is if you will closely analyse the dates , then there are some records missing in the above table due to which there are discrepencies in dates.
    E.g. If u see the 6th row, startdate is 2012-03-22 and enddate is also 2012-03-22. But here in this case the enddate should be 2012-05-10(which is next update)
    I need to write a sql script to update enddates with the latest update startdate in my table. I have 60000 of C_id which are affected.
    COULD ANYONE plz Help.. I knw its difficult but u can give a try ..........Plz ask if anyone requires more info.
    Abhishek

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    >> I have a dimension table (DIM_CAR) for which I need to write a update statement. My table structure is : <<
    NO! This is a picture of the data; it is not DDL! Is this what you would have posted if you had manners? 
    CREATE TABLE Foobars
    (c_id CHAR(7) NOT NULL, 
     foo_start_date DATE NOT NULL, 
     PRIMARY KEY (c_id, foo_start_date), -- my guess!!
     CHECK (foo_start_date < foo_end_date),-- another guess! 
     foo_end_date DATE);
    INSERT INTO Foobar
    VALUES 
    ('7546343', '2012-05-29', 'NULL), 
    ('7546343', '2012-05-18', '2012-05-29'), 
    ('7546343', '2012-05-14', '2012-05-18'), 
    ('7546343', '2012-05-10', '2012-05-10'), 
    ('7546343', '2012-05-10', '2012-05-14'), 
    ('7546343', '2012-03-22', '2012-03-22'), 
    ('7546343', '2012-03-15', '2012-03-22'), 
    ('7546343', '2012-02-02', '2012-03-15'), 
    ('7546343', '2012-01-31', '2012-02-02');
    Now the scenario is Whenever any update comes in car, then it closes the previous record [sic: rows are not records! Please learn basic terms] and open a new record [sic](SCD). 
    What is “SCD” and why do you think it is meaningful to us? Here is an article on this topic. 
    Modifying Contiguous Time Periods
    This article explains how to modify contiguous time periods that were described in Joe Celko’s article 'Contiguous Time Periods in SQL'.  Joe describes the table itself that he calls the 'Kuznetsov History Table'. He explains how it is used to store contiguous
    time intervals with constraint to ensure that the date periods really are contiguous, The editor suggested that I give a brief description of how to modify the data in the History table as this may not be entirely obvious.
    When trusted constraints enforce data integrity, the data is guaranteed to be valid at the end of any statement, even if it is not committed. When we modify contiguous time periods, in order to get from one valid state to another we may need to insert a row
    and update another one, or we may need to delete a row and update another one. This is one of those cases when MERGE really shines – it allows us to get from one valid state to another in one statement, inserting, updating, and deleting rows as needed.
    CREATE TABLE Tasks
    (task_id INT NOT NULL, 
     task_score INTEGER NOT NULL, 
     current_start_date DATE NOT NULL, 
     current_end_date DATE NOT NULL, 
     previous_end_date DATE NULL, 
     CONSTRAINT PK_Tasks_task_id_current_end_date 
     PRIMARY KEY (task_id, current_end_date), 
     CONSTRAINT UNQ_Tasks_task_id_previous_end_date 
      UNIQUE (task_id, previous_end_date), 
     CONSTRAINT FK_Tasks_task_id_previous_end_date 
      FOREIGN KEY (task_id, previous_end_date) 
      REFERENCES Tasks (task_id, current_end_date), 
     CONSTRAINT CHK_Tasks_previous_end_date_NotAfter_current_start_date 
      CHECK (previous_end_date <= current_start_date), 
     CONSTRAINT CHK_Tasks_current_start_date_Before_current_end_date 
      CHECK (current_start_date < current_end_date)
    Some Easy Modifications.
    It is easy to begin a new series of time periods
    INSERT INTO Tasks
      (task_id, task_score, current_start_date, current_end_date, previous_end_date)
    VALUES (1, 100, '2010-1002', '2010-1023', NULL),
           (1, 80, '2010-1023', '2010-11-03', '2010-1023');  
     It is just as easy to continue adding periods to the end of the series.
    INSERT INTO Tasks
      (task_id, task_score, current_start_date, current_end_date, previous_end_date)
    VALUES(1, 98, '2010-11-20', '2010-11-25', '2010-11-03'),
          (1, 75, '2010-11-26', '2010-11-27', '2010-11-25');
    Deleting one or more rows from the end is just as easy, and we shall skip the example. As we have seen, it is easy to perform typical, the most common operations against history of periods.
    However, some other operations are less easy and need more explanations. Now that we have enough test data, let us move on to more complex examples. Here is the test data at this moment: 
    Adding periods to the beginning.
    Each series of periods has exactly one first period – this is enforced by the following constraint: Unique_task_id_and_previous_end_date
    As a result, when we are inserting one or more periods to the beginning of the series, we have to update the period that used to be the first, as follows:
    MERGE INTO Tasks 
    USING (VALUES (1, 98, '2009-03-01', '2009-03-06', NULL),
                  (1, 100, '2010-10-02', '2010-10-23', '2009-03-06') 
           ) AS Source (task_id, task_score, current_start_date, current_end_date, previous_end_date)
       ON Tasks.task_id = Source.task_id
           AND Tasks.current_start_date = Source.current_start_date
    WHEN MATCHED 
    THEN UPDATE
         SET task_score = Source.task_score, 
             current_start_date = Source.current_start_date, 
             current_end_date = Source.current_end_date, 
             previous_end_date = Source.previous_end_date
    WHEN NOT MATCHED 
    THEN INSERT (task_id, task_score, current_start_date, current_end_date, previous_end_date)
     VALUES (Source.task_id, Source.task_score, Source.current_start_date,
             Source.current_end_date, Source.previous_end_date); 
    Now we will verify that our test data looks as expected, with a new row at the beginning, and previous_end_date column is modified to point to the new row for the row that used to be the first before this modification:
    We are also going to discuss some other scenarios, such as adding/deleting periods in the middle of the series. In all these cases we shall be using MERGE, and the DML looks quite similar, so let us wrap it up in a stored procedure.
    CREATING A STORED PROCEDURE
    The following code implements this merging functionality with a stored procedure that uses a table to hold teh new rows:
    CREATE TABLE NewTasks
    (task_id INTEGER NOT NULL, 
    task_score INTEGER NOT NULL, 
    current_start_date DATE NOT NULL, 
    current_end_date DATE NOT NULL, 
    previous_end_date DATE NULL,
    deletion_flg CHAR(1));
    CREATE PROCEDURE MergeNewTasks
    AS BEGIN 
    MERGE INTO Tasks 
    USING (SELECT task_id, task_score, current_start_date, current_end_date, previous_end_date, deletion_flg
             FROM NewTasks) AS Source
       ON Tasks.task_id = Source.task_id
          AND Tasks.current_start_date = Source.current_start_date
    WHEN MATCHED AND deletion_flg = 'Y'
    THEN DELETE
    WHEN MATCHED 
    THEN UPDATE SET
         task_score = Source.task_score, 
         current_start_date = Source.current_start_date, 
         current_end_date = Source.current_end_date, 
         previous_end_date = Source.previous_end_date
    WHEN NOT MATCHED 
    THEN INSERT (task_id, task_score, current_start_date, current_end_date, previous_end_date) 
     VALUES (Source.task_id, Source.task_score, Source.current_start_date, Source.current_end_date, Source.previous_end_date);
    END; 
    Let us use this stored procedure.
    Filling a gap in the middle of the series
    The following code fills the gap on November 25th.
    CREATE TABLE NewTasks (..);
    INSERT INTO NewTasks
      (task_id, task_score, current_start_date, current_end_date, previous_end_date, deletion_flg)
    VALUES (1, 75, '2010-11-25', '2010-11-26', '2010-11-25', 'N'),
     (1, 80, '2010-11-26', '2010-11-27', '2010-11-26', 'N');
    EXEC MergeNewTasks NewTasks = NewTasks;  
    Here is the data after this modification, with a period added in the middle fo the series:
    Deleting a period in the middle of the series
    The following code deletes the period added in the previous example.
    CREATE TABLE NewTasks (..);
    INSERT INTO NewTasks
      (task_id, task_score, current_start_date, current_end_date, 
        previous_end_date, deletion_flg)
    VALUES (1, 75, '2010-11-25', '2010-11-26', '2010-11-25', 'Y'),
           (1, 80, '2010-11-26', '2010-11-27', '2010-11-25', 'N');
    EXEC MergeNewTasks;  
    Here is the data after this modification:
    Inserting two periods in the middle, and adjusting an exaisting period to make room for them. This is the last and most complex example involving our stored procedure:
    CREATE TABLE NewTasks (..);
    INSERT INTO NewTasks
      (task_id, task_score, current_start_date, current_end_date, previous_end_date, deletion_flg)
    VALUES (1, 98, '2010-11-20', '2010-11-22', '2010-11-03', 'N'), 
           (1, 75, '2010-11-22', '2010-11-23', '2010-11-22', 'N'),
           (1, 98, '2010-11-23', '2010-11-25', '2010-11-23', 'N');
    EXEC MergeNewTasks; 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • SQL Update statement taking too long..

    Hi All,
    I have a simple update statement that goes through a table of 95000 rows that is taking too long to update; here are the details:
    Oracle Version: 11.2.0.1 64bit
    OS: Windows 2008 64bit
    desc temp_person;
    Name                                                                                Null?    Type
    PERSON_ID                                                                           NOT NULL NUMBER(10)
    DISTRICT_ID                                                                     NOT NULL NUMBER(10)
    FIRST_NAME                                                                                   VARCHAR2(60)
    MIDDLE_NAME                                                                                  VARCHAR2(60)
    LAST_NAME                                                                                    VARCHAR2(60)
    BIRTH_DATE                                                                                   DATE
    SIN                                                                                          VARCHAR2(11)
    PARTY_ID                                                                                     NUMBER(10)
    ACTIVE_STATUS                                                                       NOT NULL VARCHAR2(1)
    TAXABLE_FLAG                                                                                 VARCHAR2(1)
    CPP_EXEMPT                                                                                   VARCHAR2(1)
    EVENT_ID                                                                            NOT NULL NUMBER(10)
    USER_INFO_ID                                                                                 NUMBER(10)
    TIMESTAMP                                                                           NOT NULL DATE
    CREATE INDEX tmp_rs_PERSON_ED ON temp_person (PERSON_ID,DISTRICT_ID) TABLESPACE D_INDEX;
    Index created.
    ANALYZE INDEX tmp_PERSON_ED COMPUTE STATISTICS;
    Index analyzed.
    explain plan for update temp_person
      2  set first_name = (select trim(f_name)
      3                    from ext_names_csv
      4                               where temp_person.PERSON_ID=ext_names_csv.p_id
      5                               and   temp_person.DISTRICT_ID=ext_names_csv.ed_id);
    Explained.
    @?/rdbms/admin/utlxpls.sql
    PLAN_TABLE_OUTPUT
    Plan hash value: 3786226716
    | Id  | Operation                   | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT            |                | 82095 |  4649K|  2052K  (4)| 06:50:31 |
    |   1 |  UPDATE                     | TEMP_PERSON    |       |       |            |          |
    |   2 |   TABLE ACCESS FULL         | TEMP_PERSON    | 82095 |  4649K|   191   (1)| 00:00:03 |
    |*  3 |   EXTERNAL TABLE ACCESS FULL| EXT_NAMES_CSV  |     1 |   178 |    24   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - filter("EXT_NAMES_CSV"."P_ID"=:B1 AND "EXT_NAMES_CSV"."ED_ID"=:B2)
    Note
       - dynamic sampling used for this statement (level=2)
    19 rows selected.By the looks of it the update is going to take 6 hrs!!!
    ext_names_csv is an external table that have the same number of rows as the PERSON table.
    ROHO@rohof> desc ext_names_csv
    Name                                                                                Null?    Type
    P_ID                                                                                         NUMBER
    ED_ID                                                                                        NUMBER
    F_NAME                                                                                       VARCHAR2(300)
    L_NAME                                                                                       VARCHAR2(300)Anyone can help diagnose this please.
    Thanks
    Edited by: rsar001 on Feb 11, 2011 9:10 PM

    Thank you all for the great ideas, you have been extremely helpful. Here is what we did and were able to resolve the query.
    We started with Etbin's idea to create a table from the ext table so that we can index and reference easier than an external table, so we did the following:
    SQL> create table ext_person as select P_ID,ED_ID,trim(F_NAME) fst_name,trim(L_NAME) lst_name from EXT_NAMES_CSV;
    Table created.
    SQL> desc ext_person
    Name                                                                                Null?    Type
    P_ID                                                                                         NUMBER
    ED_ID                                                                                        NUMBER
    FST_NAME                                                                                     VARCHAR2(300)
    LST_NAME                                                                                     VARCHAR2(300)
    SQL> select count(*) from ext_person;
      COUNT(*)
         93383
    SQL> CREATE INDEX EXT_PERSON_ED ON ext_person (P_ID,ED_ID) TABLESPACE D_INDEX;
    Index created.
    SQL> exec dbms_stats.gather_index_stats(ownname=>'APPD', indname=>'EXT_PERSON_ED',partname=> NULL , estimate_percent=> 30 );
    PL/SQL procedure successfully completed.We had a look at the plan with the original SQL query that we had:
    SQL> explain plan for update temp_person
      2  set first_name = (select fst_name
      3                    from ext_person
      4                               where temp_person.PERSON_ID=ext_person.p_id
      5                               and   temp_person.DISTRICT_ID=ext_person.ed_id);
    Explained.
    SQL> @?/rdbms/admin/utlxpls.sql
    PLAN_TABLE_OUTPUT
    Plan hash value: 1236196514
    | Id  | Operation                    | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT             |                | 93383 |  1550K|   186K (50)| 00:37:24 |
    |   1 |  UPDATE                      | TEMP_PERSON    |       |       |            |          |
    |   2 |   TABLE ACCESS FULL          | TEMP_PERSON    | 93383 |  1550K|   191   (1)| 00:00:03 |
    |   3 |   TABLE ACCESS BY INDEX ROWID| EXTT_PERSON    |     9 |  1602 |     1   (0)| 00:00:01 |
    |*  4 |    INDEX RANGE SCAN          | EXT_PERSON_ED  |     1 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       4 - access("EXT_PERSON"."P_ID"=:B1 AND "RS_PERSON"."ED_ID"=:B2)
    Note
       - dynamic sampling used for this statement (level=2)
    20 rows selected.As you can see the time has dropped to 37min (from 6 hrs). Then we decided to change the SQL query and use donisback's suggestion (using MERGE); we explained the plan for teh new query and here is the results:
    SQL> explain plan for MERGE INTO temp_person t
      2  USING (SELECT fst_name ,p_id,ed_id
      3  FROM  ext_person) ext
      4  ON (ext.p_id=t.person_id AND ext.ed_id=t.district_id)
      5  WHEN MATCHED THEN
      6  UPDATE set t.first_name=ext.fst_name;
    Explained.
    SQL> @?/rdbms/admin/utlxpls.sql
    PLAN_TABLE_OUTPUT
    Plan hash value: 2192307910
    | Id  | Operation            | Name         | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | MERGE STATEMENT      |              | 92307 |    14M|       |  1417   (1)| 00:00:17 |
    |   1 |  MERGE               | TEMP_PERSON  |       |       |       |            |          |
    |   2 |   VIEW               |              |       |       |       |            |          |
    |*  3 |    HASH JOIN         |              | 92307 |    20M|  6384K|  1417   (1)| 00:00:17 |
    |   4 |     TABLE ACCESS FULL| TEMP_PERSON  | 93383 |  5289K|       |   192   (2)| 00:00:03 |
    |   5 |     TABLE ACCESS FULL| EXT_PERSON   | 92307 |    15M|       |    85   (2)| 00:00:02 |
    Predicate Information (identified by operation id):
       3 - access("P_ID"="T"."PERSON_ID" AND "ED_ID"="T"."DISTRICT_ID")
    Note
       - dynamic sampling used for this statement (level=2)
    21 rows selected.As you can see, the update now takes 00:00:17 to run (need to say more?) :)
    Thank you all for your ideas that helped us get to the solution.
    Much appreciated.
    Thanks

  • Using IBIEE / RPD with MS SQL SERVER

    Currently using OBIEE 10.1.3.4.1 with our RPD. We are using MS SQL Server 2005.
    QUESTION: Why is the SQL Select statement using an Oracle SQL NVL Command?
    Is there a setting or something I can do to ensure MS SQL Server commands are used?
    Thank you
    Steven S. Brault
    Oracle - Consulting Technical Manager
    Odbc driver returned an error (SQLExecDirectW).
    Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 16001] ODBC error state: 37000 code: 8180 message: [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.. [nQSError: 16001] ODBC error state: 37000 code: 195 message: [Microsoft][ODBC SQL Server Driver][SQL Server]'nvl' is not a recognized built-in function name.. [nQSError: 16002] Cannot obtain number of columns for the query result. (HY000)
    SQL Issued: SELECT Risk."Risk Significance" saw_0, Risk."Risk Likelihood" saw_1, case Risk."Risk Likelihood" when Risk."Risk Likelihood" then 'Risk Likelihood' end saw_2, "Facts - Risk"."Risk Likelihood" saw_3, "Facts - Risk"."Risk Significance" saw_4, COUNT(DISTINCT "Facts - Risk"."Process Key") saw_5 FROM "GRC Diagnostics - Detail" ORDER BY saw_4, saw_3

    I am guessing your are using OOB Rpd and have OOB web catalog deployed , but running on a SQL server 2005.
    I ran into the same issue and foud out that some of the columns built in the OOB repository were based on Oracle DB functions ,which apparently as not supported by SQL server , you will have to go in and update the column calculations in the BM layer

  • SQL UPDATE statement in MS Excel

    Hi All,
    I have a request to perform a column update in ap_invoices_all table. There are around 1000 rows to be updated. The input is in the form of MS Excel.
    Can somebody suggest how to make an update statement using MS Excel.
    My query using excel should look like below:
    UPDATE AP_INVOICES_ALL
    SET description = '',
    last_update_date = ,
    last_updated_by =
    WHERE org_id =
    AND vendor_site_id =
    AND invoice_num = ''
    Regards,
    Radhika.

    >
    Can somebody suggest how to make an update statement using MS Excel.
    >
    as a way:
    -- create heterogeneous service for ms excel
    -- create dblink for this service
    -- do update like
    UPDATE AP_INVOICES_ALL
       SET description = (
                              with t as
                                select value_for_description,                                   
                                       org_id,
                                       vendor_site_id,
                                       invoice_num
                                 from sheet@dblink_to_excel
                              select t.value_for_description
                                from t t
                               where s.org_id = t.org_id
                                     and s.vendor_site_id = t.vendor_site_id
                                     and s.invoice_num = t.invoice_num
                            )other way:
    -- create heterogeneous service for ms excel
    -- create dblink for this service
    -- insert for some temporary table
    -- do update like above but based on temp table

Maybe you are looking for

  • How do I return to a previous time on my mac pro?

    How do I return to a previous time on my mac pro?  I accidently messed up my bookmarks and want to get them back the way they were just 2 days ago. Thank you

  • Quantity Contract Fields

    Hello Gurus, I would like to make certain fields to be seen in the document type MK (Contracts).  When I make my configurtion changes to make certain fields required specifically the target quantity field I do not see it come up at all in transaction

  • Is DAC 10.134 compatable with BI Apps 7.9.6.4 with Informatica 9.1 hotfix2?

    hi, since I cannot install dac11g successfully, may i know if DAC 10.1.3.4 is compatable with BI Apps 7.9.6.4 with Informatica 9.1 hotfix2 on windows x64 2008 R2 platform? Did anyone has experience on this combination? Thanks, Eddy

  • PSD file worked fine month ago - now corrupted

    Hihi, Suddenly I can´t open a psd file I saved on the 24th of January, I opened it im march but now I get this error window: COuld not complete your request because the file is not compatable with this version of Photoshop the file name is litun.psd

  • Error message in Outook

    Recently im getting the following error Task 'mail.btinternet.com - Receiving' reported error (0x800CCC90) : 'Your incoming (POP3) e-mail server has reported an internal error. If you continue to receive this message, contact your server administrato