FIRST ROWS OPTIMIZER HINT IN ORACLE

Hello All,
Version : Oracle9i Enterprise Edition Release 9.2.0.5.0 - 64bit Production
Can we use First Rows hint quick response time for application programming.
The java result set waits for query completion to achieve the complete result set.
Weird though to raise in a DB forum but i Guess most application might have used this and most of you would have come across this issue in application front.
Thanks
Vijay G

Exactly the same query should, more or less, perform exactly the same (except when statistics and optimizer parameters vary !), but adjusting for client / network latency overheads.
Are you sure that your Java program is actually submitting exactly the same SELECT statement to the Oracle server as your sqlplus or TOAD session is ? (btw, TOAD shows only the first 'n' rows).
Another question : Why do you have a PARALLEL Hint there ? That would make sense for a FullTableScan -- but your requirement should NOT be for a FullTableScan.
Your ORDER BY clause will not guarantee that the 21st row -- ie the 3rd page -- is different from the 20th row -- the last row on the second page.
See Tom Kyte's notes again.
http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
Hemant K Chitale
http://hemantoracledba.blogspot.com

Similar Messages

  • Give some hints that in a table control , first row will be editable and

    pls,
    give some hints that in a table control , first row will be editable and
    rest of the rows will be non-editable.

    Hi,
    Take the group1 for all the textboxes in table control as 'ABC'.
    Use this code, its working:-
    it_zekpo is my internal table w/o header line,
    wa_zekpo is work area.
    Name of input/output fields on screen are:-
    wa_zekpo-field1,
    wa_zekpo-field2, and so on...
    At screen flow-logic
    PROCESS BEFORE OUTPUT.
    *  MODULE status_8003.
      LOOP WITH CONTROL po_tb.
        MODULE read_data.
      ENDLOOP.
    PROCESS AFTER INPUT.
    *  MODULE user_command_8003.
      LOOP WITH CONTROL po_tb.
        MODULE modify_data.
      ENDLOOP.
    In PBO
    *&      Module  READ_DATA  OUTPUT
    MODULE read_data OUTPUT.
      READ TABLE it_zekpo INTO wa_zekpo INDEX po_tb-current_line. "po_tab is table control name
      "enable only first row and disable rest rows in table control.
      IF sy-subrc EQ 0.
        IF sy-tabix GE 2.
          IF screen-group1 = 'ABC'.
            LOOP AT SCREEN.
              SCREEN-INPUT = 0.
              SCREEN-ACTIVE = 0.
            ENDLOOP.
            MODIFY SCREEN.
          ENDIF.
        ENDIF.
      "disable empty rows
      ELSE.
        IF screen-group1 = 'ABC'.
          LOOP AT SCREEN.
            SCREEN-INPUT = 0.
            SCREEN-ACTIVE = 0.
          ENDLOOP.
          MODIFY SCREEN.
        ENDIF.
      ENDIF.
      data : line_count type i.
      describe it_zekpo
      lines line_count.
      po_tb-lines = line_count + 10.
      "to increase the number of lines in table control dynamically
    ENDMODULE.                 " READ_DATA  OUTPUT
    In PAI
    *&      Module  MODIFY_DATA  INPUT
    MODULE MODIFY_DATA INPUT.
      MODIFY IT_ZEKPO FROM WA_ZEKPO INDEX po_tb-currentline.
    ENDMODULE.                 " MODIFY_DATA  INPUT
    Hope this solves your problem.
    Thanks & Regards,
    Tarun Gambhir

  • How to include optimizer hints in Discoverer

    We have a Discoverer report which used to run fine prior to DB migration from (9.2.0.6 to 10G Rac 10.2.0.4).
    Since the database is migrated to 10g RAC same reports is running for longer time and failes with ROW_ID error,
    we ran the sql generated by the report in SQL Plus with below optimizer hint.
    Select /*+ optimizer_features_enable('9.2.0') */
    this query ran well with optimizer hint, but i am wondering how to use the optimizer hint in Discoverer Plus/Desktop.
    Select /*+ optimizer_features_enable('9.2.0') */
    C.EMPLOYEE_NUMBER||' '||A.EMPLOYEE_NAME, A.REPORTS_TO, C.SERVICE_CODE, COUNT(B.ACCOUNT_NUMBER)
    FROM PSTAGE.NEW_EMPLOYEE_MASTER A,
    PSTAGE.NEW_ALL_WORK_ORDER_MASTER B,
    PSTAGE.NEW_ALL_WORK_ORDER_DETAIL C
    WHERE ( ( B.WORK_ORDER_NUMBER = C.WORK_ORDER_NUMBER AND B.SITE_ID = C.SITE_ID )
    AND ( A.EMPLOYEE_NUMBER = C.EMPLOYEE_NUMBER AND A.SITE_ID = C.SITE_ID ) )
    AND ( B.WO_STATUS <> 'CN' )
    AND ( C.EMPLOYEE_NUMBER = ANY(SELECT S254_200018.EMPLOYEE_NUMBER
    FROM PSTAGE.NEW_EMPLOYEE_MASTER S254_199317,
    PSTAGE.NEW_ALL_WORK_ORDER_MASTER S254_199854,
    PSTAGE.NEW_ALL_WORK_O
    Thanks in advance

    Hi Sunil
    In the Administrator tool, you can add hints to the driving folder used in your query. A first glance at your report seems to indicate that B might be the driver.
    If you launch the Administrator tool, open the business area then right-click on the folder in question you can select Properties. The second to last property is called Optimizer hints. Try setting the same hint in here exactly the way you would do it inside SQL.
    I am not 100% sure whether this would take as this isn't a folder hint per se, but it is worth a try. You might also want to look at this thread: how to design Optimizer hints  to the generated SQL
    Another thing to check is to look at the code that is being generated by your Discoverer worksheets. Do you by chance see a NOREWRITE hint being added? This is a common issue with newer systems. This hint tells the database that the query cannot be rewritten which in most cases will cause poor performance. If this is happening to you I advise you to disable that hint. This is done by editing the pref.txt and adding a new preference called
    Out of the box, Discoverer Plus will sometimes add the NOREWRITE hint. This will cause Plus worksheets to operate much slower than Desktop worksheets. You can disable the NOREWRITE hint by adding a new preference called UseNoRewriteHint to pref.txt in the Database section. After you have done this you will have to run the apply preferences script.
    [Database]
    UseNoRewriteHint = 0
    Be sure to close all of your IE windows so that a new JVM is loaded.
    For example, you might turn on UseNoRewriteHint (i.e. set it to 1) if you want users to always query against the latest data (e.g. created today), even though this might be slower than querying the summary data (e.g. created yesterday). The NOREWRITE hint instructs the optimizer to disable query rewrite for the query block, which overrides the setting of the parameter QUERY_REWRITE_ENABLED.
    Default Value: 0
    Valid Values
    0 = Do not add the NOREWRITE hint. This is the one I recommend.
    1 = Do add the NOREWRITE hint.
    Another possible area is with query prediction. This is taken from an Oracle Note: Under some circumstance when you run a query against an Oracle 10g database, the queryprediction might take up the majority of time and CPU may hit 100%.
    The cause for this is an an Oracle10g (10.1) database issue but seeing as you are on 10.2 this might not be an issue any more. I throw it out there just in case you still hvae issues and want to raise this with Oracle. The last I heard is that the root cause was still under investigation in an unpublished Bug:4024370. There was a workaround to the issue:
    1. Disable Query Prediction (strongly recommended anyway):
    For Plus/Viewer:
    Edit pref.txt on the middle-tier server and set QPPEnable=0
    Run the applypreferences script (.sh or .bat)
    For Desktop:
    Edit the registry and set QPPEnable=0
    HKEY_CURRENT_USERS\Software\ORACLE\Discoverer <version>\Database
    2. If you still wish to use Query Prediction while the database issue is being investigate, then you can configure the Query Predictor to use the Explain Plan method rather than the Dynamic Views method.
    For Plus/Viewer:
    Edit pref.txt on the middle-tier server and set QPPObtainCostMethod=0
    Run the applypreferences script (.sh or .bat)
    For Desktop:
    Edit the registry and set QPPObtainCostMethod=0
    HKEY_CURRENT_USERS\Software\ORACLE\Discoverer <version>\Database
    Hope this helps
    Best wishes
    Michael

  • ODBC Driver adds ROWID next to SELECT and disables the optimizer hint

    I want to use an optimizer hint in my sql statement. For example: "select /*+ index(emp,status) +*/ status,name from emp where status=1". I have a bitmap index on status field, i want to force the select statement to use it. This one works fine from sql plus. If i execute the same statement from a VB application and run it via ODBC [Microsoft driver or oracle driver] it's sending the statement like "select rowid,/*+.....+*/ ...". I believe hint has to be next to the word SELECT, so it's not being used. I want to create an ADO connection from the vb application and create a recordset and loop through it and update some values. Any thoughts?
    I tried some other options...like
    select * from (select /*+ index(1,2) +*/....)
    select a.* from (select /*+ index(1,2) +*/...) a
    cn1.execute(sqltext) from vb..
    In all these three methods it's not adding a rowid next to select.. so hint is used and able to use the index. But having issues with updating the recordset. It says "query is not from one table" and "can't be updated" errors..

    The ODBC drivers are going to need to select the rowid in order to get an updatable or a scrollable recordset. Otherwise, they won't know which row in the database to update or how to fetch the previous rows without caching the entire recordset.
    Can you create a view from the hinted select statement and select from that? That's likely to be the fastest solution.
    Justin

  • Report sum on the first row

    Hi All,
    i have an report with a few columns an i sumerized them by clicking on the sum checkbox. My report result into data with a nice sum row at the bottom of the report.
    The question is, is it possible to get this summary line to the beginning of the report as the first row of the report ?
    Regards,
    Marco

    Yes, but you got to do that yourself like in this example using analytic functions:
    http://apex.oracle.com/pls/otn/f?p=31517:86
    You may put your totals wherever you want.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • [Solved] 27.8.4 How to Create a VO on a REF CURSOR - Missing first row

    Searching the forum I found: BC4J - Get one less row from view object.
    Dive into BC4J related  --REF CURSOR (Resultset)
    The first message did not have any answers, and the second had a follow up question - still no answers though - and I thought I would try a different title.
    (This is off topic, but it would be a great help if the search results also displayed the number of replys in the thread. That way, I wouldn't have to view the messages that don't have responses.)
    (This will be deployed on a server that has the ADF for JDeveloper 10.1.2 installed, so using that version of JDeveloper to develop the app.)
    Okay, back to the problem ==>
    I created a VO from a ref cursor, using the manual as a guide. When I run a page that displays a read only table of the view object, I am missing the first row. (Always the first row!) I don't have any order set, and if I call the ref cursor in a Java program for testing, I see all rows and the count is correct.
    One other point, when I call the page, I get the following validation error:
    Validation Error
    You must correct the following error(s) before proceeding:
    * JBO-29000: Unexpected exception caught: java.lang.ClassCastException, msg=null
    * null
    I still see the table, it is just missing the first row of data.
    In my form I have first, previous set, next set , and last
    navigation buttons. If I press last then first, the error goes away. I still don't see the missing row though.
    Any guidance would be appreciated! I can post my code, but it is pretty much the same code in the AdvancedViewObjectExamples.zip in the ViewObjectOnRefCursor example. I just substituted my two package calls (getRefCursor and getRefCursorCount).
    Thanks, Ken

    Went back to a backup copy of the source. Fixed the error. Now I'm back to just not being able to see the first row of data.
    Additional Note: I had removed fields in the display. Once I truncated the ps_txn table in the schema defined by the model, the data would display (Still without the first record.)
    Are there any examples that are more in depth than the few pages in the developer guide?
    Here is the code for my VOImpl class:
    package newslinearchive.model.datamodel;
    import java.math.BigDecimal;
    import java.sql.CallableStatement;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Timestamp;
    import java.sql.Types;
    import oracle.jbo.InvalidParamException;
    import oracle.jbo.JboException;
    import oracle.jbo.domain.Date;
    import oracle.jbo.domain.Number;
    import oracle.jbo.server.DBTransaction;
    import oracle.jbo.server.QueryCollection;
    import oracle.jbo.server.SQLBuilder;
    import oracle.jbo.server.ViewObjectImpl;
    import oracle.jbo.server.ViewRowImpl;
    import oracle.jbo.server.ViewRowSetImpl;
    import oracle.jdbc.driver.OracleCallableStatement;
    import oracle.jdbc.driver.OracleTypes;
    // --- File generated by Oracle ADF Business Components Design Time.
    // --- Custom code may be added to this class.
    // --- Warning: Do not modify method signatures of generated methods.
    public class SearchRefCursorImpl extends ViewObjectImpl {
    * This is the default constructor (do not remove)
    public SearchRefCursorImpl() {
    * Overridden framework method.
    * Executed when the framework needs to issue the database query for
    * the query collection based on this view object. One view object
    * can produce many related result sets, each potentially the result
    * of different bind variable values. If the rowset in query is involved
    * in a framework-coordinated master/detail viewlink, then the params array
    * will contain one or more framework-supplied bind parameters. If there
    * are any user-supplied bind parameter values, they will PRECEED the
    * framework-supplied bind variable values in the params array, and the
    * number of user parameters will be indicated by the value of the
    * numUserParams argument.
    protected void executeQueryForCollection(Object qc,Object[] params,int numUserParams) {
    storeNewResultSet(qc,retrieveRefCursor(qc,params));
    super.executeQueryForCollection(qc, params, numUserParams);
    * Overridden framework method.
    * Wipe out all traces of a built-in query for this VO
    protected void create() {
    getViewDef().setQuery(null);
    getViewDef().setSelectClause(null);
    setQuery(null);
    * Overridden framework method.
    * The role of this method is to "fetch", populate, and return a single row
    * from the datasource by calling createNewRowForCollection() and populating
    * its attributes using populateAttributeForRow().
    protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet rs) {
    * We ignore the JDBC ResultSet passed by the framework (null anyway) and
    * use the resultset that we've stored in the query-collection-private
    * user data storage
    rs = getResultSet(qc);
    * Create a new row to populate
    ViewRowImpl r = createNewRowForCollection(qc);
    try {
    * Populate new row by attribute slot number for current row in Result Set
    // populateAttributeForRow(r,0, rs.getLong(1));
    // populateAttributeForRow(r,1, rs.getString(2));
    // populateAttributeForRow(r,2, rs.getString(3));
    // MASTERID NOT NULL NUMBER
    populateAttributeForRow(r,0, rs.getBigDecimal(1));
    //ID NOT NULL NUMBER
    populateAttributeForRow(r,1, rs.getBigDecimal(2));
    // CAID NOT NULL NUMBER
    populateAttributeForRow(r,2, rs.getBigDecimal(3));
    // LANGUAGE NOT NULL VARCHAR2(30)
    populateAttributeForRow(r,3, rs.getString(4));
    // IS_CURRENT_VERSION NOT NULL NUMBER(1)
    populateAttributeForRow(r,4, rs.getBigDecimal(5));
    // FOLDER_ID NOT NULL NUMBER
    populateAttributeForRow(r,5, rs.getBigDecimal(6));
    // FOLDER_REGION_ID NOT NULL NUMBER
    populateAttributeForRow(r,6, rs.getBigDecimal(7));
    // NAME NOT NULL VARCHAR2(256)
    populateAttributeForRow(r,7, rs.getString(8));
    // DISPLAY_NAME VARCHAR2(256)
    populateAttributeForRow(r,8, rs.getString(9));
    // ITEMTYPE NOT NULL VARCHAR2(30)
    populateAttributeForRow(r,9, rs.getString(10));
    // SUBTYPE VARCHAR2(40)
    populateAttributeForRow(r,10, rs.getString(11));
    // SUBTYPE_CAID NUMBER
    populateAttributeForRow(r,11, rs.getBigDecimal(12));
    // PARENT_ITEM_ID NUMBER
    populateAttributeForRow(r,12, rs.getBigDecimal(13));
    // CATEGORY_ID NUMBER
    populateAttributeForRow(r,13, rs.getBigDecimal(14));
    // CATEGORY_CAID NUMBER
    populateAttributeForRow(r,14, rs.getBigDecimal(15));
    // AUTHOR VARCHAR2(50)
    populateAttributeForRow(r,15, rs.getString(16));
    // DESCRIPTION VARCHAR2(2000)
    populateAttributeForRow(r,16, rs.getString(17));
    // PUBLISH_DATE NOT NULL DATE
    populateAttributeForRow(r,17, rs.getDate(18));
    // EXPIREMODE VARCHAR2(90)
    populateAttributeForRow(r,18, rs.getString(19));
    // EXPIRENUMBER NUMBER
    populateAttributeForRow(r,19, rs.getBigDecimal(20));
    // EXPIREDATE DATE
    populateAttributeForRow(r,20, rs.getDate(21));
    // IMAGE VARCHAR2(350)
    populateAttributeForRow(r,21, rs.getString(22));
    // KEYWORDS VARCHAR2(2000)
    populateAttributeForRow(r,22, rs.getString(23));
    // URL VARCHAR2(4000)
    populateAttributeForRow(r,23, rs.getString(24));
    // FILENAME VARCHAR2(350)
    populateAttributeForRow(r,24, rs.getString(25));
    // TEXT CLOB()
    populateAttributeForRow(r,25, rs.getClob(26));
    // FOLDER_LINK_ID NUMBER
    populateAttributeForRow(r,26, rs.getBigDecimal(27));
    // FOLDER_LINK_CAID NUMBER
    populateAttributeForRow(r,27, rs.getBigDecimal(28));
    // ACTIVE NOT NULL NUMBER(1)
    populateAttributeForRow(r,28, rs.getBigDecimal(29));
    // CAN_BE_CHECKEDOUT NUMBER(1)
    populateAttributeForRow(r,29, rs.getBigDecimal(30));
    // IS_ITEM_CHECKEDOUT NUMBER(1)
    populateAttributeForRow(r,30, rs.getBigDecimal(31));
    // CHECKER_USERNAME VARCHAR2(256)
    populateAttributeForRow(r,31, rs.getString(32));
    // CHECKOUT_DATE DATE
    populateAttributeForRow(r,32, rs.getDate(33));
    // FULLSCREEN NOT NULL NUMBER(1)
    populateAttributeForRow(r,33, rs.getBigDecimal(34));
    // INPLACE NOT NULL NUMBER(1)
    populateAttributeForRow(r,34, rs.getBigDecimal(35));
    // CREATEDATE NOT NULL DATE
    populateAttributeForRow(r,35, rs.getDate(36));
    // CREATOR NOT NULL VARCHAR2(256)
    populateAttributeForRow(r,36, rs.getString(37));
    // UPDATEDATE DATE
    populateAttributeForRow(r,37, rs.getDate(38));
    // UPDATOR VARCHAR2(256)
    populateAttributeForRow(r,38, rs.getString(39));
    // SECURITY VARCHAR2(25)
    populateAttributeForRow(r,39, rs.getString(40));
    // VISIBLE NOT NULL NUMBER(1)
    populateAttributeForRow(r,40, rs.getBigDecimal(41));
    // SEQUENCE NOT NULL NUMBER
    populateAttributeForRow(r,41, rs.getBigDecimal(42));
    // CATEGORY_SEQUENCE NOT NULL NUMBER
    populateAttributeForRow(r,42, rs.getBigDecimal(43));
    // AUTHOR_SEQUENCE NOT NULL NUMBER
    populateAttributeForRow(r,43, rs.getBigDecimal(44));
    // CREATE_DATE_SEQUENCE NOT NULL NUMBER
    populateAttributeForRow(r,44, rs.getBigDecimal(45));
    // ITEMTYPE_SEQUENCE NOT NULL NUMBER
    populateAttributeForRow(r,45, rs.getBigDecimal(46));
    catch (SQLException s) {
    throw new JboException(s);
    return r;
    * Overridden framework method.
    * Return true if the datasource has at least one more record to fetch.
    protected boolean hasNextForCollection(Object qc) {
    ResultSet rs = getResultSet(qc);
    boolean nextOne = false;
    try {
    nextOne = rs.next();
    * When were at the end of the result set, mark the query collection
    * as "FetchComplete".
    if (!nextOne) {
    setFetchCompleteForCollection(qc, true);
    * Close the result set, we're done with it
    rs.close();
    catch (SQLException s) {
    throw new JboException(s);
    return nextOne;
    * Overridden framework method.
    * The framework gives us a chance to clean up any resources related
    * to the datasource when a query collection is done being used.
    protected void releaseUserDataForCollection(Object qc, Object rs) {
    * Ignore the ResultSet passed in since we've created our own.
    * Fetch the ResultSet from the User-Data context instead
    ResultSet userDataRS = getResultSet(qc);
    if (userDataRS != null) {
    try {
    userDataRS.close();
    catch (SQLException s) {
    /* Ignore */
    super.releaseUserDataForCollection(qc, rs);
    * Overridden framework method
    * Return the number of rows that would be returned by executing
    * the query implied by the datasource. This gives the developer a
    * chance to perform a fast count of the rows that would be retrieved
    * if all rows were fetched from the database. In the default implementation
    * the framework will perform a SELECT COUNT(*) FROM (...) wrapper query
    * to let the database return the count. This count might only be an estimate
    * depending on how resource-intensive it would be to actually count the rows.
    public long getQueryHitCount(ViewRowSetImpl viewRowSet) {
    Long result = (Long)callStoredFunction(NUMBER,
    "PORTAL.SEARCH_REFCURSOR.getRefCursorCount",
    viewRowSet.getParameters(true));
    return result.longValue();
    // ------------- PRIVATE METHODS ----------------
    * Return a JDBC ResultSet representing the REF CURSOR return
    * value from our stored package function.
    * new Object[]{getNamedBindParamValue("Email",params)}
    private ResultSet retrieveRefCursor(Object qc, Object[] params) {
    ResultSet rs = (ResultSet)callStoredFunction(OracleTypes.CURSOR,
    "PORTAL.SEARCH_REFCURSOR.getRefCursor",
    null);
    return rs ;
    private Object getNamedBindParamValue(String varName, Object[] params) {
    Object result = null;
    if (getBindingStyle() == SQLBuilder.BINDING_STYLE_ORACLE_NAME) {
    if (params != null) {
    for (Object param : params) {
    Object[] nameValue = (Object[])param;
    String name = (String)nameValue[0];
    if (name.equals(varName)) {
    return (String)nameValue[1];
    throw new JboException("No bind variable named '"+varName+"'");
    * Store a new result set in the query-collection-private user-data context
    private void storeNewResultSet(Object qc, ResultSet rs) {
    ResultSet existingRs = getResultSet(qc);
    // If this query collection is getting reused, close out any previous rowset
    if (existingRs != null) {
    try {existingRs.close();} catch (SQLException s) {}
    setUserDataForCollection(qc,rs);
    hasNextForCollection(qc); // Prime the pump with the first row.
    * Retrieve the result set wrapper from the query-collection user-data
    private ResultSet getResultSet(Object qc) {
    return (ResultSet)getUserDataForCollection(qc);
    * Return either null or a new oracle.jbo.domain.Date
    private static Date nullOrNewDate(Timestamp t) {
    return t != null ? new Date(t) : null;
    * Return either null or a new oracle.jbo.domain.Number
    private static Number nullOrNewNumber(BigDecimal b) {
    try {
    return b != null ? new Number(b) : null;
    catch (SQLException s) { }
    return null;
    //----------------[ Begin Helper Code ]------------------------------
    public static int NUMBER = Types.NUMERIC;
    public static int DATE = Types.DATE;
    public static int VARCHAR2 = Types.VARCHAR;
    public static int CLOB = Types.CLOB;
    * Simplifies calling a stored function with bind variables
    * You can use the NUMBER, DATE, and VARCHAR2 constants in this
    * class to indicate the function return type for these three common types,
    * otherwise use one of the JDBC types in the java.sql.Types class.
    * NOTE: If you want to invoke a stored procedure without any bind variables
    * ==== then you can just use the basic getDBTransaction().executeCommand()
    * @param sqlReturnType JDBC datatype constant of function return value
    * @param stmt stored function statement
    * @param bindVars Object array of parameters
    * @return function return value as an Object
    protected Object callStoredFunction(int sqlReturnType, String stmt,
    Object[] bindVars) {
    CallableStatement st = null;
    try {
    st = getDBTransaction().createCallableStatement("begin ? := " + stmt +
    "; end;", 0);
    st.registerOutParameter(1, sqlReturnType);
    if (bindVars != null) {
    for (int z = 0; z < bindVars.length; z++) {
    st.setObject(z + 2, bindVars[z]);
    st.executeUpdate();
    return st.getObject(1);
    catch (SQLException e) {
    throw new JboException(e);
    finally {
    if (st != null) {
    try {
    st.close();
    catch (SQLException e) {}
    /**Gets the bind variable value for Email
    public String getEmail() {
    return (String)getNamedWhereClauseParam("Email");
    /**Sets <code>value</code> for bind variable Email
    public void setEmail(String value) {
    setNamedWhereClauseParam("Email", value);
    /**getEstimatedRowCount - overridden for custom java data source support.
    public long getEstimatedRowCount() {
    long value = super.getEstimatedRowCount();
    return value;
    Thanks, Ken

  • Getting the first row for each group

    Hi Everyone,
    I have a query which returns a number of rows, all of which are valid. What I need to do is to get the first row for each group and work with those records.
    For example ...
    client flight startairport destairport stops
    A fl123 LGW BKK 2
    A fl124 LHR BKK 5
    B fl432 LGW XYZ 7
    B fl432 MAN ABC 8
    .... etc.
    I would need to return one row for Client A and one row for Client B (etc.) but find that I can't use the MIN function because it would return the MIN value for each column (i.e. mix up the rows). I also can use the rownum=1 because this would only return one row rather than one row per group (i.e. per client).
    I have been investigating and most postings seem to say that it needs a second query to look up the first row for each grouping. This is a solution which would not really be practical because my query is already quite complex and incorporating duplicate subqueries would just make the whole thing much to cumbersome.
    So what I really new is a "MIN by group" or a "TOP by group" or a "ROWNUM=1 by group" function.
    Can anyone help me with this? I'm sure that there must be a command to handle this.
    Regards and any thanks,
    Alan Searle
    Cologne, Germany

    Something like this:
    select *
    from (
       select table1.*
       row_number() over (partition by col1, col2 order by col3, col4) rn
       from table1
    where rn = 1In the "partition by" clause you place what you normally would "group by".
    In the "order by" clause you define which will have row_number = 1.
    Edit:
    PS. The [url http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions004.htm#i81407]docs have more examples on using analytical functions ;-)
    Edited by: Kim Berg Hansen on Sep 16, 2011 10:46 AM

  • Can't fetch XMLType after getting first row

    Hi - when I call OCIDefineObject in a sub function, after getting the first row of XMLType value, the program can't fetch subsequent rows and stops. If I call OCIDefineObject in the same memory space of where the fetch call locates, it works out fine. Somehow the persistency of xmldocnode can not last.
    Any clues? I can email out both working/non-working programs upon request.
    my environment is Oracle 11g on Solaris box.
    Sample Code: (fetch only the first row and stop)
    char orderNumData[4001];
    xmldocnode* xmlData = (xmldocnode *) 0;
    xmldocnode** xmlDatap = &xmlData;
    defineStr(define_orderNum, (char*)&orderNumData, 4001);
    defineXML(define_customerdata, xmlDatap );
    rc = OCIStmtExecute ( svc, stmt, err,
              1,
              0, NULL, NULL,
              OCI_DEFAULT);
    cout << "OrdNum: " << orderNumData << endl;
    displayXML (xmlData);
    while ((rc = OCIStmtFetch2 (stmt, err, 1,
    OCI_FETCH_NEXT,
    (ub4) 1,
    OCI_DEFAULT )) == OCI_SUCCESS)
    cout << "OrdNum: " << orderNumData << endl;
    displayXML (xmlData);
    void defineXML ( OCIDefine defineHdn, xmldocnode *xmlDatap )
    ociStatus = OCITypeByName( env,
    err,
    svc,
    (const text *) "SYS",
    (ub4) strlen((char *)"SYS"),
    (const text *) "XMLTYPE",
    (ub4) strlen((char *)"XMLTYPE"),
    (CONST text *) 0,
    (ub4) 0,
    OCI_DURATION_SESSION,
    OCI_TYPEGET_HEADER,
    (OCIType **) &xmltdo);
    ociStatus = OCIDefineByPos ( stmt,
    &defineHdn,
    err,
    pos,
    (dvoid *) 0,
    (sb4) 0,
    SQLT_NTY,
    (dvoid *) 0,
    (ub2 *)0,
    (ub2 *)0,
    (ub4) OCI_DEFAULT );
    ociStatus = OCIDefineObject( defineHdn,
    err,
    (OCIType *) xmltdo,
    (dvoid **) xmlDatap,
    &xmlSize,
    (dvoid **) &indp,
    (ub4 *) 0);
    Working one:
    Instead if I call OCITypeByName, OCIDefineByPos,
    and OCIDefineByPos right before the OCIStmtExecute() in the main,
    then all results can be returned.
    OCITypeByName(...)
    OCIDefineByPos(...)
    OCIDefineObject(...)
    rc = OCIStmtExecute ( svc, stmt, err,
    1,
    0, NULL, NULL,
    OCI_DEFAULT);
    cout << "OrdNum: " << orderNumData << endl;
    displayXML (xmlData);
    while ((rc = OCIStmtFetch2 (stmt, err, 1,
    OCI_FETCH_NEXT,
    (ub4) 1,
    OCI_DEFAULT )) == OCI_SUCCESS)
    cout << "OrdNum: " << orderNumData << endl;
    displayXML (xmlData);
    Thanks,
    Terrence

    void defineXML ( OCIDefine defineHdn, xmldocnode *xmlDatap ) { ...
    ociStatus = OCIDefineObject(
    defineHdn, err, (OCIType *) xmltdo, (dvoid **) xmlDatap,
    &xmlSize, (dvoid **) &indp, (ub4 *) 0);
    Instead if I call OCITypeByName, OCIDefineByPos,
    and OCIDefineByPos right before the OCIStmtExecute()
    in the main, then all results can be returned.I ran into this issue myself (was going nuts until a smarter colleague open my eyes on the issue). The problem is that you passing addresses of local variables in defineXML for xmlSize and indp, when the addresses you pass must remain valid for the whole fetch. (xmlSize is not written to apparently, by indp is for sure, so you are writing/corrupting your program stack...)
    To resolve this, I use a stack allocated helper struct whose lifetime extends the fetch, and which is referenced in the bind_object method. --DD
    struct ObjectBindInfo {
        void* p_value;
        void* p_indicator;
        ub4 value_size;
        ub4 indicator_size;
    static void insert_one_object(ub4 id) { ...
        sql_point pt(id);
        ObjectBindInfo pt_info(pt, &pt.indicator_);
        stmt.bind_object(conn, 2, pt, pt_info);
    ... void Statement::bind_object(
        Connection& conn, ub4 position, ..., ObjectBindInfo& obj_info
        // WARNING: Addresses passed to OCIBindObject MUST still be
        // valid after OCIStmtExecute, so cannot be addresses to local
        // (stack) vars. Thus the use of ObjectBindInfo...
        checkerr(
            OCIBindObject(
                bind_hndl, errhp(), tdo,
                (void**)&obj_info.p_value,     &obj_info.value_size,
                (void**)&obj_info.p_indicator, &obj_info.indicator_size
            errhp()
    }Of course, you've noticed that I talk about binds above, but the fact that you need to provide non-local var addresses to OCI applies to defines as well. --DD
    Message was edited by: ddevienne

  • 64-bit driver only returns first row of table

    I have a C++ application using ADO (the MSADO COM components) and the Oracle OLEDB provider for database access. The application works fine on a 32-bit computer using the 32-bit Oracle client and driver. However, when I run a 64-bit build of the application, running on a 64-bit computer (Windows Server 2008 x64), using the 64-bit Oracle client and driver, a SELECT operation returns only the first row of the table.
    Note that this is only happening with the ActiveX ADO components. ADO.NET is not having a problem.
    In both cases I am connecting to the same database, which is Oracle 10.2 (32-bit) running on a different server. I have tested with Oracle client 10.2.0.4 and 11.1.0.7 and got the same result in both cases.
    I have reproduced the issue with a simple table (one column, NVARCHAR2(255)) and simple code.
    In the code, I execute "select count(*) from tablename" and get the correct record count (more than one record). But when I then open the recordset ("select columnname from tablename"), ADO reports EndOfFile after I have read the first row and called MoveNext on the recordset.
    My Oracle knowledge is limited so I don't know if there are driver properties I should be checking.
    Anyone have ideas?
    Thanks in advance.

    For 10.2 it's fixed in 10204 Patch 21 and higher.
    For 11.1 it's fixed in 11107 Patch 12 and higher.
    Cheers,
    Greg

  • Only first row of a mysql table is updated

    Hi,
    I'm using Netbeans 5.5 with Visual Web Pack and trying to update data, stored in a mysql table.
    I use a dropdown list to select a row and show the data in various textfields. This works fine. The problem, that it's not possible to save changes, I enter in the textfields. Everytime only the first row of the table will be (over)written. This happens also with the derby database. I checked the tutorial about inserting, updatting and deleting, it works fine. But they use a table to make changes to the data, so the case is different from mine.
    Can anybody give me a hint? I'm going crazy ...
    Thanx in advance
    Markus

    yes this sounds crazy. i encountered similar problem with textfields. if they are numerous type, don't forget to add integerConverter to the textfield. it helped me out in my case. hope this helps
    dElay

  • File Adapter - Skipping first row (header row) in a csv file

    How can I skip processing the first row in BPEL? I have a csv file and the first row has column header that I should not process.
    Thanks

    Hi,
    Use nxsd:headerLines="1" in the declaration section see the sample below
    Name,Street,City,State,Country
    ABC Private Limited, Street 1, Bangalore, Karnataka, India
    XYZ Private Limited, Street 2, Bangalore, Karnataka, India
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd"
                targetNamespace="http://www.oracle.com/ias/processconnect"
                xmlns:tns="http://www.oracle.com/ias/processconnect"
                elementFormDefault="qualified"
                attributeFormDefault="unqualified"
                nxsd:encoding="US-ASCII"
                *nxsd:headerLines="1"*            nxsd:stream="chars"
                nxsd:version="NXSD">  <xsd:element name="AddressBook">
        <xsd:complexType>
          <xsd:sequence>
           <xsd:element name="Address" minOccurs="1" maxOccurs="unbounded">
             <xsd:complexType>
               <xsd:sequence>
                 <xsd:element name="Name" type="xsd:string" nxsd:style="terminated"
                    nxsd:terminatedBy="," >
                  </xsd:element>
                 <xsd:element name="Street" type="xsd:string" nxsd:style="terminated"
                    nxsd:terminatedBy="," >
                 </xsd:element>
                 <xsd:element name="City" type="xsd:string" nxsd:style="terminated"
                    nxsd:terminatedBy="," >
                 </xsd:element>
                 <xsd:element name="State" type="xsd:string" nxsd:style="terminated"
                    nxsd:terminatedBy="," >             </xsd:element>
                 <xsd:element name="Country" type="xsd:string" nxsd:style="terminated"
                    nxsd:terminatedBy="${eol}" >
                 </xsd:element>
               </xsd:sequence>
             </xsd:complexType>
           </xsd:element>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>

  • Optimizer mode in oracle 10g

    what is the difference between setting optimizer mode in oracle 10g
    optimizer_mode=choose
    optimizer_mode=all_rows

    user446367 wrote:
    what i have to set for the below parameters . any idea ?
    optimizer_index_caching
    optimizer_index_cost_adjIn general you would leave them set at the default value in 10g (and probably, in most earlier versions, for most cases as well). Even if you were to change them, asking for specific values on an internet forum is rather asking for trouble, it's not dissimilar to asking "what should I set for the parameter processes?" A reasonable value will be application dependent.
    The first parameter reduces the cost of some types of indexed access by assuming that only the specified percentage of index i/o actually results in a physical I/O and therefore only that percentage of the io cost is taken into account. By contrast all tablescan access and the other types of indexed access are assumed to be uncached and therefore need costing.
    The second parameter just arbitrarily scales indexed access path costings.
    You could argue, and some have, that you could calculate a cache hit ratio for index blocks in much the same way as you can calculate a cache hit ratio generally and then set the first parameter to this value. The standout problems with this approach are
    1) It applies to all matching statements and objects not just your problem ones.
    2) It doesn't necessarily even apply to your problem statements.
    3) It doesn't have anything to do with query duration per se, just efficiency of one particular access path.
    4) People tend to choose to round costs down and make the likelihood of two plans getting the same cost and being chosen on a tiebreaker basis higher.
    The second parameter just asks you how much you like the idea of indexes generally. If you are going to change it pick a family members age or something - it'll make you smile every time you see it.
    Niall Litchfield
    http://www.orawin.info/

  • Showing data for the first row only

    Oracle Experts ,
    Below is my table in oracle.I wnat show Company ID only for the first row of each company. Table 2 is my output .
    Company Country Company ID
    BARCALAYS UK 1
    BARCALAYS USA 1
    BARCALAYS Australia 1
    Kingfisher UK 2
    Kingfisher INDIA 2
    Kingfisher INDIA 2
    Output Table 2 :
    Company Country Company ID
    BARCALAYS UK 1
    BARCALAYS USA Null
    BARCALAYS Australia Null
    Kingfisher UK 2
    Kingfisher INDIA Null
    Kingfisher INDIA Null
    Please give me a sql query.
    Many thanks in advance .
    Regards,
    Dirasa

    based on if a particular country is appearing twice for the same company and company_id wether to show the company_id for that country or not you may use any of the below queries :)
    /* Will show compan_ID twice if the country is repeated */
      with x as (
          select 'Foo' company_name, 'UK' country, 1 company_id from dual
          union all
          select 'Foo', 'USA', 1 from dual
          union ALL
           select 'Foo', 'USA', 1 from dual
           UNION ALL
          select 'Foo', 'AUS', 1 from dual
          union ALL
        select 'Foo', 'AUS', 1 from dual
          union all     
          select 'Bar', 'UK', 2 from dual
          union all
         select 'Bar', 'USA', 2 from dual
         union all
         select 'Bar', 'India', 2 from dual
    SELECT company_name,country,CASE WHEN rn=1 THEN company_id ELSE NULL END company_id
       FROM (SELECT
       company_name,company_id,country,rank()over(PARTITION BY company_name,company_id ORDER BY country) rn
        FROM x)
    /* Will NOT show compan_ID twice even if the country is repeated */   
      with x as (
          select 'Foo' company_name, 'UK' country, 1 company_id from dual
          union all
          select 'Foo', 'USA', 1 from dual
          union all
          select 'Foo', 'AUS', 1 from dual
          union ALL
        select 'Foo', 'AUS', 1 from dual
          union all     
                 select 'Foo', 'USA', 1 from dual
           UNION ALL
          select 'Bar', 'UK', 2 from dual
          union all
         select 'Bar', 'USA', 2 from dual
         union all
         select 'Bar', 'India', 2 from dual
    SELECT company_name,country,CASE WHEN rn=1 THEN company_id ELSE NULL END company_id
       FROM (SELECT
       company_name,company_id,country,row_number()over(PARTITION BY company_name,company_id ORDER BY country) rn
        FROM x)
    /* Will show compan_ID twice if the country is repeated */
      with x as (
          select 'Foo' company_name, 'UK' country, 1 company_id from dual
          union all
          select 'Foo', 'USA', 1 from dual
          union ALL
           select 'Foo', 'USA', 1 from dual
           UNION ALL     
          select 'Foo', 'AUS', 1 from dual
          union ALL
        select 'Foo', 'AUS', 1 from dual
          union all     
          select 'Bar', 'UK', 2 from dual
          union all
         select 'Bar', 'USA', 2 from dual
         union all
         select 'Bar', 'India', 2 from dual
    SELECT company_name,country,CASE WHEN rn=1 THEN company_id ELSE NULL END company_id
       FROM (SELECT
       company_name,company_id,country,dense_rank()over(PARTITION BY company_name,company_id ORDER BY country) rn
        FROM x)
                    Cheers!!!
    Bhushan

  • LOV defaults to first row

    Hi,
    I have an LOV from a VO on my JSF page. When i open the page, the first row from the VO gets defaulted into this field. i do not want this. I want no value to be there aso that user selects the value.
    Thanks,
    lakshmi.

    "Edit the LOV in the VO, goto UI Hints tab, select "Include NO Selection Item - > Blank Item"
    This should have worked for you... did u deploy the model lov..
    Key attribute is to be set for the lov vo for any validation that has to be done..

  • First row from Service Order Object list not stored in OBJK table

    Hi all,
    Please be patience with my terminology .
    Could you please explain me if we have SO created based on notification, and that notification already have Equipment number, why this equipment is not created in OBJK table? So always the first row (as in attachment) is not stored in OBJK, other rows(objects) are there.
    I know the EQUNR is stored in AFIH, but it's useless for us because I'm creating HANA analytical view with following join logic (simplified):
    AFIH.OBKNR=OBJK.OBKNR
    OBJK.ILOAN=ILOA.ILOAN
    ILOA.TPLNR=IFLOT.TPLNR
    ILOA.ILOAN=EQUZ.ILOAN (where EQUZ.DATBI='99991231')
    EQUZ.EQUNR=EQUI.EQUNR
    The join logic might not be 100% correct.
    Thank you for your help.

    Using the tags to format your code may help you get a response sooner than later.
    This and other useful pieces of information are located in the  FAQ
    http://wiki.oracle.com/page/Oracle+Discussion+Forums+FAQ                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for