Function returning cursor to be used in select statement

I have written a function which returns a cursor. I want to use this in a select statement to display rows. How to do this.
Eg : function - test_fn return sys_refcursor. (returns empno, empname, deptname)
select test_fn from dual
This should return
empno empname deptno
1 name1 dept1
2 name 2 dept2
....

Try This::
SCOTT@xe_144>variable c  refcursor
SCOTT@xe_144>CREATE OR REPLACE FUNCTION get_nm
  2     RETURN sys_refcursor
  3  AS
  4    
  5     c sys_refcursor;
  6  BEGIN
  7    
  8     open c for 'SELECT ENAME , SAL FROM EMP';
  9      
10     RETURN c;
11  END;
12  /
Function created.
SCOTT@xe_144>select get_nm into :c from dual;
GET_NM
CURSOR STATEMENT : 1
CURSOR STATEMENT : 1
ENAME             SAL
SMITH             800
ALLEN            1600
WARD             1250
JONES            2975
BLAKE            2850
CLARK            2450
KING             3000
AKASH2           5000
TURNER           1500
ADAMS            1100
JAMES             950
MILLER           1300
ABC              2000
13 rows selected.Let me know if its works for you.

Similar Messages

  • Why does getdate() function return same time value for multiple select statements executed sequentially

    When I run the following code
    set nocount on
    declare @i table(id int identity(1,1) primary key, sDate datetime)
    while((select count(*) from @i)<10000)
    begin
    insert into @i(sDate) select getdate()
    end
    select top 5 sDate, count(id) selectCalls
    from @i
    group by sDate
    order by count(id) desc
    I get the following results. 
    sDate                   selectCalls
    2014-07-30 14:50:27.510 406
    2014-07-30 14:50:27.527 274
    2014-07-30 14:50:27.540 219
    2014-07-30 14:50:27.557 195
    2014-07-30 14:50:27.573 170
    As you can see the select getdate() function returned same time up to the milisecon 406 time for the first date value.  This started happening when we moved our applications to a faster server with four processors.  Is this correct or am I
    going crazy?
    Please let me know
    Bilal

    Observe that adding 2 ms is accurate only with datetime2.  As noted above, datetime does not have ms resolution:
    set nocount on
    declare @d datetime, @i int, @d2 datetime2
    select @d = getdate(), @i = 0, @d2 = sysdatetime()
    while(@i<10)
    begin
    select @d2, @d, current_timestamp, getdate(), sysdatetime()
    select @d = dateadd(ms,2,@d), @i = @i+1, @d2=dateadd(ms,2,@d2)
    end
    2014-08-09 08:36:11.1700395 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1720395 2014-08-09 08:36:11.173 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1740395 2014-08-09 08:36:11.177 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1760395 2014-08-09 08:36:11.180 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1780395 2014-08-09 08:36:11.183 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1800395 2014-08-09 08:36:11.187 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    DATE/TIME functions:
    http://www.sqlusa.com/bestpractices/datetimeconversion/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • PL/SQL cursors vs. SQL*plus Select statement

    Hi folks, hope you're doing well,
    Here is a question that kept me wondering:
    Why would I use cursors when i can achieve the same thing with a SQL+ Select statement which is much easier to formulate than a cursor (e.g. you need no declaration, loops etc)?.
    Thanks so much,
    -a

    There is no such thing as a SQL*Plus SELECT statement. The SELECT command is part of the SQL Language - not part of the SQL*Plus (very limited small vocabulary) macro language.
    All SQL SELECTs (from client languages) winds up in the SQL Engine as SQL cursors. A SQL Cursor is basically the:
    - SQL source code
    - SQL "compiled" code (instructions on how to fetch the rows)
    On the client side, client cursors (not to be confused with SQL cursors) are used. A client cursor is created in the client language when it makes SQL calls via the database client driver (called the OCI/Oracle Call Interface for Oracle clients).
    Typically this is what a client does. It makes a connection to the database and gets a database handler in return. The database handler is the "communication channel" from the client to the db. In Oracle, the database handler in the client refers to the Oracle session (for that client) on db server.
    A SQL statement (source code) is used by the client. This can be a SELECT statement you type in at the SQL*Plus command line. It can be a SELECT statement for the PL/SQL cursor command in a stored procedure.
    The client creates a SQL handle for this SQL statement, by calling the Oracle client driver. Note that this SQL handle is a client handle - a client cursor for that SQL statement.
    E.g.
    a) sqlHandle = CreateSQL( databaseHandle, 'SELECT ... FROM ...')
    b) sqlHandle.Parse
    c) sqlHandle.Execute
    After the SQL handle (client cursor) has been executed, the client can fetch rows from it.
    This is what SQL*Plus does automatically for you, without you having to write the code to do it. SQL*Plus CONNECT command create a database connection handle. You enter a SELECT statement and SQL*Plus creates a SQL handle (client cursor), executes it, fetches from it, displays the rows, and closes the SQL handle when done.
    The same applies to PL/SQL. You can use a SELECT statement just like that in PL/SQL. E.g.
    declare
      i integer;
    begin
      select count(*) into i from emp where deptid = 123;
    end;This is called an implicit cursor. PL/SQL creates (just like SQL*Plus) an implicit client cursor. It creates and disposes of that client SQL handle for you - you do not need to do it.
    Or, you can create an explicit cursor. E.g. declare
      cursor c is select count(*) from emp where deptid = 123;
      i integer;
    begin
      open c;
      fetch c into i;
      close c;
    end;The question as to when to use implicit (client) cursors versus explicit (client) cursors depends on your requirements. Do you need to cycle through the results of the SQL? Etc.
    And keep in mind that in either case, the SQL Engine creates a SQL cursor anyway on its side.

  • How to use the select statement in for loop

    Hi All,
    my question is can we use select statement in for loop like as follows .
    for key in select key from one_table.
    when i am using this am getting an error like Found select invalid i identifier
    how to make use of select statement in for loop
    please suggest me .
    Thanks
    Sree

    SQL>set serveroutput on;
    SQL> DECLARE
         BEGIN
         FOR Cur_Rec IN (SELECT dname FROM dept) LOOP
          DBMS_OUTPUT.PUT_LINE(Cur_Rec.dname);
         END LOOP;
         END;
    SQL>
    ACCOUNTING
    RESEARCH
    SALES
    OPERATIONSAs per your requirement always filter the Query beforehand
    Like
    FOR Cur_Rec IN (SELECT key FROM <table> WHERE key=1) LOOP
    END LOOP;Edited by: Lokanath Giri on १ दिसंबर, २०११ ३:५६ अपराह्न

  • Create a view using a select statement

    Hi
    I need to create a view using a select statement to view details from 2 different tables which will only show data where the holidays commence after june.
    I am new to oracle so any help will do.
    Thanks

    Hi
    I need to create a view using a select statement to view details from 2 different tables which will only show data where the holidays commence after june.
    I am new to oracle so any help will do.
    Thanks

  • How to join THREE different tables into internal table using one select statement .

    How to join THREE different tables into internal table using one select statement .
    Hi experts,
    I would like to request your guidance in solving the problem of joining the data from three different database tables into one internal table
    Scenario:
    Database tables:
    SPFLI
    SFLIGHT
    SBOOK.
    Table Fields:
    SPFLI - CARRID CONNID COUNTRYFR CITYFRM COUNTRYTO CITYTO
    SFLIGHT - CARRID CONNID FLDATE SEATSMAX SEATSOCC SEATSMAX_C
    SEATSOCC_C SEATSMAX_F SEATSOCC_F
    SBOOK - CARRID CONNID CLASS
    MY INTERNAL TABLE IS IT_XX.
    Your help much appreciated.
    Thanks in advance.
    Pawan.

    Hi Pawan,
    please check below codes. hope it can help you.
    TYPES: BEGIN OF ty_xx,
            carrid     TYPE spfli-carrid   ,
            connid     TYPE spfli-connid   ,
            countryfr  TYPE spfli-countryfr,
            cityfrom   TYPE spfli-cityfrom  ,
            countryto  TYPE spfli-countryto,
            cityto     TYPE spfli-cityto   ,
            fldate     TYPE sflight-fldate ,
            seatsmax   TYPE sflight-seatsmax ,
            seatsocc   TYPE sflight-seatsocc ,
            seatsmax_b TYPE sflight-seatsmax_b,
            seatsocc_b TYPE sflight-seatsocc_b,
            seatsmax_f TYPE sflight-seatsmax_f,
            seatsocc_f TYPE sflight-seatsocc_f,
            class      TYPE sbook-class,
          END OF ty_xx,
          t_xx TYPE STANDARD TABLE OF ty_xx.
    DATA: it_xx TYPE t_xx.
    SELECT spfli~carrid
           spfli~connid
           spfli~countryfr
           spfli~cityfrom
           spfli~countryto
           spfli~cityto
           sflight~fldate
           sflight~seatsmax
           sflight~seatsocc
           sflight~seatsmax_b
           sflight~seatsocc_b
           sflight~seatsmax_f
           sflight~seatsocc_f
           sbook~class
      INTO TABLE it_xx
      FROM spfli INNER JOIN sflight
      ON spfli~carrid = sflight~carrid
      AND spfli~connid = sflight~connid
      INNER JOIN sbook
      ON spfli~carrid = sbook~carrid
      AND spfli~connid = sbook~connid.
    Thanks,
    Yawa

  • Using ref cursor in "in clause" in select statement

    Hi,
    Is there any way can we use the ref cursor in the in condition of a select statement.
    Regards,
    Venkat.
    Edited by: ramanamadhav on Aug 23, 2011 11:14 AM

    ramanamadhav wrote:
    I'm sorry if I post in confusing way. I will give an example. Just see the psudo code here.
    declare
    rf_cur sys_refcursor;
    begin
    pr_test(empno,rf_cur);
    -- rf_cur returning emp names.
    select * from emp
    where empname in (ref_cusor results);-- here i want to consume my ref cursor result in the in conditions.
    end;
    Thanks &Regards,
    Venkat.No you can't do that. A ref cursor is not a set of results as you believe.
    Take a read of this article...
    {thread:id=886365}

  • How to get the value from a function using a select statement

    I have a function(user defined not built in) that returns multiple values(like an array). My question is how do i get those values in a select statement. when i tried to retrieve it,
    select pack.my_members from dual;
    i am getting an error
    ORA-00902: invalid datatype
    I am sure this must be a syntax error with the select statement
    The following is the function that give the array of data
    package pack
    package spec
    Type my_table is table of varchar2(25);
    function the_members
    return pack.my_table;
    pakcage body
    function the_members return pack.my_table
    Remarks: This function returns a table containing names of the
    members
    is
    tm pack.my_table:= pack.my_table('first member','second member','third member','fourth member');
    begin
    return tm;
    end the_members;

    Check this example on Pipelinedfunction

  • ORA-00911: invalid character using multiple select statements

    I am getting an ORA-00911: invalid character error when trying to execute 2 select statements using ODP.NET.
    cmd.CommandText = "select sysdate from dual;select sysdate from dual;";
    cmd.Connection = conn;
    cmd.CommandType = System.Data.CommandType.Text;
    conn.Open();
    OracleDataReader dr = cmd.ExecuteReader();
    This works in SQL server but for some reason it appears this does not work in Oracle?
    If this is the case what is a vaiable workaround? Wrapping the 2 statements in a transaction?
    Seems strange that you can't return multiple result sets using in-line sql statements.

    Oracle doesn't support passing multiple statements like that, and this is unrelated to ODP.NET.
    SQL> select * from emp;select * from dept;
    select * from emp;select * from dept
    ERROR at line 1:
    ORA-00911: invalid character
    You could do it via an anonymous block and ref cursors though if you dont want to do it via a stored procedure..
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    public class test
    public static void Main()
        using (OracleConnection con = new OracleConnection("data source=orcl;user id=scott;password=tiger;"))
            con.Open();
            string strSql = "begin open :refcur1 for select * from emp;" +
                "open :refcur2 for select * from dept;" +
                "open :refcur3 for select * from salgrade;end;";
            using (OracleCommand cmd = new OracleCommand(strSql, con))
                cmd.Parameters.Add("refcur1", OracleDbType.RefCursor, ParameterDirection.Output);
                cmd.Parameters.Add("refcur2", OracleDbType.RefCursor, ParameterDirection.Output);
                cmd.Parameters.Add("refcur3", OracleDbType.RefCursor, ParameterDirection.Output);
                OracleDataAdapter da = new OracleDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds);
                cmd.Parameters["refcur1"].Dispose();
                cmd.Parameters["refcur2"].Dispose();
                cmd.Parameters["refcur3"].Dispose();
                foreach (DataTable dt in ds.Tables)
                    Console.WriteLine("\nProcessing {0} resultset...", dt.ToString());
                    foreach (DataRow row in dt.Rows)
                        Console.WriteLine("column 1: {0}", row[0]);
    }Hope it helps,
    Greg

  • Creating multiple datasets using mulitple select statements as part of one macro / stored procedure

    Hi,
    I am working on a report what has 10 datasets derived from 10 different select statements.
    Is it possilbe to save those 10 select statements as a macro / stored procedure and then use that macro to generate those dataset in the ssrs report builder ?
    AshishSinghal

    Hi AshishSinghal84,
    According to your description, you want to write multiple select statements in a procedure, then use the procedure as dataset in the report, right?
    According to my knowledge, when we write multiple select statements in a procedure, we have to create relationship between these select statements, otherwise it will only return the first one query's fields. If you are using SSRS 2008 R2, you can use Lookup
    function to display these fields from different datasets on one data region control, but the prerequisite is that you must have one common field. For more information about lookup function, please see:
    http://msdn.microsoft.com/en-us/library/ee210531.aspx
    If all these solution you cannot achieve due to your special condition, the last workaround is to use subreport to display all the fields together.
    If you have any more questions, please feel free to ask.
    Thanks,
    Wendy Fu
    Wendy Fu
    TechNet Community Support

  • How to use a select statement with chinese characters?

    I am currently developing a java servlet<using tomcat 4.x> which allows me to use select statement to retrieve results from the Microsoft SQL Server 2000 database. I am using a simple form to get the parameter for querying. The main problem i'm facing is that there are chinese information in the SQL database, but i can't retrieve it through the sql statement with the chinese characters input<thru the form with the help of NJ STAR>in the WHERE condition. When i execute the statement, it returns me no results even though the rows are present in the database.
    Does anyone have the solution to using chinese words in the WHERE clause of the select statement to retrieve results with columns which contains chinese characters? Please help me. Thanks everyone. :)
    PS: when i cut and paste those characters in the sql database and paste onto java.. it is ??? in questionmarks.. but when i paste them into excel 2000.. its shown as chinese chars again..
    please heelppp~~

    Greetings,
    PS: when i cut and paste those characters in thesql
    database and paste onto java.. it is ??? in
    questionmarks.. but when i paste them into excelThis is why the SELECT is not returning any results.
    You need to set the character encoding set on your
    statement and parameters for the characters to be
    properly translated. Refer to the charsetName
    parameter in the String class constructor in your API
    docs and also to
    $JDK_DOCS/guide/intl/encoding.doc.html in your JDK
    documentation.
    2000.. its shown as chinese chars again..Because Office programs are performing the same kind
    of character translation with the appropriate MS APIs.
    please heelppp~~Regards,
    Tony "Vee Schade" Cookis it possible for you to show me some coding examples? i don't really understand what is to be done in order to set the char set and what does it really do.. tried reading up but still dun understand.. :(
    pardon my shallow knowledge of java..
    ok..
    The thing is when i used an insert statement with chinese characters of GBK format hardcoded into the java servlet and then i use the insert statement to insert the chars into the database, it cannot be seen as a chinese word when i off the NJStar. and then it can be searched out with my current form of servlet.. below is my coding of the servlet..
    note: i've set my html file to charset = GBK
    //prototype of Search engine...
    //workable for GBK input and output...
    import java.io.*;
    import java.io.OutputStream;
    import java.io.IOException;
    import javax.servlet.http.*;
    import javax.servlet.ServletException;
    import java.util.*;
    import java.sql.*;
    import java.nio.charset.Charset;
    public class SearchBeta extends HttpServlet {
         private Vector musicDetails = new Vector();
         private String query = "";
         public void service (HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException, UnsupportedEncodingException {
              query = req.getParameter ("T1");
              System.out.println("before:"+query);
              String type = req.getParameter ("D1");//type
              query = req.getParameter ("T1");
              //query = "������";
              System.out.println("after:"+query);
              getResults(type,query);
              System.out.println("locale = :"+req.getLocale());
              res.setContentType ("text/html;charset=GBK");
              PrintWriter out = res.getWriter();
              out.println("<html>");
              out.println("<head>");
              out.println("<body bgcolor = \"black\">");
              out.println("<font face = \"comic sans ms\" color=\"Cornsilk\">");
              if (query.length()==0)
                   out.println ("Please key in your search query.");
              else if (musicDetails.size()==0)
                   out.println ("Sorry, no results matching your search can be found.");
              else {
                   out.println("<center>");
                   out.println("<table cellspacing = \"50\">");
                   int i = 0;
                   //Display the details of the music
                   while (i<musicDetails.size()) {
                        Results details = (Results)musicDetails.get(i);
                        String dbArtist = "";
                        String dbAlbum = "";
                        String dbTitle = "";
                        String dbCompany = "";
                        dbAlbum = details.getAlbum();
                        dbTitle = details.getTitle();
                        dbCompany = details.getCompany();
                        dbArtist = details.getArtist();
                        try{
                             dbAlbum = new String(dbAlbum.getBytes("ISO-8859-1"),"GBK");
                             dbTitle = new String(dbTitle.getBytes("ISO-8859-1"),"GBK");
                             dbCompany = new String(dbCompany.getBytes("ISO-8859-1"),"GBK");
                             dbArtist = new String(dbArtist.getBytes("ISO-8859-1"),"GBK");//correct translation.
                        catch(UnsupportedEncodingException e){
                             System.out.print(e);
                             e.printStackTrace();
                        String dbImage_loc = details.getImage();
                        out.println("<tr>");
                             out.println("<td><table>");
                                  out.println("<img src=C:\\Program Files\\Apache Group\\Tomcat 4.1\\webapps\\examples\\ThumbNails\\"+dbImage_loc+">");
                             out.println("<tr>");
                                  out.println("<th><font color=\"violet\"> Artist: </font></th>");
                                  out.println("<td><font color=\"Cornsilk\">"+dbArtist+"</font></td>");
                             out.println("</tr>");
                             out.println("<tr>");
                                  out.println("<th><font color=\"violet\"> Title: </font></th>");
                                  out.println("<td><font color=\"Cornsilk\">"+dbTitle+"</font></td>");
                             out.println("</tr>");
                             out.println("<tr>");
                                  out.println("<th><font color=\"violet\"> Company: </font></th>");
                                  out.println("<td><font color=\"Cornsilk\">"+dbCompany+"</font></td>");
                             out.println("</tr>");
                             System.out.println("album: "+ dbAlbum);
                             out.println("<tr>");
                                  out.println("<th><font color=\"violet\"> Album: </font></th>");
                                  out.println("<td><font color=\"Cornsilk\">"+dbAlbum+"</font></td>");
                             out.println("</tr>");
                             System.out.println("company: "+ dbCompany);
                             out.println("</table></td>");
                        out.println("</tr>");
                        i++;
                   out.println("</table>");
                   out.println("</center>");
              out.println("</font>");
              out.println("</body>");
              out.println("</head>");
              out.println("</html>");
              out.close();
              //to remove all the elements from the Vector
              musicDetails.removeAllElements();
         //get Searched Music Details and store in Results object which is stored in musicDetails vector
         public void getResults (String type, String searchQuery) {
              try {
                   Class.forName ("com.microsoft.jdbc.sqlserver.SQLServerDriver");
                   Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=music","sa","kokkeng");
                   Statement stmt = con.createStatement();
                   String query = "SELECT * FROM MusicDetails WHERE "+type+" = '"+searchQuery+"'";
                   ResultSet rs = stmt.executeQuery(query);
                   while (rs.next()) {
                        String artist = rs.getString("Artist");
                        String title = rs.getString("Song");
                        String company = rs.getString("Company");
                        String album = rs.getString("Album");
                        String image_loc = rs.getString("Image");
                        Results details = new Results (artist,title,company,album,image_loc);
                        musicDetails.add(details);
                   stmt.close();
                   con.close();
              catch (Exception e) {
                   System.out.println(e.getMessage());
                   e.printStackTrace();
    with the above servlet i created, i can search out the data in the database which i've inserted through the insert statement. I still can't search for things i've keyed into the database directly using NJStar..
    thank you so much for helping.. really hope any one else who knows the answer to this will reply too... thank you all so much...
    -KK

  • How to return the result set of multiple select statements as one result set?

    Hi All,
    I have multiple select statements in my stored procedure that I want to return as one result set 
    for instance 
    select id from tableA
    union 
    select name from table b 
    but union will not work because the result sets datatypes are not identical so how to go about this ?
    Thanks

    You have to CAST or CONVERT (or implicitly convert) the columns to the same datatype.  You must find a datatype that both columns can be converted to without error.  In your example I'm guessing id is an int and name is a varchar or nvarchar. 
    Since you didn't convert the datatypes, SQL will use its data precedence rules and attempt to convert name to an int.  If any row contains a row that has a value in name that cannot be converted to an int, you will get an error.  The solution is
    to force SQL to convert the int to varchar.  So you want something like
    select cast(id as varchar(12)) from tableA
    union
    select name from tableb
    If the datatypes are something other that int or varchar, you must find a compatable datatype and then convert one (or both) of the columns to that datatype.
    Tom

  • SELECT OPTIONS use in select statement

    hi,
    I have defined my selection screen in the main program.
    selection-screen begin of screen 0101 as subscreen.
    selection-screen begin of block b1.
    select-options:  S_KUNNR for  KNA1-KUNNR,
    selection-screen end of block b1.
    selection-screen end of screen 0101.
    then in an include in the same module pool, i try to use this in select statement
    SELECT * INTO CORRESPONDING FIELDS OF XXX FROM ZPPP WHERE KUNNR IN S_KUNNR.
    I get  an error saying " the IN operator with S_KUNNR is neither followed by an internal table nor by a valuelist "..what does this mean ?
    thks

    Check the sample code...
    REPORT  ztest_mod.
    DATA: kunnr TYPE kunnr.
    * Custom Selection Screen 0200
    SELECTION-SCREEN BEGIN OF SCREEN 0200 AS SUBSCREEN.
    SELECT-OPTIONS: s_kunnr FOR  kunnr.
    SELECTION-SCREEN END OF SCREEN 0200.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_kunnr-low.
      BREAK-POINT.
    START-OF-SELECTION.
      "in this screen i have a button with function code 'SEARCH'
    " and a subscreen area with name sub
      CALL SCREEN 100.
    *&      Module  STATUS_0100  OUTPUT
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'STATUS'.
    ENDMODULE.                    "status_0100 OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
    MODULE user_command_0100 INPUT.
      DATA: it_kunnr TYPE TABLE OF kna1.
      CASE sy-ucomm.
        WHEN 'SEARCH'.
          SELECT * FROM kna1
          INTO TABLE it_kunnr
          WHERE kunnr IN s_kunnr.
        WHEN 'BACK'.
          LEAVE TO SCREEN 0.
      ENDCASE.
    ENDMODULE.                    "user_command_0100 INPUT
    in the flow logic..
    PROCESS BEFORE OUTPUT.
      MODULE status_0100.
      CALL SUBSCREEN sub INCLUDING sy-repid '0200'.
    PROCESS AFTER INPUT.
      MODULE user_command_0100.
    Regards
    Vijay Babu Dudla

  • Index not being used in Select statement

    Friends
    I have the following SQL statement:
    SELECT
    a.acct,
    a.date_field,
    UPPER(b.feegroup) feegrp,
    SUM (a.fee1) fee1,
    SUM (a.fee2) fee2,
    SUM (a.fee3) fee3
    FROM table1 a, table2 b
    WHERE 1 = 1
    AND a.fee_id = b.fee_id
    GROUP BY a.acct, a.date_field, b.feegroup;
    Both the tables have index on fee_id column. When I run the explain plan for this statement, I am getting the following output:
    Operation | Option | Object Name | Position
    SELECT STATEMENT | | | 560299
    HASH | GROUP BY| |1
    TABLE ACCESS | FULL| table2 | 1
    TABLE ACCESS | FULL| table1 | 2
    Why Oracle is not using the index?
    Edited by: darshilm on Dec 10, 2009 3:56 PM

    The proposed plan is the optimal according to your current conditions in the "where clause" where you have only the equality join condition and therefore the CBO can use HASH JOIN. Using any kind of index access would just increase the amount of required work unless you would add some very restrictive conditions which will select rows from relatively small amount of blocks. Here I have to mention that what really counts in the CBO cost calculation is the amount of blocks accessed and not the number of rows. The "currency" for I/O in Oracle is a block and not a row. CBO always uses an assumption that there is nothing in the buffer cache and it will have to perform a physical read for every block.
    How many blocks will actually be accessed depends on the data distribution. It can happen that every single row that you have to retrieve resides in a different block and although you access only 1000 rows out of a million row table you would have to visit almost every block of that table. For such a situation a FULL TABLE SCAN is the best access path and Oracle will use multiblock I/O for that. On the other side you can have those 1000 rows only in a few blocks and then the index access would be the most appropriate one. For index access Oracle uses single block I/O. Usually the actual situation is somewhere between this two extreme situations. But you can run some tests by yourself and see when an index access will be replaced by a full table scan while you will make your predicates less selective.
    HTH, Joze
    Co-author of the forthcoming book "Expert Oracle Practices"
    http://www.apress.com/book/view/9781430226680
    Oracle related blog: http://joze-senegacnik.blogspot.com/
    Blog about flying: http://jsenegacnik.blogspot.com/
    Blog about Building Ovens, Baking and Cooking: http://senegacnik.blogspot.com

  • How can i retrieve the output of procedure using a select statement ?

    Hi every one.
    this mite be dumm ?
    how can i use the output of the a procedure containing multiple rows of data in a select statement ?

    This is not  a SQL Developer question. You should ask it in the SQL and PL/SQL forum.
    The short answer is you can't.  Sounds is if you are trying to use MSSQL techniques in oracle. Learn oracle techniques

Maybe you are looking for

  • Are there any new HP Printers which will work on the new Airport Extreme?

    Has anyone had luck connecting an HP printer to the new 802.11N network? We have an older one which will not connect. THANKS!

  • Blending modes, RGB to CMYK

    Hi, Is there any way that blending modes in cmyk look the same (change the colors in a same way) as that they are in RGB ? Thanks

  • Building multiple product pages

    Hello... When it comes to creating up to 1700 web pages that are generally the same but a few attributes need to be changed what is the best way to speed up the process? For example, let's say you have 1700 products to sell and you need to create lin

  • ISP requires authentication for outgoing email

    On my Samsung Droid, my ISP requires authentication for outgoing email.  I don't see this as an option and so all my supposedly sent items are sitting in my Outbox.  Anyone else have this issue?  My Gmail and Hotmail accounts work just fine. Thx

  • Activating original Iphone.

    The Iphone went crazy on Friday, Saturday, Sunday.  Everytime you touched it - it would hop around all of your contacts, sometimes call a contact or activate Yahoo or Google on Safari.   Finally decided that I needed to refresh the software.  After d