Query that returns only certain fields in Java

Currently I use a filter that identifies certain keys, then get all the keys and get a unique value of each object. The rest of the object is important enough. I've seen references to the passage on the ability to do it, using CohQL, but I can't run Java.

Basically, I want to do: "select the"Cache"box where key ="asdf '" I just want back the specific 'field' rather than the entire object. How can I do this?

Thank you.

Hi user13279246,

You can do this by using the ReducerAggregator. Your code would look like:

Filter filter = QueryHelper.createFilter(...);
ValueExtractor extractor = new ReflectionExtractor("isReadOnly");
Map mapResult = cache.aggregate(filter, new ReducerAggregator(extractor));

The mapResult will be indexed by the actual cache keys, but the values will be extracted Boolean property.

If you need to return a number of "columns", you would use the MultiExtractor instead. In this case, each value in the returned map would be a list of corresponding extracted properties.

Kind regards
Gene

Published by: ggleyzer on February 15, 2011 16:41

Tags: Fusion Middleware

Similar Questions

  • Need help to write a MySQL query that returns only the peer matching records

    Because I don't know how to explain it easily, I use the table below as an example.

    I want to create a MySQL query that returns only the records that match counterparts where 'col1' = 'ABC '.

    Notice the ' ABC / GHI' record does not have a Counter-match ' GHI / ABC' record. This record must not be returned because there is no Counter-Party correspondent. With this table, the ' ABC / GHI' record should be the one returned in the query.

    How can I create a query that will do it?


    ID | col1 | col2
    --------------------
    1. ABC | DEF
    2. DEF | ABC
    3. ABC | IGS
    4. DEF | IGS
    5. IGS | DEF


    * Please let me know if you have no idea of what I'm trying to explain.

    I wanted to just the results where col1 = ABC, but I already got the answer I needed on another forum. Thank you anyway.

    SELECT a.col1,
    a.col2
    FROM table_name AS a
    LEFT OUTER
    Table_name JOIN b
    ON b.col1 = a.col2
    AND a.col1 = b.col2
    WHERE b.col1 IS NOT NULL AND a.col1 = 'ABC '.

  • Query that returns number 1 - Add additional columns based on percentages

    I have a query that returns a large number.  The return value will always be a single field (a column, a line, a single value).

    I need to have also three other columns in the return of this request: one that returns a number that is 50% of the original number, one that returns a number that is 75% of the original number, and one that is double the original number.  How is that possible?  If anyone can point me to examples, it would be a great help.  I got the results mixed by searching, so I'm not sure good practices.

    Thank you for the input in advance.

    Hello

    Whenever you have a question, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the accurate results you want from this data, so that people who want to help you can recreate the problem and test their ideas.

    Explain, using specific examples, how you get these results from these data.

    If you show what you want to do using commonly available tables, like those of the scott schema, then you don't need to display the sample data; just results and explanations.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

    I'm not sure that understand the question.

    If x is a number, then

    .50 * x is 50% of this number,

    .75 * x is 75% of that number, and

    2 * x is to double this figure.

    You can get them all in the same query, if you want to.  For example:

    SELECT ename

    sal

    .50 * sal AS p_50

    .75 * sal AS p_75

    2 * sal AS dbl

    FROM scott.emp;

    Output:

    ENAME SAL P_50 P_75 DBL

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

    SMITH, 800, 400, 600, 1600

    1600 800 1200 3200 ALLEN

    1250 625 WARD 937,5 2500

    JONES 2975 1487.5 2231,25 5950

    1250 625 MARTIN 937,5 2500

    2850 1425 BLAKE 2137,5 5700

    2450 1225 CLARK 1837,5 4900

    3000 1500 2250 6000 SCOTT

    KING 5000 2500 3750 10000

    1500 750 1125 3000 TURNER

    1100 550 825 2200 ADAMS

    JAMES 950 475 712,5 1900

    FORD 3000 1500 2250 6000

    1300 650 975 2600 MILLER

    Is that what you ask?

  • Function that returns only numbers

    Is it possible to have a SQL function that returns only numbers in a varchar?

    Example:

    My PHONE_NUMBER table contains a field with a phone number in VARCHAR2, it can contain:

    1-888-444-5555 or (514) 444-6666 or 514-222-4444 ext: 100


    I want to have a fuction which back me:

    18884445555 and 5144446666...


    Thanks for the help

    Hello

    For a copy of the string s with everything except the numbers (0-9), was deleted:

    REGEXP_REPLACE ( s
                   , '[^0-9]
                   )
    

    The expression above will work in Oracle 10 and higher.
    In any version, you can use TRANSLATE to remove the numbers, then reuse TRANSLATE to remove these characters from the s.

    TRANSLATE ( s,
           , '0' || TRANSLATE ( s
                                  , 'A0123456789'
                        , 'A'
                        )
           , '0'
           )
    
  • I need a query that returns the average amount of characters from text colum in MS SQL.

    I need a query that returns the average amount of characters from text colum in MS SQL.

    Could someone show me how?

    Sorting, I need of the

    DATALENGTH

    function

  • SQL QUERY THAT RETURNS THE PL/SQL

    Hello

    I'm putting in 4.2 below apex

    DECLARE

    date of frdate: =: P22_FROMDATE;

    date date: =: P22_TODATE;

    l_date1 varchar2 (11): = to_char(frdate,'dd-mon-yyyy');

    l_date2 varchar2 (11): = to_char(todate,'dd-mon-yyyy');

    v_sql varchar2 (32000);

    v_Name varchar2 (4000): = months_name (frdate, todate);

    char (1) of the v1: = q "[']";

    number of lbr1 (6): =: P22_FROMBRANCH;

    number of LBR2 (6): =: P22_TOBRANCH;

    number of M1 (6): = 11;

    Start

    v_sql: ='SELECT * FROM (SELECT LBRCODE, PRDACCTID, MN, AVGX FROM (SELECT LBRCODE, PRDACCTID, MN, SUM (BALL) BALL, COUNT (MN) DAYS, ROUND (SUM (BAL) count (MN), 2) AVGX ';))

    v_sql: = v_sql | "FROM (SELECT LBRCODE, PRDACCTID, TO_CHAR (BALDATE,'|)) CHR (39) | ' MM' | CHR (39) |') ' | ' ||'|| CHR (39) | » _'|| CHR (39) |' | ' || «TO_CHAR (BALDATE,'|)» CHR (39) | ' AAAA '. CHR (39) |') MN, BALL ';

    V_SQL: = V_SQL | "(SELECT Q2. LBRCODE, Q2. PRDACCTID, T1. BALDATE, T_OST_NEW (Q2. LBRCODE, Q2. PRDACCTID, T1. BALDATE) BALL ';

    V_SQL: = V_SQL | "FROM (select TO_DATE('||) Chr (39) | l_date1 | Chr (39) | «, » || CHR (39) | ' DD-MON-YYYY ' | CHR (39) |') baldate FROM DUAL Union all the ';

    V_SQL: = V_SQL |' select (TO_DATE('||) Chr (39) | l_date1 | Chr (39) | «, » || CHR (39) | ' DD-MON-YYYY ' | CHR (39) |') + level) double baldate ';

    V_SQL: = V_SQL |' connect by level < = (TO_DATE('||) Chr (39) | l_date2 | Chr (39) | «, » || CHR (39) | ' DD-MON-YYYY ' | CHR (39) |') -TO_DATE('||) Chr (39) | l_date1 | Chr (39) | «, » || CHR (39) | ' Dd-mon-yyyy ' | CHR (39) |')) ) Q1,';

    V_SQL: = V_SQL | "(SELECT LBRCODE,'|) ' (rpad (prdcd, 8,'|)) V1 ||'' || v1 |') || LTRIM (rpad('|| v1 ||) » x'|| V1 | «, 25, » || v1 | » 0' || v1||'),'|| v1 | » x'|| v1 |')) prdacctid OF D009021 WHERE the LBRCODE between ' | : P22_FROMBRANCH |' and ' | : P22_TOBRANCH | "AND moduleinfo =' | TO_NUMBER(:P22_SELECTLIST);

    V_SQL: = V_SQL |') ((Q2)) GROUP BY LBRCODE, PRDACCTID, MN))';

    V_SQL: = V_SQL | "PIVOT (MAX (AVGX) (MN) IN (';))

    V_SQL: = V_SQL | V_NAME;

    V_SQL: = V_SQL |')) ORDER OF LBRCODE, PRDACCTID ';

    RETURN V_SQL;

    END;

    I created all the elements of the required page

    I get the error message like missing expression

    to test, I created a function to return the query, it works very well know to return a query that gives me desired report

    am I missing something?

    Help, please

    HEMU wrote:

    Hello Sir

    Sorry to bother you again

    I tried to use «function that returns colon-delimited topics»

    and I got following error

    unable to determine query headings: ORA-06550: line 1, column 138: PLS-00103: Encountered the symbol ";" when expecting one of the following:  . ( ) , * % & = - + < / > at in is mod remainder not rem =>  <> or != or ~= >= <= <> and or like like2 like4 likec between || multiset member submultiset The symbol ")" was substituted for ";" to continue.
    
    failed to parse SQL query:
    

    can take you a look at page901 once again please and a function named months_namex

    is it feasible that I'm looking for?

    The immediate cause of this error is simply incorrect report headings function call syntax:

    return months_namex(to_date(:p901_fromdate,'dd-mon-yyyy'),to_date(:p901_todate,'dd-mon-yyyy')

    This should be:

    return months_namex(to_date(:p901_fromdate,'dd-mon-yyyy'),to_date(:p901_todate,'dd-mon-yyyy'));

    However there is no months_namex function defined in the workspace.

  • Help turn the query that returns single return system

    Hello, I have two tables, readings, and values. Values have a foreign key to the readings.
    create table readings 
    (
    id number primary key,
    point number,
    datereading date
    );
    
    create table reading_values
    (
    id number primary key,
    counter_nr number,
    point number,
    reading_id number,
    datereading date,
    CONSTRAINT fk_reading
    FOREIGN KEY (reading_id)
    REFERENCES readings (id)
    );
    The point and datereadings columns have the same value of related rows.
    insert into readings values (1, 1234, to_date('20100622 12:12', 'yyyymmdd HH24:MI'));
    insert into reading_values values (1, 0, 1234, 1, to_date('20100622 12:12', 'yyyymmdd HH24:MI')); --row1
    insert into reading_values values (2, 1, 1234, 1, to_date('20100622 12:12', 'yyyymmdd HH24:MI')); --row2
    
    insert into readings values (2, 1234, to_date('20100623 12:12', 'yyyymmdd HH24:MI'));
    insert into reading_values values (3, 0, 1234, 2, to_date('20100623 12:12', 'yyyymmdd HH24:MI')); --row3
    insert into reading_values values (4, 1, 1234, 2, to_date('20100623 12:12', 'yyyymmdd HH24:MI')); --row4
    
    insert into readings values (3, 1111, to_date('20100621 12:12', 'yyyymmdd HH24:MI'));
    insert into reading_values values (5, 0, 1111, 3, to_date('20100623 12:12', 'yyyymmdd HH24:MI')); --row5
    Now I have the procedure which the entry: p_point and p_date.
    select * from reading_values rv, 
    (select * from (select id, datereading
    from readings where datereading < p_date and point = p_point
     order by datereading desc) where rownum <= 1) t where rv.reading_id = t.id
    so I want the previous reading_values (in time based on p_date) for a certain point p_date. I hope this makes sense?
    Example:
    select * from reading_values rv, 
    (select * from (select id, datereading
    from readings where datereading < to_date('20100624 12:12', 'yyyymmdd HH24:MI') and point = 1234
     order by datereading desc) where rownum <= 1) t where rv.reading_id = t.id
    
    returns row 3 and 4
    Now, what I want to do, is replace p_point and p_date with two collections. For example: p_points = [1234, 1111] p_dates = [20100622 15:12, 20100624 12:12]
    Here, I want to have the previous reading_values by point = 1234 and datereading < 20100622 order 15:12 by datereading (where rownum < = 1).

    and also reading_values by point = 1111 and datereading < 20100624 order 12:12 by datereading (where rownum < = 1).

    This should return line1, line2 and row5...

    So far I came up with this. But I can't be sure that it is correct. And the performance seems to be horrible (cost 88, 13 recursive calls, 155 becomes uniform) for a query with 2 entry points and 2 dates compared to the original to just a single point query and the date of entry (cost 13, 1 recursive call and gets 14 coherent).
    Select rv.* from (SELECT r.id
          FROM    Readings r, 
          (select rownum rn1, t1.id from table1 t1 order by id) t1, -- input parameter1 (point collection)
          (select rownum rn2, t2.date_now from table1 t2 order by id) t2  -- input parameter 2 (date collection)
          WHERE  r.point = t1.id
              AND     r.datereading = (SELECT  max(r2.datereading)
              FROM   Readings r2
                WHERE   r2.point = t1.id
                AND     r2.datereading < t2.date_now AND rn1 = rn2)
        ) r, Reading_Values rv where r.id= rv.reading_id;
    code for creating table 1 that I used instead of collections of entry:
    create table table1
    (
     id number not null primary key,
     date_now date not null
    );
    insert into table1 values (1234, to_date('20100622 15:12', 'yyyymmdd HH24:MI'));
    insert into table1 values (1111, to_date('20100624 12:12', 'yyyymmdd HH24:MI'));
    Hope someone can help me on my way :) Please ask if something is unclear or strange! Thank you!

    Published by: KarlTrumstedt on 23-jun-2010 06:20

    Try this

    SELECT RV.ID, RV.COUNTER_NR, RV.POINT, RV.READING_ID, RV.DATEREADING
    FROM (
        SELECT (    SELECT LAST_VALUE(RE.ID) OVER
                         (PARTITION BY RE.POINT ORDER BY RE.DATEREADING)
                    FROM READINGS RE
                    WHERE RE.DATEREADING < T1.DATE_NOW AND RE.POINT = T1.ID
                ) ID,
                T1.ID POINT,
                T1.DATE_NOW
        FROM TABLE1 T1
    ) X
    JOIN READING_VALUES RV
    ON (X.ID = RV.READING_ID AND X.POINT = RV.POINT)
    ;
    
  • Doubt with query that returns unnecessary reocrds

    Hello
    I use under query to retrieve security descending titles in a database:

    Select master sre1.security_id,
    sre2. Clone SECURITY_ID, sa1. Addr STREET_ADDR1
    Of
    SAM_REAL_ESTATE sre1, SAM_REAL_ESTATE sre2, sam_address sa1, sa2 sam_address
    where
    sre1. ADDRESS_ID = sa1. ADDRESS_ID and sre2. ADDRESS_ID = sa2. ADDRESS_ID
    and sre1.security_id < sre2. SECURITY_ID
    and trim (nvl (upper (sa1. STREET_ADDR1), 'Null')) = trim (nvl (upper (sa2. STREET_ADDR1), 'Null'))
    and in sre1.security_id (175459876,175460893,175460770,20530359,21943331,20306795)
    and in sre2.security_id (175459876,175460893,175460770,20530359,21943331,20306795)
    order by 1, 2;


    which returns results as below:

    MASTER CLONE ADDR
    20306795 20530359 Waverley
    20306795 21943331 Waverley
    * 20530359 21943331 Waverley *.
    175459876 175460770 temple
    175459876 175460893 temple
    * 175460770 temple 175460893 *.

    Now, I do not want the selected records in bold as the safety of clone is coming security master while only the less registration by different address should enter into main list and the rest of his security should come clone

    Please suggest

    Thank you
    Deepak

    NOT TESTED

    select min(master) master,clone,addr
      from (select sre1.security_id master,
                   sre2.SECURITY_ID clone,
                   sa1.STREET_ADDR1 addr
              from SAM_REAL_ESTATE sre1,
                   SAM_REAL_ESTATE sre2,
                   sam_address sa1,
                   sam_address sa2
             where sre1.ADDRESS_ID = sa1.ADDRESS_ID
               and sre2.ADDRESS_ID = sa2.ADDRESS_ID
               and sre1.security_id < sre2.SECURITY_ID
               and trim(nvl(upper(sa1.STREET_ADDR1),'Null')) = trim(nvl(upper(sa2.STREET_ADDR1),'Null'))
               and sre1.security_id in(175459876,175460893,175460770,20530359,21943331,20306795)
               and sre2.security_id in(175459876,175460893,175460770,20530359,21943331,20306795)
             order by sre2.SECURITY_ID,upper(sa1.STREET_ADDR1),sre1.security_id
           )
     group by clone,addr
     order by 1,2
    

    Concerning

    Etbin

    It is not a Top - N query

    Edited by: Etbin the 13.8.2009 12:00

  • Feed the list component with labels that have only certain values.

    I have to be able to sort out shorter labels in the component 'listHolder.list' by values in 'Fan', 'Herdighet', etc., which will be selected of the other items in the list
    (those who do not need to be fed by XML, but the list items own dataProvider)

    Practical example: displays only the labels in listHolder.list that are connected to the "H1" value in "Herdighet" or "H2" "Herdighet" etc.

    I am fairly new to AS3, so I do not know how to start. I appreciate everything you can give clues.

    Here's the code so far:

    //--------------------------

    var loader: URLLoader = new URLLoader();

    loader.addEventListener (Event.COMPLETE, onLoaded);

    listHolder.list. addEventListener (Event.CHANGE, itemChange);

    function itemChange(e:Event):void {}

    var selectedObj:Object = a [listHolder.listSelectedIndex]

    var xml;

    var a: Array = [];

    function onLoaded(e:Event):void {}

    XML = new XML (e.target.data);

    var it: XMLList = xml. Lauvtre;

    for (var i: uint = 0; i < il.length (); i ++) {}

    listHolder.list.addItem ({.child('Botanisk_navn').toString ()label: it [i]+ "\n"+ "-" + it [i].child('Norsk_navn').toString () "});

    a [i] = {'Fan': it [i].child('Farge').toString (), 'Herdighet': it [i].child('Herdighet').toString (),}

    "Høyde": he [i].child('hoyde').tostring (), "Botanisk_navn": he [i] .one ('Botanisk_n avn') m:System.NET.SocketAddress.ToString (),.

    'Norsk_navn': it [i].child('Norsk_navn').toString (), 'Image': it [i] .child ('image'). toString(),

    {"Blomstring": he [i].child('Blomstring').toString (), "Lysforhold": he [i] .one ('Lily book') m:System.NET.SocketAddress.ToString ()};

    }

    }

    Loader.Load (new URLRequest ("lauvtre.xml"));

    Fusion is a good thing.  The more you have to understand this, easy it all comes together when the lights start to go.

    In regard to the 'a' table... If you look at how values are it is attributed originally, they are attributed to the 'i' value of the index.  So, if the first element that passes the test of H1/H2 is the 10th 'i', it means that 10 of the table value is assigned to the first value you found.  The first 9 values in the table are zero as a result.

    But if you use the method push of the array class.

    a.push ({"Fan": he [i].child('Farge').toString (),... etc...});

    then the item is added to the index of the table rather than the 'i' the next clue.  If a table will have the same number of elements as the list and the list and table will agree in regard to pair them up.

  • Query that count only the column null lines

    create table test
    (a varchar2 (10))
    b varchar2 (10),
    c varchar2 (10),
    d varchar2 (10),
    e varchar2 (10));


    SQL > DESC TEST
    Name Null? Type
    ------------------------------- -------- ----
    A VARCHAR2 (10)
    B VARCHAR2 (10)
    C VARCHAR2 (10)
    D VARCHAR2 (10)
    E VARCHAR2 (10)

    SQL > SELECT * FROM TEST;

    A B C D E
    ---------- ---------- ---------- ---------- ----------
    A1 - A3 A4-
    B1 - B3, B4-
    C1 - C3 C4-
    D1 - D4 D5
    -E2 - E4 E5


    I want an application that only count the rows of the column as null

    A B C D E
    --- ---- ----- ------ -------
    1 4 2 0 3

    Published by: Nilesh hole, Pune, India, on August 28, 2009 12:30
    select SUM(case when a is null then 1 else 0 end)
          ,SUM(case when b is null then 1 else 0 end)
          ,SUM(case when c is null then 1 else 0 end)
          ,SUM(case when d is null then 1 else 0 end)
          ,SUM(case when e is null then 1 else 0 end)
    from TEST
    /
    

    Published by: Toon Koppelaars August 28, 2009 09:07

  • Refine a query to return only one day in the current week

    Hello again,

    Sorry, I thought I could work this given my previous help on the forum but I can't.

    What I do now is to look at the date ranges of records and display which of them are active on a given day of the current week. So for the week beginning June 27, 2011, a Monday, I need to see the records that are present on that day. The same thing on Tuesday, sea, game, Fri.

    Any ideas?


    Kind regards

    Steve Welch

    Hi Steve,.
    No doubt there is a way more elegant to do, but based on my previous post example...

    SELECT TO_CHAR (begin_date, 'DD-Mon-YYYY HH24:MI:SS') AS begin_date,
    TO_CHAR (end_date, 'DD-Mon-YYYY HH24:MI:SS') AS end_date,
    CASE WHEN TRUNC(begin_date) NEXT_DAY (TRUNC (SYSDATE) - 1, 'Sat') - 7 THEN 'X' END AS "Sun",
    CASE WHEN TRUNC(begin_date) NEXT_DAY (TRUNC (SYSDATE) - 1, 'Sat') - 6 THEN 'X' END AS "Mon",
    CASE WHEN TRUNC(begin_date) NEXT_DAY (TRUNC (SYSDATE) - 1, 'Sat') - 5 THEN 'X' END AS "Tue",
    CASE WHEN TRUNC(begin_date) NEXT_DAY (TRUNC (SYSDATE) - 1, 'Sat') - 4 THEN 'X' END AS "Wed",
    CASE WHEN TRUNC(begin_date) NEXT_DAY (TRUNC (SYSDATE) - 1, 'Sat') - 3 THEN 'X' END AS "Thu",
    CASE WHEN TRUNC(begin_date) NEXT_DAY (TRUNC (SYSDATE) - 1, 'Sat') - 2 THEN 'X' END AS "Fri",
    CASE WHEN TRUNC(begin_date) NEXT_DAY (TRUNC (SYSDATE) - 1, 'Sat') -1 THEN 'X' END AS "Sat"
    FROM mydates
    WHERE TRUNC (begin_date) < NEXT_DAY (TRUNC (SYSDATE) - 1, 'Sat') + 1
    AND TRUNC (end_date) > NEXT_DAY (TRUNC (SYSDATE) - 1, 'Sat') - 7
    ORDER BY begin_date 
    

    would give

    BEGIN_DATE end_date Mon Mar sea game Fri Sat Sun
    June 15, 2011 06:48:29 June 25, 2011 06:48:29 X X X X X X X
    June 25, 2011 06:47:57 July 5, 2011 06:47:57 X

    See you soon,.
    Rob

    Published by: Robert Chalton on June 25, 2011 10:31

  • Query that returns several generic criteria using as and in

    Hi there, try to do something like this:

    Select * from tablename
    Where columnname as 5% ' or as 8% ' or like 12% '

    without the help OR... so in this big:

    Select * from tablename
    Where columnname like IN (5% ", 8%, 12%" ")

    In MS Sql, I can do something like this:

    SELECT * from tablename t
    Where exists (select val FROM dbo.fn_String_To_Table (25, 05', '', 0))
    ATA columname WHERE AS val + '%')

    Where dbo.fn_String_To_Table converts the array of strings in a table.

    Any suggestions?

    Thank you very much.

    Samir says:

    where the comma-delimited string variable?

    Use your imagination :):

    select  *
      from  tablename t
      where regexp_like(t.column_name,'^(' || replace(starts_with_scv,',','|') || ')')
    / 
    

    SY.

  • Looping on a method that returns a query

    Hello

    I have a method that returns a query, I convey in this method, an identification number, the query uses in where clause. Now I have another query that returns a list of identification numbers that I have to loop through the appellant the first method and passing in the ID number, for example

    methodA

    Browse the methodA results
    Call methodB passing methodA.ID
    results of methodB
    close the loop

    now, the problem I have is that methodB returns a query and I want to be able to return the results of methodB as a unique query structure. I don't know how many times I will do a loop through the results of methodA, maybe twice, he could by ten times. Thus, the results of calling methodB could be very large.
    How can I add methodB results in a single query structure?

    I finally had to create a monster query with joins in about three tables, but it works.

  • Selection of a function that returns a sys refcursor or alternative

    I have a query that returns a result set of three columns, namely the SSN, the PAID_YEAR and the PAID_TOTAL. This query, I can:

    1. Create a view and then question him.
    2. Create a function result set and return

    If I go the first way, that a simple request like this takes more than 20 seconds:

    SELECT PAID_YEAR,PAID_TOTAL FROM VIEW_1 WHERE SSN=12345678912882;

    I know it's because when I query a view engine first brings all the rows in the view and then filters the lines for the criteria provided.

    If I go the second way I can send only a parameter and make the engine look for only the rows that match the condition and the Recordset. But I don't know how then SELECT this result set returned. I took a look at the tables in pipeline, but do not understand how to their advantage. So my final question is if it is somehow possible to select from the result set returned by a function like this:

    SELECT * FROM FUNCTION_1(12132323232).

    If Yes, then how, if not, what would be another way?

    I know it's because when I query a view engine first brings all the rows in the view and then filters the lines for the criteria provided.

    No - you don't "know that" because it is not true. Just check out the plan of the command explain to yourself. Oracle can always use appropriate indexes so that only the needed rows are returned.

    So my final question is if it is somehow possible to select from the result set returned by a function like this:

    SELECT * FROM FUNCTION_1(12132323232).
    

    No - you can't do it like that. You must use the TABLE function to process the result of the function defined in a table:

    'SELECT * FROM TABLE(FUNCTION_1(12132323232)).

    -type to match record emp
    create or replace type emp_scalar_type as an object
    (EMPNO NUMBER 4,
    ENAME VARCHAR2 (10),
    USE VARCHAR2 (9).
    MGR NUMBER 4,
    HIREDATE DATE,
    NUMBER OF SAL (7, 2)
    NUMBER OF COMM (7, 2)
    DEPTNO NUMBER (2)
    )
    /

    -records of the emp table
    create or replace type emp_table_type to table of emp_scalar_type
    /

    -function of pipelined

    create or replace function get_emp (p_deptno number)
    return emp_table_type
    PIPELINED
    as
    TYPE EmpCurTyp IS REF CURSOR RETURN emp % ROWTYPE;
    emp_cv EmpCurTyp;
    l_rec emp % rowtype;
    Start
    Open emp_cv SELECT * from emp where deptno = p_deptno;
    loop
    extract the emp_cv in l_rec;
    When the output (emp_cv % notfound);
    line of conduct (emp_scalar_type (l_rec.empno, LOWER (l_rec.ename),
    l_rec.job, l_rec.mgr, l_rec.hiredate, l_rec.sal, l_rec.comm, l_rec.deptno));
    end loop;
    return;
    end;
    /
     
    Select * from table (get_emp (20))

  • Foreach returns only the first line of a dataset object

    Hello, guys.

    I am having trouble with a procedure in Oracle 9.2.0.1.0.

    I have a query that returns the number of lines, but whenever I try to browse by using a foreach loop, I only get the first line and then the loop is completed.

    For example, here's the query:

    select 
          (
            CASE
              WHEN
                TO_DATE(
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'dd') || '/' ||
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'mm') || '/' ||
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'yyyy'),'DD/MM/YYYY') < DATE '2009-01-01'
              THEN DATE '2009-01-01'
              ELSE
                TO_DATE(
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'dd') || '/' ||
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'mm') || '/' ||
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'yyyy'), 'DD/MM/YYYY')
              END
          ) startdate,
    
    
          (
            CASE
              WHEN
              TO_DATE(
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level) -1,'dd') || '/' ||
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'mm') || '/' ||
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'yyyy'),'DD/MM/YYYY') > DATE '2009-06-08'
              THEN DATE '2009-06-08'
              ELSE 
              TO_DATE(
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level) -1,'dd') || '/' ||
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'mm') || '/' ||
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'yyyy'), 'DD/MM/YYYY')
              END
          ) enddate
         
        FROM dual
        CONNECT by trunc(DATE '2009-06-08','dd') >= add_months(trunc(DATE '2009-01-01','dd'),level - 1)
    

    Who shows me this output:

    STARTDATEENDDATE
    01/01/20092009-01-31
    02/01/200928/02/2009
    03/01/200931/03/2009
    04/01/200930/04/2009
    05/01/200931/05/2009
    06/01/200906/08/2009

    But whenever I run this code:

      for rec in
      (
        select 
          (
            CASE
              WHEN
                TO_DATE(
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'dd') || '/' ||
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'mm') || '/' ||
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'yyyy'),'DD/MM/YYYY') < DATE '2009-01-01'
              THEN DATE '2009-01-01'
              ELSE
                TO_DATE(
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'dd') || '/' ||
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'mm') || '/' ||
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'yyyy'), 'DD/MM/YYYY')
              END
          ) startdate,
          (
            CASE
              WHEN
              TO_DATE(
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level) -1,'dd') || '/' ||
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'mm') || '/' ||
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'yyyy'),'DD/MM/YYYY') > DATE '2009-06-08'
              THEN DATE '2009-06-08'
              ELSE 
              TO_DATE(
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level) -1,'dd') || '/' ||
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'mm') || '/' ||
                to_char(add_months(trunc(DATE '2009-01-01','mm'),level - 1),'yyyy'), 'DD/MM/YYYY')
              END
          ) enddate
         
        FROM dual
        CONNECT by trunc(DATE '2009-06-08','dd') >= add_months(trunc(DATE '2009-01-01','dd'),level - 1)    
      )
      loop
        DBMS_OUTPUT.put_line(TO_CHAR(rec.startdate, 'YYYYMMDD') || '-' || TO_CHAR(rec.enddate, 'YYYYMMDD'));
      end loop;
    

    I get this result:

    20090131 20090101

    I tried debugging and I checked that the loop runs that once, and then passes the end of loop. I'm doing something wrong?

    Thank you!

    Best regards

    Vinicius

    Try:

    for rec in

    (

    Select * from (select

    (

    CASE

    WHEN

    TO_DATE)

    TO_CHAR (add_months (trunc (DATE ' 2009-01-01', 'mm'), level - 1), "jj"). '/' ||

    TO_CHAR (add_months (trunc (DATE ' 2009-01-01', 'mm'), level - 1), "mm"). '/' ||

    TO_CHAR (add_months (trunc (DATE ' 2009-01-01', 'mm'), level - 1), 'yyyy'), "DD/MM/YYYY")< date="">

    THEN DAY ' 2009-01-01'

    ON THE OTHER

    TO_DATE)

    TO_CHAR (add_months (trunc (DATE ' 2009-01-01', 'mm'), level - 1), "jj"). '/' ||

    TO_CHAR (add_months (trunc (DATE ' 2009-01-01', 'mm'), level - 1), "mm"). '/' ||

    TO_CHAR (add_months (trunc (DATE ' 2009-01-01', 'mm'), level - 1), 'yyyy'), "DD/MM/YYYY")

    END

    ) startdate.

    (

    CASE

    WHEN

    TO_DATE)

    TO_CHAR (add_months (trunc (DATE ' 2009-01-01', 'mm') and level)-1, "dd"). '/' ||

    TO_CHAR (add_months (trunc (DATE ' 2009-01-01', 'mm'), level - 1), "mm"). '/' ||

    TO_CHAR (add_months (trunc (DATE ' 2009-01-01', 'mm'), level - 1), 'yyyy'), ' DD/MM/YYYY') > DATE '' 2009-06-08

    THEN DAY '' 2009-06-08

    ON THE OTHER

    TO_DATE)

    TO_CHAR (add_months (trunc (DATE ' 2009-01-01', 'mm') and level)-1, "dd"). '/' ||

    TO_CHAR (add_months (trunc (DATE ' 2009-01-01', 'mm'), level - 1), "mm"). '/' ||

    TO_CHAR (add_months (trunc (DATE ' 2009-01-01', 'mm'), level - 1), 'yyyy'), "DD/MM/YYYY")

    END

    ) enddate

    OF the double

    CONNECT by trunc (DATE 2009-06 - 08 ',' dd') > = add_months (trunc (DATE 2009-01 - 01 ',' dd'), level - 1)

    )   )

    loop

    Dbms_output.put_line (TO_CHAR (rec.startdate, 'YYYYMMDD') |) '-' || To_char (rec.enddate, 'YYYYMMDD'));

    end loop;

    SY.

Maybe you are looking for