How to return the first 10 records

Hi all

Can someone help me get a logic in a stored procedure that USER_ID and START_DATE as input and returns
first ten SESSION_DETAILS USER that match on USER_ID of table
and entry start_date is equal or superior to table start_date and equal or less than table end_date

Hello

the procedure will give a return Ref Cursor, and then you can extract the data in the calling procedure (untested):

create or replace function user_session_details(p_user_id in number, p_start_date in date)
return sys_refcursor
as
  l_cur sys_refcursor;
begin
   open l_cur for
      select *
      from
      (select session_details from user
       where user_id =p_user_id
       and p_start_date between start_date and end_data
     )
   where rownum <=10
  ;
 return l_cur;
end;

Now you can use this function (in SQLPLUS):

  var rc refcursor;

  begin
     :rc := user_session_details(1, sysdate);
  end;
  /
  print rc

Good luck

Herald tiomela
http://htendam.WordPress.com

Tags: Database

Similar Questions

  • Columns of folder: by default, how can return the first column 'Name' without having to move it manually every time?

    Something's happened awhile and when I create a folder which appears the first column is the column 'Date modified '. By default, how can return the first column 'Name' without having to move it manually every time?

    Hello

    I suggest you to visit these links and check if it helps:

    http://Windows.Microsoft.com/en-us/Windows-Vista/working-with-files-and-folders#section_4

    http://Windows.Microsoft.com/en-us/Windows-Vista/folders-frequently-asked-questions

    It will be useful.

  • How to get the first 5 records the table max

    Hello Experts,

    I had a rqmt to extract first five columns in a table for the past 6 years, I have implemented the function Rank and doing this, but it does not work, can anyone suggest me how to implement this?

    Thank you.

    Hello...

    Define first five... is this

    Select * from table_name
    where rownum<6>

    Then, create a column inside fx: RCOUNT (1), then filter this column: less than 6.
    ------------------------
    or is it based on a few rows?
    just explain.

    Check if correct/help
    Bachelot

  • Returns the number of records

    IM under the sub query, it returns the number of records, but how can I count the number of records is reurning?

    I use version 12.0.0.61 (toad for oracle)

    Thank you

    Select * from object

    where owner = 'FIRST '.

    AND OBJECT_TYPE = 'FUNCTION '.

    AND OBJECT_NAME LIKE '% FDR_ % '.

    If you want just the County

    select count(*)
      from all_objects
     where owner='PREMIER'
      AND OBJECT_TYPE='FUNCTION'
      AND OBJECT_NAME LIKE'%FDR_%'
    

    If you want the number on each line in addition to the line-level data

    select a.*, count(*) over () cnt
      from all_objects a
     where owner='PREMIER'
      AND OBJECT_TYPE='FUNCTION'
      AND OBJECT_NAME LIKE'%FDR_%'
    

    Justin

  • How to select the first item in an array in a loop FOR

    Hello.

    I use Labview 8.5

    In my application, I have a loop 'for' where I read some values from a device. (strings and digital)

    As you know Labview 'stores' values up to what the loop 'for' is completed, and then they come out in a table.

    Ok.

    I want to just use the first element for strings and digital and then do something with it, like to compare (for digital)

    For strings, I used successfully 'Split 1 D Array' and choose 'everything first subarray'. Good.

    Now for digital that works too, but the result is an element, array type too. I need to be digital (decimal) is not no table type, because I need to compare (greater than 0). Then use a case...

    So, table of an element in a digital decimal? Or the table at the first decimal element. How?

    I tried also with the subset of the table. Even think. Labview won't let me compare a table 1 d with 0. It makes sense, but how to convert, to have the first decimal element?

    Try to use the 'Index Array' function. If you do not connect to the terminal of the index value, it will return the first elelemnt in the table. If wire you an index, it will return the value specified.

    Ben

  • How to return the approver e-mail notification iProcurement in R12?

    Hi all

    How to return the approver e-mail notification iProcurement in R12?

    Symptom: A Summit a requisition to B, need for approval of B

    (1) B lost the e-mail that is sent by A
    (2) need B a new notification sent by A.

    environment: Oracle R12.1.2 | AIX 6.1




    Concerning
    Terry Chen

    I thank you for your answer, you want to reassign B once again?

    Yes.

    Can I use the feature "Rewind"? Can this function sends notification to the user again?

    Don't know if it would work for notifications of iProcurement, then please try first the option to reassign.

    Thank you
    Hussein

  • How to set the first character as selections in the EditField.

    Hi friends,

    I am a third-party application that I have to set the first character as capital.

    so please help me how to set the first tank as capital.

    Take a look at AutoTextEditField - maybe you can use this to do it automatically...

  • How to find the first Sunday and the second Saturday of each month

    Hi all

    How to find the first Sunday and the second Saturday of each month

    Thank you

    Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production

    994122 wrote:

    Hello

    I need to pass the months parameter how to do this? like Jan, Feb etc... (one of those)

    Do you have a procedure?

    Should you output only for the months you passed in the parameter?

    The easiest way is to set the parameter as date. When you go such as p_date as DATE ' 2014-10-01', then you can

    PROCEDURE two_dates)

    p_date IN DATE

    p_first_sunday DATE

    p_second_saturday DATE

    )

    IS

    BEGIN

    p_first_sunday: = NEXT_DAY (TRUNC (p_date, 'MM') - 1, TO_CHAR (DATE ' 2014-10-12', 'DAY'));

    p_second_saturday: = NEXT_DAY (TRUNC (p_date, 'MM') - 1, TO_CHAR (DATE ' 2014-10-11', 'DAY')) + 7;

    END two_dates;

    Or you describe what you need.

  • How to put the first page to run?

    How to put the first page to run?

    Dimitri Gielis Blog (Oracle Application Express - APEX): Change the page (first) by default in APEX

  • set_item_property changing the text, but how to return the original value

    Hi all
    I use Oracle Forms Builder 10 gr 2 / I have the following problem: in a button I trigger when it is pressed. And then I change a few elements prompt text. But my problem is how to return the original prompt text. A kind of refresh or clear?


    Here is a piece of code that modifies the prompt text:
    set_item_property('XXBG_CE_STATEMENT_LINES_NEW.AGENT_NO', PROMPT_TEXT, get_item_property('XXBG_CE_STATEMENT_LINES_NEW.AGENT_NO', prompt_text) || '*');
    Thanks in advance,
    Bahchevanov.

    This is not tested, but it's something like this:

    declare
       v_item  varchar2(200);
    begin
       v_item := get_block_property('block',first_item);
       loop
          exit when v_item = 'block.'||null;
          set_item_property(...);
          v_item := 'block.'||get_item_property(v_item,nextitem );
       end loop;
    end;
    
  • How to get the first element of a list?

    Hello

    I have the following hierarchy:

    A (first level)
    -A1 (A child)
    -B1 (A child)
    -B11 (B1 child)
    -B12 (B1 child)

    I have a UDA on B11 and B12 members who have the same name as the A1, and I want to assign values to A1 to B11 and B12. After that, I want to consolidate the hierarchy so I can have B1 and with values.

    I would like to use the ancestors function to do but the ancestors need a member as a parameter and the only relationship between A1 and B11, B12 is the UDA.

    I can't do @ANCESTORS (@UDA (%{dimname/}, 'A1')) because of this, so I would use a function to get at least 1 member with the UDA, I want and use ancestors on this subject, but I can't seem to find a function that returns the first member of a list.

    Can someone help me on this?

    Thank you

    Bummer, I finally shot to the top of my 11.1.2.1 instance of cloud and tried. You have (unfortunately) reason - I can spend real members names in @LANCESTORS and use it outside of a DIFFICULTY, but the minute I put in @ATTRIBUTE or @UDA he has poured out. Disappointment, because I thought that was a really cool thing.

    I think still if you know z is always the parent you want to consolidate, a @IDESCENDANTS("Z") would do the trick, but maybe with inefficient - certainly less than a full size AGG.

    Kind regards

    Cameron Lackpour

    Published by: CL 4 June 2012 10:13
    Arrgh, and it's in the docs with underlining added by me:
    If the function @LANCESTORS is used alone (not in a statement to FIX), you must use the function @LIST and specify names of members.

  • How to replace the first occurrence of a substring

    How to replace the first occurrence of a substring of my original string? everything built in features in PL/SL?
    EX: Original string: "webinweb" I need the output of string as: "xyzinweb" simply replace occuarnce first of 'web' by "xyz".
    SQL> select   regexp_replace('webinweb','web','xyz',1,1) from dual
    /
    REGEXP_R
    --------
    xyzinweb
    
  • How to find the most recent record?

    How to find the most recent record?

    Hello

    It is part of our Bill the elements table, retrieved by the following query:

    SELECT movimento, dt_movimento, cd_material,
    cd_tp_operacao, nf, series,
    sole, pr_unitario
    Of itemfat
    WHERE cd_material IN ('722136', '759177', ' 810725', 818848')
    AND cd_tp_operacao ("' 1102 c ' ', ' 2102 C")
    ORDER BY cd_material,
    dt_movimento


    MOVIMENTO DT_MOVIMENTO CD_MATERIAL CD_TP_OPERACAO NF SERIES AS PR_UNITARIO
    2008-03-11 2137625, 722136 2102 1084738 3 120 2 915
    2588890 08/05/2008 722136-2102 1090987 3 120 2,5615
    755522 09/10/2007 759177-2102 101449 1 200 0.6
    701055 03/10/2007 810725-2102 1013865 1 36 10.9
    1588804 20/12/2007 810725 2102 1014182 1 96 10.9
    1305653 03/12/2007 818848-2102 108555 1 240 6.5
    3102134 07/18/2008 818848 2102 109784 1 360 6.5


    Seems that I whant to retrieve only the most recent records for each item, as:

    MOVIMENTO DT_MOVIMENTO CD_MATERIAL CD_TP_OPERACAO NF SERIES AS PR_UNITARIO
    2588890 08/05/2008 722136-2102 1090987 3 120 2,5615
    755522 09/10/2007 759177-2102 101449 1 200 0.6
    1588804 20/12/2007 810725 2102 1014182 1 96 10.9
    3102134 07/18/2008 818848 2102 109784 1 360 6.5


    Can someone help me with a sentece SQL to do?

    Thanks in advance.

    You can certainly do it:

    SELECT   movimento, dt_movimento, cd_material, cd_tp_operacao, nf, serie,
             quantidade, pr_unitario
        FROM itemfat i
       WHERE cd_material IN ('722136', '759177', '810725', '818848')
         AND cd_tp_operacao IN ('1102C', '2102C')
         AND dt_movimento =
                (SELECT MAX (dt_movimento)
                   FROM itemfat d
                  WHERE d.cd_material = i.cd_material
                    AND d.cd_material IN ('722136', '759177', '810725', '818848')
                    AND d.cd_tp_operacao IN ('1102C', '2102C'))
    ORDER BY cd_material, dt_movimento
    

    : p

  • How to get the first and last record

    Hai All

    I have a table called T1 and there are more than 8 lakhs Archives and I have a column named Timestamp, so I need to get the first record value and time stampvalue and last record and time stamp value so that I can conclude that for example
    form June 13 to 15 June data are here


    Kind regards

    SrikkanthM

    What is the problem with:

    select min(timestamp),max(timestamp)
    from T1;
    

    ?

  • HP Pavilion 15: bought and returned the faulty HP laptop - how désenregistrez the point of records of HP?

    Hello

    Last week, I bought a laptop HP, therefore, I explored with enthusiasm and registered the product on the HP website.

    Unfortunately, it was a "bad order" element that the dealer had neglected and sold to me.

    Therefore, how to unregister the article...?

    See you soon!

    Hello

    Support HP members contacted me - solved.

    See you soon!

Maybe you are looking for