How to write a function to estimate the number of rows returned SQL?

How to write a function to estimate the number of rows returned SQL through SQL Execution Plan?
My idea is
Call dbms_sql.parse to create the SQL PLAN, then ask the PLAN for the number of estimated return lines.
But how to get SQL plan through "id cursor?
Thank you.

You can use EXECUTE IMMEDIATE to explain plan statement. About the STATEMENT_ID generation, it could be anything. Even a SYSTIMESTAMP cast as TANK would work.

Tags: Database

Similar Questions

  • How to limit the number of rows returned in a query

    Hi friends,
    I want to limit the number of rows returned by my request to some 10 lines. How to do this. When I try to make some 6 rows with the rownum < 10 its giving results for a particular Department and that too only... btw I'm bundling my table and includes much a table joins and will order the results of the table by a column... How to do this...

    Run it:

    select * from (your query goes here) where rownum < 10
    

    Nicolas.

  • Count the number of rows returned from each view in USER_VIEWS

    For each USER_VIEWS view, I would return the name, creation date, last modified dateand the number of rows returned by this view.

    Here's what I have so far:
    col object_name format a20
    select 
    object_name, 
    created, 
    last_ddl_time
    from user_objects
    where object_type = 'VIEW'
    Returns:
    OBJECT_NAME          CREATED   LAST_DDL_TIME
    -------------------- --------- -------------
    AISLE_AVG            11-FEB-12 11-FEB-12     
    COURSE_AVG           11-FEB-12 20-FEB-12     
    EXE_12_VIEW          11-FEB-12 21-FEB-12     
    L1_P2                17-FEB-12 17-FEB-12     
    L1_P3                17-FEB-12 17-FEB-12     
    L1_P4                17-FEB-12 17-FEB-12     
    L1_P5A               17-FEB-12 17-FEB-12     
    L1_P5B               17-FEB-12 17-FEB-12     
    LAB3_1A              12-FEB-12 20-FEB-12     
    LAB3_1B              12-FEB-12 20-FEB-12     
    LAB3_2A              12-FEB-12 20-FEB-12     
    LAB3_2B              12-FEB-12 20-FEB-12     
    LAB5_1               19-FEB-12 19-FEB-12     
    LAB5_2               19-FEB-12 19-FEB-12     
    LAB5_3               19-FEB-12 19-FEB-12     
    LAB5_4               19-FEB-12 19-FEB-12     
    LAB5_5               19-FEB-12 19-FEB-12     
    LAB5_TIMES           19-FEB-12 19-FEB-12     
    LAB6_1               19-FEB-12 19-FEB-12     
    LAB7_VIEW            20-FEB-12 20-FEB-12     
    PROGRAMS             11-FEB-12 21-FEB-12     
    STUDENT_GPA          11-FEB-12 21-FEB-12     
    
     22 rows selected 
    How can I add a last column that counts the number of rows returned by this view?

    EDIT - here is a dump of my paintings, and here are my views.

    Edit2 - this is possible by using the DECODE function, by chance?

    The function...

    CREATE OR REPLACE FUNCTION view_row_count (view_name VARCHAR2)
    RETURN NUMBER
    AS
    retval NUMBER;
    BEGIN
    EXECUTE IMMEDIATE
    'select count(*) from '||view_name INTO retval;
    RETURN retval;
    END view_row_count;
    /
    

    And now the query...

    select
    object_name,
    created,
    last_ddl_time,
    view_row_count(object_name) as view_row_count
    from user_objects
    where object_type = 'VIEW'
    
  • Determine the number of rows returned by a cursor

    I have a problem when I need to use slightly different logic based on whether or not a cursor returns a single line or multiple lines. I know you can use % ROWCOUNT to determine the number of rows returned far+, but it's not really help me because I need to know this information before I start to do any treatment.


    In other words. How can I know the number of rows returned by a cursor without actually iterate through the entire thing.

    I'm looking for something like this:
       Cursor ReqCursor(pi_cert_id IN Varchar2) Is
          SELECT course_id cid, grade g
            FROM requirements
           WHERE cert_id = pi_cert_id;
       c_ReqCursor ReqCursor%Rowtype;
    
    Open CertCursor(p_cert_num);
        Loop
            Fetch CertCursor
              INTO c_CertCursor;
            Exit When CertCursor%Notfound;
            
            If c_CertCursor%NumOfRows > 1 THEN
                Case A;
            Else
                Case B;
            End If 
       End Loop
    Close CertCursor;

    For your business add

     SELECT course_id cid, grade g, count(*) over() Tot_Rows
            FROM requirements
           WHERE cert_id = pi_cert_id;
    --"Fetch 1st row and you will know if the cursor has more than 1 row"
    

    HTH
    SS

  • How to write Save function based on the drop-down list box selection data in app mxml flex4 with as3

    Hi all

    I'm working on the application web flex4 with as3.

    I have a doubt, I've created a mxml it has two text boxes, except the button and a combo box that is has two option as a percentage and the amount.

    my needs are I gave here.

    need 1: when I choose option amount that two text boxes does not have to be editable.when I select text tat box two percentage option will be editable.

    need 2: when I select the percentage in combox option and two text boxes are empty, and then click the button Save-> I want to display warning msg

    need 3: when I select the option amount combox and the two boxes are emptu click the button Save-> I don't want any warning messages.

    How to validate it and how to write backup for this function.

    This is my sample code:

    list box ID = baseAmtPer

    ID TextBox1 = maxCommAmt.text

    ID = baseAmtPer.text text box

    If (((baseAmtPer.editable!=true) & & (maxCommAmt.editable! = true)) & & ((baseAmtPer.text=="") & &(ma xCommAmt.text=="")) |) (baseAmtPer.text == "") | (maxCommAmt.Text=="")) -> This condition not allowing while I'm selecing amount in combo box. How the TWO TEXT BOX WILL BE EMPTY for this problem

    {

    Alert.Show ("enter in all areas", "Information");

    }

    on the other

    {

    some encodings

    }

    Hello

    Please go through the following Code:

    http://ns.Adobe.com/MXML/2009.

    xmlns:s = "library://ns.adobe.com/flex/spark".

    xmlns:MX = "library://ns.adobe.com/flex/mx" minWidth = "955" = "600" minHeight >

    Import mx.collections.ArrayCollection;

    Import mx.controls.Alert;

    Import spark.events.IndexChangeEvent;

    protected function button1_clickHandler(event:MouseEvent):void

    {

    If (comboBox.selectedItem == "Percentage" & textBox1.text == "" & textBox2.text == "") {}

    Alert.Show ("enter the values");

    }

    }

    protected function comboBox_changeHandler(event:IndexChangeEvent):void

    {

    {if(ComboBox.SelectedItem=="Amount")}

    textBox1.editable = false;

    textBox2.editable = false;

    }

    else {if(comboBox.selectedItem=="Percentage")

    textBox1.editable = true;

    textBox2.editable = true;

    }

    }

    ]]>

    Amount

    Percentage

    Thank you and best regards,

    ------------------------------------------------------------------------------------------ --

    Vibhuti Gosavi . [email protected] | www.infocepts.com

    ------------------------------------------------------------------------------------------ --

  • How to limit the number of rows returned in the PIF

    Hi friends...
    How to restrict the no of lines displayed from a few 10 rows for example... at the BEEP

    If its in RTF, you can use position to restrict.
    <><11]?>

    You can also restrict the it in your sql query using ROWNUM.

  • Count the number of rows in a table (s)

    Hi all

    I have a TKT_PRIORITY_LK table that I want to count the number of rows returned by a priority level... say Low, Medium, High, critical. I want to be able to count how many of each created are they, instead returning ID instead, if making any sense... Can you please help with this.

    Example; Select count (*) in TKT_PRIORITY_LK

    PRIORITY group

    Kind regards

    Sandrine

    Try this

    Select a.PRIORITY, count (*) from TKT_PRIORITY_LK a, TKT_TICKET_MAIN b

    where a.id = b.PRIORITY_ID

    A.PRIORITY group

  • total number of rows returned, how to learn it

    Hello
    I think that in Oracle should be some simple var which contains the number of rows returned, can someone help me with this.
    I actually do it:
    INSERT INTO TT_1 SELECT * FROM TT_2 WHERE COND_01.

    Here so get the total number of rows populated without COUNT (*) extra.


    TX
    TR

    If you want to see in PL/SQL you can do it like this:

    SQL> set serveroutput on
    SQL> create table t1 as select * from all_tables where 1 = 0;
    
    Table created
    SQL> BEGIN
      2    INSERT INTO t1 SELECT * FROM all_tables;
      3    dbms_output.put_line('Rows inserted: ' || SQL%ROWCOUNT);
      4  END;
      5  /
    
    Rows inserted: 2238
    
    PL/SQL procedure successfully completed
    
    SQL> 
    
  • How to write a function block?

    Hello

    Someone knows how to write a function block with LabVIEW?  Something like those in real time live > function blocks >.

    Thank you very much in advance?

    Assuming you are referring to these specifically...

    http://www.NI.com/white-paper/7339/en/

    .. then the answer is that it is almost impossible to make a new. However, there is really nothing special all that to their topic. They are essentially normal subVIs (which you can learn about the other links) which just happened to have some terminals connected to shared variables. I personally would not normally recommend that anyway. If you could clarify what exactly you are trying to do, it might be possible to give more specific advice.

  • Does anyone know of a VI or how to write one that will stop the computers time be disabled if an application is run.

    Does anyone know of a VI or how to write one that will stop the computers clock be turned off if an application is run. The time and date can be reset normally while an application is running by clicking on the time in the lower right of the screen of the computer. I have an application that runs over several days and it is essential that the time and date of the computer not be changed. Is there an easy way of this lockout the user? Note that I am what I consider a beginner advanced in LV

    Thank you

    Chuck

    This isn't something that you can from LabVIEW, because this is an operating system operation, and it will depend on the operating system you are using. Under Windows, you can use Group Policy to control this. Please Google on "prevent changing the date and time of windows."

    Also, please try to refrain from stuffing your message in its entirety in the block of material. Keep short, but descriptive enough topic so we can understand what you're asking basically. Thank you.

  • I'm new in indesign scripting, please tell me how to write a script to get the contents of an XML element and then sort all the content

    I'm new in indesign scripting, please tell me how to write a script to get the contents of an XML element and then sort all the content

    Hello

    Can the code below is useful for you, but I do not know how to sort.

    Change the tag based on your employment application.

  • How can I get the number of rows in the table using Sunopsis API target in ODI 10 g?

    Hi guys,.

    In fact, I want to send an alert message as soon as the interface is run from a package. I've included alert OdiSendMail that sends an email once the interface is running.

    Could someone please tell how to get the number of rows inserted into the table the Sunopsis API target.

    I tried to use < % = odiRef.getNbRows () % >, but this has not worked for me. Since I am a beginner, could you please help out me

    This is my mail to send ODI format

    "The population of data managed to < % = odiRef.getSysDate () % >

    Total of lines in the target table is: < - need an API code-> "


    Kind regards

    Clinton

    Published by: LawrenceClinton on February 25, 2013 20:53

    Hello

    Create the project with details below variable

    Nom_de_variable: Total_Row_Count

    Type of variable: Variable discount

    Definition tab:
    Data type: digital
    Action: No persistent

    Refresh the tab:
    Schema: provide the schema of your repository to work and be

    SELECT log.nb_row
    THE journal of snp_step_log, snp_scen_step step
    WHERE log.nno = step.nno
    AND step.scen_no = (SELECT scen_no FROM snp_scen_step WHERE step_name='<%=odiRef.getPrevStepLog ('STEP_NAME") % > ')
    AND log.sess_no = '< % = odiRef.getSession ("SESS_NO") % >' code at low
    AND step.step_name = ' < % = odiRef.getPrevStepLog ("STEP_NAME") % > '

    Note: add this variable after the stage of interface in your package (after the interface anywhere you can place), you can add this variable before ODISendEmailNotification in your package

    call this varciable * #Total_Row_Count * in the Notification of ODISendEmail

    for example :

    Data has been fulfilled successfully in < % = odiRef.getSysDate () % >
    Total no of lines filled are: * #Total_Row_Count *

    it will work

    cordially,
    Phanikanth

    edited by: Phanikanth on February 28, 2013 01:13

    edited by: Phanikanth on February 28, 2013 01:14

  • How to access a certain date in the date and time field SQL Server

    I have a field named job_date in a table in my database of the 8 SQL Server.

    The data type is datetime.

    Thus, the values for the fields as the 2013-03-11 15:55:52.000 look.

    How to query this field to include only the values of a certain date?

    For example

    < cfquery name = "get_job_name" datasource = 'abc' >

    SELECT FROM job_info job_date WHERE Job_name = March 12, 2013"

    < / cfquery >

    When I query the field now I get NO RECORDS.

    This is because as the fields like this 15:55:52.000 2013-03-11. instead of this March 12, 2013"

    How to access a certain date in the date and time field SQL Server when its formatting as this 15:55:52.000 2013-03-11. ?

    where job_date > = TheDateYouWant

    and job_date<>

    In addition, the format is irrelevent.  The only issue of date formats time is when you want to display.

  • How do to display the number of rows Inserted/deleted etc. in PL/SQL

    In Oracle 10 g PL/SQL, I have a delete statement in a stored procedure. This isn't in a cursor. I want to see the number of lines that I deleted. I can use dbms_output.put_line package. I should know this, but I don't have time to perfect syntax. How do I get the number of rows that are deleted and the display via dbms_output.put_lline?

    For example:

    set serveroutput on
    
    begin
    
       delete  dept;
    
       dbms_output.put_line(sql%rowcount);
    
    end;
    /  
    

    Miguel

  • How can I find the number of users returned by cfldap query?

    How can I find the number of users returned by cfldap query?

    I'm not allowed to do something like:

    < cfif ArrayLen (results.rows) WG 1 >

    Then, I get an error:

    faultCode:Server.Processing faultString:' unable to invoke CFC - class type object coldfusion.tagext.net.LdapResultTable can use table ' faultDetail: "

    Thank you very much for all you can shed light

    Expand on Dan's response.

    #results. USNCreated # is a reference to the entire column.  This shortcut is allowed inside of a or a loop.  But if you want to access the record set directly outside one of these structures of loop, you must use the query.column [full row] or ["column"] [rank] query syntax.

    THAT IS TO SAY

    
    

Maybe you are looking for