Limit number of rows from wildcard expansion- DRG-51030

We use CONTEXT iindex in 11g to search on a text DB column, "Name".
This is used in a UI to show autosuggest list of 25 matching names.
When the end user types an 'a' we want to show a list of the first 25 names that contain an 'a'.
We hit the issue of too many matches in the wildcard expansion query:
DRG-51030: wildcard query expansion resulted in too many terms
This is a frequent use case when the user types just 1 character ('a' will easily match over 50K names in our case).
Is there a way to make the wildcard expansion query only return the first 25 rows?
We never show more than 25 names in our UI - so we would like the expansion query to also return max of 25 rows.
Our query is:
SELECT ResEO.DISPLAY_NAME,
ResEO.RESOURCE_ID,
ResEO.EMAIL
FROM RESOURCE_VL ResEO
WHERE CONTAINS (ResEO.DISPLAY_NAME , '%' || :BindName || '%' )>0
Also,
Is there a way to use CTXCAT type of index and achieve this (expansion query limit of 25)?
We are considering switching to CTXCAT index based on documentation that recommends this type of an index for better performance.

Your best bet may be to look up the words directly in the $I token table.
If your index is called NAME_INDEX you could do:
select /* FIRST_ROWS(25) */ token_text from
  (  select token_text
     from dr$name_index$i  
     where token_text like 'A%' )
where rownum < 26;That should be pretty quick.
However, if you really want to do %A% - any word which has an A in it - it's not going to be so good, because this will prevent the index being used on the $I table - so it's going to do a full table scan. In this case you really need to think a bit harder about what you're trying to achieve and why. Does it really make any sense to return 25 names which happen to have an A in them? Why not wait until the user has typed a few more characters - 3 perhaps? Or use my technique for one or two letters, then switch over to yours at three characters (or more).
A couple of notes:
- Officially, accessing the $I table is not supported, in that it could change in some future version, though it's pretty unlikely.
- I trust you're using the SUBSTRING_INDEX option if you're doing double truncated searches - a wild card at the beginning and end. If not, your performance is going to be pretty poor.

Similar Messages

  • Resukt:Get number of rows from 3 different table...?

    Hi All,
    I need to find out number of rows from 3 different table for the same conditions. Instead of writing 3 queries, is it possible to get it thru one query?
    For example, i need to find out number of rows in tables where name = 'Ameet' from 3 different table, i will end writing 3 queries.
    1. select count(1) from table_a where name = 'Ameet';
    1. select count(1) from table_b where name = 'Ameet';
    1. select count(1) from table_c where name = 'Ameet';
    Is it possible to write a single query to get result of all above 3 queries?
    result:
    table_a table_b table_c
    34 44 2

    One way:
    SELECT      (SELECT     COUNT(*) AS CNT FROM TABLE_A WHERE name='Ameet') AS TABLE_A
    ,     (SELECT     COUNT(*) AS CNT FROM TABLE_B WHERE name='Ameet') AS TABLE_B
    ,     (SELECT     COUNT(*) AS CNT FROM TABLE_C WHERE name='Ameet') AS TABLE_C
    FROM DUALIf you want the total:
    SELECT     SUM(CNT)
    FROM
         SELECT     COUNT(*) AS CNT FROM TABLE_A WHERE name='Ameet'
         UNION ALL
         SELECT     COUNT(*) FROM TABLE_B WHERE name='Ameet'
         UNION ALL
         SELECT     COUNT(*) FROM TABLE_C WHERE name='Ameet'
    )

  • Limit Number of Rows on a Page

    Hi all,
    I am unable to succeed with the following.
    I have an XML data source which looks like this:
    <?xml version="1.0"?>
    <LIST_GEMPLOYEES>
    <LIST_G_EMPLOYEE>
    <EMPLOYEE_NUMBER>1</EMPLOYEE_NUMBER>
    <EMPLOYEE_NAME>Employee 1</EMPLOYEE_NAME>
    </LIST_G_EMPLOYEE>
    <LIST_G_EMPLOYEE>
    <EMPLOYEE_NUMBER>2</EMPLOYEE_NUMBER>
    <EMPLOYEE_NAME>Employee 2</EMPLOYEE_NAME>
    </LIST_G_EMPLOYEE>
    <!-- many rows here (LIST_G_EMPLOYEE tags) -->
    </LIST_GEMPLOYEES>
    And I want to define a template which only allows 5 rows on a page.
    What I did:
    I should insert a page break after the limit number of rows on a page is reached. This means that, after each group of 5 rows, a page break should be inserted.
    To accomplish this goal, I followed these steps:
    1. Define a field which will contain and initialize the Counter variable before the table which will show the list of employees, by using the syntax:
    Field1: <?xdoxslt:set_variable($_XDOCTX, ’Counter’, 0)?>
    2. Define the table which list all employees in the data source:
    2.1. Use a 2 columns table. In the first column, define 2 fields as follows:
    2.2. In the second column, define 6 fields containing the following code:
    Field2: <?for-each: LIST_G_EMPLOYEE?>
    Field3: <?EMPLOYEE_NUMBER?>
    Field4: <?xdoxslt:set_variable($_XDOCTX, ’Counter’, xdoxslt: get_variable($_XDOCTX, ’Counter’) + 1)?>
    Field5: <?EMPLOYEE_NAME?>
    Field6: <?if: xdoxslt:get_variable($_XDOCTX, ’Counter’) mod 5=0?>
    Field7: <?split-by-page-break:?>
    Field8: <?end if?>
    Field9: <?end for-each?>
    Here is explanation for syntax I used:
    Field1: Declare and init Counter variable to value = 0
    Field2: This fetches through all employees - start a for-each cycle
    Field3: This prints the employee number
    Field4: This increments the Counter variable
    Field5: This prints the employee name
    Field6: This tests whether Counter variable is divided by 5
    Field7: This generates a page break
    Field8: End of condition
    Field9: End of for-each cycle
    Result:
    The first page has just the header and the second page has the header and only record and it goes the same
    for the rest of the pages. Any help is greatly appreciated.
    Thanks.

    Have a look at this post
    http://winrichman.blogspot.com/2008/09/limit-row-per-page.html

  • Fastest way to check total number of rows from View ?

    Hello Everyone,
    Good Morning !!!!
    I am trying to know the exact number of rows from a view.
    I have total 262 columns in a view name vw_sample. First column name is col_1 and I do not have permission to view that. but I do have permission to view all other 261 columns. I want to know fastest way to know exact number of rows in this view vw_sample.
    How can i know that ?
    I tried below things.
    1) Tried using COUNT(*) & COUNT(1) but I don't have permission to first column col_1 so that didn't worked.
    2) I do not have permission to view DMV "sys.dm_db_partition_stats"
    3) I tried to execute below code.
    select col_2, col_3,...col_262
    into #TempTable
    from vw_sample
    and it gave me below error
    Msg 1105, Level 17, State 2, Line 1
    Could not allocate space for object '<temporary system object: 9830433781072176840>'
    in database 'tempdb' because the 'PRIMARY' filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.
    4) Accidentaly I run below code
    select col_2, col_3,...col_262
    from vw_sample
    It gave me 11 million rows in 40 minutes. As we know this method is not good to test just number of rows from a view.
    So what would be my option here ?
    Thanks in advance.
    Thanks
    Fredyy

    Fredy, did you try with other column names instead of col1?
    SELECT COUNT(col2) FROM View
    What difference does that make, than using your column 1.
    Please mark as answer, if this has helped you solve the issue.
    Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.
    IMO, sqlsaga's answer is the way to go, but you may need to make a minor change.  When you do COUNT(<some expression>), SQL counts the number of rows where <some expression> is not NULL.  So if col2 can be NULL you need to make a change
    so you know what you are counting can't be NULL.  If there is some other column in the view that can't be NULL, just count it.  Otherwise just use the ISNULL function to convert NULL's to a value.  For example, do
    Select COUNT(IsNull(col2, 0)) From vw_sample
    Note the above assumes that col2 is a type that contains a number (int, numeric, float, etc).  If col2 is of a different type, then just replace the 0 in the above with any valid value of the same type as col2 (so '' for varchar, '19000101' for datetime,
    etc).
    Tom

  • Deleing large number of rows from table

    Hi,
    Consider tables A,B,C,D,E,F. all are having 100000++ records Tables B,C,D are dependent on table A (with foreign key constraint). When I am deleting records from all tables, table B,C,D are taking max 30-40 seconds while table A is taking 30-40 mins. All tables are having indexes.
    Method I have used:
    1. Created Temp table
    2. then deleted all records from B,C,D,E,F for all records in temp table for limit of 500.
    delete from B where exists (select 1 from temp where b.col1=temp.col1);
    3. please suggest options for me why it is taking too much time for deleting records in table A.
    Is there any thing that during deleting data from such master table, it is reffering to all dependent tables even if dependent data is not present ??? If yes then couls you please please suggest options for me to remove this ? I hope it won't go for CHECK constraints during deleting data.
    Thanks,
    Avinash
    Edited by: user12952025 on Apr 30, 2013 2:55 AM
    Edited by: user12952025 on Apr 30, 2013 2:56 AM
    Edited by: user12952025 on Apr 30, 2013 2:57 AM

    user12952025 wrote:
    Hi,
    Consider tables A,B,C,D,E,F. all are having 100000++ records Tables B,C,D are dependent on table A (with foreign key constraint). When I am deleting records from all tables, table B,C,D are taking max 30-40 seconds while table A is taking 30-40 mins. All tables are having indexes.What attribute of the Foreign key is specified? Is it On Delete Cascade? If yes, then in a way, deleting data fro Child tables is un-necessary. Only a Delete from parent shall suffice.
    >
    Method I have used:
    1. Created Temp table
    2. then deleted all records from B,C,D,E,F for all records in temp table for limit of 500.
    delete from B where exists (select 1 from temp where b.col1=temp.col1);
    3. please suggest options for me why it is taking too much time for deleting records in table A.
    Is there any thing that during deleting data from such master table, it is reffering to all dependent tables even if dependent data is not present ??? If yes then couls you please please suggest options for me to remove this ? I hope it won't go for CHECK constraints during deleting data.One another way is to "Switch-Off" the relationship while deleting the data.
    ALTER TABLE table_name
    disable CONSTRAINT constraint_nameAnd then Delete the data from each of tables.
    You did specify the number of rows in each table, it would have been better to mention the number of rows to be deleted.
    It is not a hard-and-fast way, but would generally perform better, to copy the data (to be retained) from Parent Table into a Temporary Table, Drop Parent Table and rename teh Temporary table to parent table. Similar can be performed on Child tables.
    You may then Enable the Foreign key constraints.

  • How to limit number of rows(pagination) in the bam report?

    Is there anyway i can limit the number of rows in a report in BAM 10.1.3.4 ?

    In BAM 11g
    There is a property ElementsCountLimit which is configurd in BAMServerConfig.xml
    The number of change lists that are cached before rewriting the cache file.
    The default value is 50. When the 51st change list is received, it is cached by replacing the 1st change list.
    Default: 50

  • Determine number of rows from javascript so I can hide if zero

    Hi All,
    Found a great article which I adapted to use the link on a report to delete a row in db and remove from table (without a refresh).
    It works great except I want the region to not display when there are no rows left.
    Currently it shows "No Data Found" but because the page does not submit the region does not hide.
    Here is the Java code:
    function ackMsg(p_this, p_empno) {
    // get the table row on which the user clicked
    var tr = $(p_this).closest('tr');
    // perform an asynchronous HTTP AJAX request using jQuery
    $.ajax({
    type: "POST",
    url: "wwv_flow.show",
    data: {
    p_flow_id: $('#pFlowId').val(),
    p_flow_step_id: $('#pFlowStepId').val(),
    p_instance: $('#pInstance').val(),
    x01: p_empno, // assign p_empno to the g_x01 global variable
    p_request: "APPLICATION_PROCESS=ack_message" // refer to the application process
    beforeSend: // executes while the AJAX call is being processed
    function() {
    // delete following HTML classes from the table row element
    // could be possibly theme dependent
    tr.removeClass('even');
    tr.removeClass('odd');
    // use jQuery's animate function to give the table row, and its children, a red background
    tr.children().hover(function() {
    tr.children().animate({'backgroundColor': '#00cc00'}, 300);
    }, function() {
    tr.children().animate({'backgroundColor': '#00cc00'}, 300);
    tr.children().animate({'backgroundColor': '#00cc00'}, 300);
    success: // to be called if the request succeeds
    function() {
    jQuery(p_this).trigger('apexrefresh');
    // jQuery has difficulties animating inline elements
    // that's why we wrap them in a div, which is a block element
    tr.children().wrapInner('<div>').children().fadeOut(400, function() {
    tr.remove(); // visually remove the row from the report
    I did some Googling to add the line ' jQuery(p_this).trigger('apexrefresh');' which refreshes just that report.
    What I think I need to do is add a check for number of rows left after the refresh then if = 0 do full page refresh to allow the region condition to hide it.
    Unfortunately after hours on Google I can't find how to check how many rows are in the table.
    PS the function is called from the link in the report like this onclick="ackMsg(this, #ACK#)"
    Please help
    AT
    Edited by: user1678248 on May 13, 2013 9:39 PM
    Edited by: user1678248 on May 13, 2013 9:40 PM

    1)
    When you set a column to hidden in a classic report using the method I described, it creates hidden form elements for that column.
    <tt><input type="hidden" name="f01" value="" id="f01_0002"></tt>
    You should inspect the source to figure out the name value.
    Since this belongs to the wwv_flow form, we can therefore get this data with: wwv_flow.f01
    Alternatively, you could have used the apex_item API to achieve the same result, which probably gives a bit better control.
    http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35127/apex_item.htm#CHDBFHGA
    select apex_item.hidden(1, col) || col col
    from table
    Set that column to a standard report column so it doesn't escape the html.
    You can also reference the data in these fields using PL/SQL using the apex_application API:
    http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35127/apex_app.htm#CHDGJBAB
    2)
    As above, setting the column to hidden creates hidden elements on the page. It is simply f01 because that is the only hidden field I would have on my page. With four reports on the page, you would need to be careful not to do the same on the other reports, as you would get inaccurate data. For each report, setting columns to hidden always starts with f01. In that, you would be best to use the apex_item API.
    I actually initially ran into this issue when i had a tabular form on the same page as a report with hidden fields, which was causing conflicts in the page processes.
    Hope it helps.

  • Need to limit number of rows returned by a query

    Hi. Is there a way to limit the rowsets returned to me in a query? I need to get the first 100, then the next hundred, etc until there are no more rows left to retrieve. Someone told me that I should use a cursor to do this. Does anyone have a specific example? Can this be done with a combination of SQL/JDBC?
    Thanks in advance...bbetta
    null

    if you are talking about limiting the number of rows to be returned to the calling program to a managable number of rowa ...
    for example the result set size would be 5000 rows and you want to get them in batches of 50 or 100 ..
    see the attached link :
    JDBC Code Templates
    http://technet.oracle.com/sample_code/tech/java/sqlj_jdbc/htdocs/templates.htm#BatchSize
    if you want the server side transaction to only return the first 50 or 100 rows even though the result set has more ... then
    another approach is required -- possibly as suggested above ...

  • Get Number of rows from a sql query.

    I am reading data from a sql query in a BLS transaction and I would like to know the number of rows returned.
    Is there an easy way to do this without looping through the table?
    Thanks Jasper

    Hi Jasper,
    You can use the XPATH count function similar to  this:
    GetTagList.Results{count(/Rowsets/Rowset/Row)}
    Kind Regards,
    Diana Hoppe

  • RDL report(2008).Want to display different number of rows from second page onwards than the first page.

    I have used pagination to display the report data.I have used page break.I want to display 10 records on first page and from second page onwards I want to display 25 records on all remaining pages.
    I followed this link to show 25 records for all page. "http://www.sqlchick.com/entries/2010/9/11/displaying-fixed-number-of-rows-per-ssrs-report-page.html". Now suggest me how display 10 records only on first page having 25 from second page onwards.

    Hi mukesh_harkhani,
    According to your description, you want to insert page break for different number of rows, display 10 rows on the first page and 25 rows on the following pages. After testing the issue in my SQL Server Reporting Services 2008 environment, we can use the
    method below to achieve your requirement:
    In your scenario, right-click the group which contains the expression: =CEILING(RowNumber(Nothing)/25) to open the Group Properties dialog box.
    Modify the original expression to the following in the Group on textbox:
    =Floor((RowNumber(Nothing)+14)/25)
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Count number of rows from oracle and sql database and generate a report

    Hi All,
    Can someone help me in writing a java program for the following scenario?
    1. Read the number of rows available from oracle table and print the total row count in a Report.txt text file.
    2. Read the number of rows inserted in a sql database (after a specific process-just an information) and print the total row count in the same text file Report.txt .
    3. Read the Error Log file (which is generated after a specific process say it has success and failed report for each iterations) and print the number of success and number of failure in the same text file Report.txt .
    I need the final Report.txt file in the following format:
    1. Oracle table <table name> has 500000 rows.
    2. After completion of the specific process 300000 rows were added to SQL table <table name>
    Error Log Report:
    300000 successfull entries and 200000 failed entries were found from the Error Log file.

    Thanks for your immediate reply.
    I'm just a beginner in java so if i make any mistake please correct and excuse me. :)
    This is the code i have for connecting to two different database.
    package connectDatabase;
    * @author
    import java.sql.*;
    public class ConnectTo
         public void OracleDB()
              Connection dbconn;
              try {
                DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
                String connString="jdbc:oracle:thin:@SYS_IP:1521:oracl";
                dbconn = DriverManager.getConnection(connString, "uname","pwd" );
            catch(SQLException sqlex)
                 sqlex.printStackTrace();
            catch(Exception excp)
                excp.printStackTrace();
         public void SqlDB()
              Connection conn;
              try { 
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
                String url = "jdbc:odbc:connectDB"; 
                conn = DriverManager.getConnection(url,"uname","pwd");  
              catch (Exception e)
                System.err.println("An Exception occured! " +e.getMessage()); 
    }I'm just codding the second half which is for connecting to oracle databse and calculates the row count and displayes in the command prompt.
    then connects to SQL database and counts successfull insert in the table.(row count) and displayes on the command prompt.
    can you simplify the above code so that i can call the oracleDB() method and SqlDB() method seperately from another calss file using the object of this class?
    I'm ok if the report can be seen in a command prompt. FInally i need to calculate the success and failure count from the log file. will let you know once i'm done with codding.

  • Limit Number for Rows in BW Query Result

    Hello Experts,
        I am creating a query to be consumed by a web service. Therefore, I want to restrict the number of rows the query can display. Does anyone know a way to limit the result set to display only say FIRST 100 rows of data?
        I have looked at 'safety belt' solution, i.e. limiting number of cells to for example, 5000 cells. However, when the limit is exceeded the query just shows an error message not the first 5000 cells.
    thanks,
    Kartik

    Hi,
    You can do some things like..........
    Do not display the data in a detailed level.
    Use Always Suppress option in the result set.
    Also it depends on your Query definition. If your rows contains Branch wise or Region Wise, then your report will be fit in your first level of output. You need not to drilldown further.
    Why do you want to consider only first 1000 rows if you are planning to use it by Web service?
    I don't know whether it is feasible or not. I have one more alternative for you. You can try to achieve by APD by the Query. Insert a ABAP routine which should consider first 1000 result rows for your Web service. Just throw a light on this idea..............
    Regards,
    Suman

  • Limit number of rows returned in Toad

    Hi,
    I use toad to query a database, in fact, its a data warehouse and each time my query returns a huge number of rows and I have to wait for quite some time. Is there a way of getting only a few rows at a time. I mean, I want to see the complete data returned by in a piecemeal manner, say it fetches me the first 30 rows and I keep seeing this data while it keeps getting the next 30.
    Any suggestions?
    Thanks in advance,
    Rajesh

    The first query will give you a random set of 100 rows from your table. There is no such thing as the "first 100 rows" without an order by in the inner query. The secons query will return nothing.
    SQL> SELECT * FROM (
      2  SELECT indv_id FROM indv_t)
      3* WHERE rownum > 100 and rownum < 200;
    no rows selectedA close approximation of this query that does return rows is:
    SQL> SELECT * FROM (
      2  SELECT indv_id,rownum rn FROM indv_t)
      3* WHERE rn > 100 and rn < 200;
    INDV_ID           RN
    1040             101
    1057             102
    1073             103
    2055             197
    2063             198
    2071             199
    99 rows selected.The only correct, repeatable, efficient way to page data is something like:
    SELECT * FROM
       SELECT *, rownum rn FROM
          your query here WITH AN ORDER BY
       WHERE rn <= :max_value
    WHERE rn >= :min_valueOracle will not guarantee that the same query will return the rows in the same order for every execution without an ORDER BY clause. There are dozens of factors that can influence the query path chosen by the optimizer, and therefore the order of the rows returned. As the optimizer gets more complex (and smarter?), and Oracle adds new acces paths, I xan only assume that the number of factors influencing the access path will continue to grow.
    In short, if you want to talk about first and last rows, you need to sort them first.
    TTFn
    John

  • Getting a specified number of rows froma query

    How can I get the minimum 3 row from a query after a order by in the select
    Eg;
    SELECT ROWNUM,ROWID, connection_id, GROUP_ID
    FROM prov_pending_commands
    ORDER BY group_id
    4     AAAZWTAAYAAANMiAAA     680932     32702947
    3      AAAZWTAAYAAANMgAAB     644610     32703643
    2 AAAZWTAAYAAANLrAAB     51925942 32704602
    1 AAAZWTAAYAAANLrAAA     61247803 32704613
    I need to get only the group ids 32702947,32703643, 32704602 for some other processing.
    I checked by getting rownum or row id, but after ordering it gives wrong data
    Please need help

    Hi,
    Try this,
    select * from (select name, row_number() over (order by name) as row_num from test) row_num
    where row_num <= 3
    If you are looking for something else explain us more with sample output.
    Thanks!
    M T

  • Getting a fixed number of rows from various items

    Hello,
    I am new to Oracle and I am having a hard time resolving this problem. I will try to explain as best as possible.
    The application requires that I build a list of items that have been shipped. As they may have various shipping companies, there may be various tracking numbers for each item shipped. The application requires that I get a list of the items that have been shipped that meet certain criteria, then for each item, list the first three tracking numbers that are found. If the shipped item has more than three tracking numbers, the others beyond the third are ignored. I built a SELECT statement using the rownum "column" to limit my result set to a maximum of three. My intention was to build a list of
    item ids, then pass those to a stored procedure, then loop for each item id, getting the first three tracking numbers. The tracking numbers returned would be appended to a cursor, which would return the entire set of tracking numbers for the list of item ids.
    Any recommendations as to how to approach this requirement would be greatly appreciated. I have gotten through the SELECT that returns the list of item ids. I am having trouble finding the correct approach to getting the three tracking numbers for each item id. One solution was to have the application cycle through each
    item id, but I am hoping that this can be done within the stored procedure so that it is called only once for the returned list of item ids.
    I wish to thank you in advance. This is all the information I can provide, as I don't have any DDL statements. I hope it will suffice.
    Salvador
    null

    Please see if you can use something like this:
    SELECT a.item, a.tracking_number
    FROM table_name a
    WHERE 3 >=
    (SELECT COUNT (*) + 1
    FROM table_name b
    WHERE a.item = b.item
    AND b.ROWID < a.ROWID
    AND b.criteria = 'whatever')
    AND a.criteria = 'whatever'
    ORDER BY a.item, a.tracking_number
    For example, if you have a table named items_shipped that has columns named item, tracking_num, and shipped, and you want all the items that meet the criteria that shipped = 'Y' and the first three tracking_nums for those items, then your query would look something like this:
    SELECT a.item, a.tracking_num
    FROM items_shipped a
    WHERE 3 >=
    (SELECT COUNT (*) + 1
    FROM items_shipped b
    WHERE a.item = b.item
    AND b.ROWID < a.ROWID
    AND b.shipped = 'Y')
    AND a.shipped = 'Y'
    ORDER BY a.item, a.tracking_num
    You have given very limited information. If the above suggestions are not sufficient, please provide your table structure, including table names, column names, data types and lengths, some sample data, what criteria must be met, and a sample of what you would like the output to be.
    null

Maybe you are looking for