To loop through the table and use the values returned in another query

Hello

I tried to do something very simple, but still can not.

I am trying to iterate on a table and use each line of a column in a where clause to display a query clause.

For example:

I want to retrieve all users of dba_users pass it to a clause where clause in a query to show for example account_status and profile of each user. But I want to do it in a way if I can turn the result in an html table.

I tried too much really, so I'll post something that does not work, but which I think will show the problem I have,

BEGIN
 FOR i IN (SELECT username from dba_users order by 1)
 LOOP
 EXECUTE IMMEDIATE 'select account_status from dba_users where username like ''||i.username||''';
 END LOOP;
 END;
 /

Example of what I want to achieve:

Suppose that there are two users, SYS, and SCOTT:

USERNAME                       PROFILE                        ACCOUNT_STATUS
------------------------------ ------------------------------ --------------------------------
SYS                            DEFAULT                        OPEN


USERNAME                       PROFILE                        ACCOUNT_STATUS
------------------------------ ------------------------------ --------------------------------
SCOTT                            DEFAULT                        OPEN

Thanks in advance for your time,

OD

Hi Bill,

Bill Citad kirjoitti:

What a join or a sub query going to help me? honestly

-- join
select
  s.sql_id,
  h.loads_total
from dba_hist_sqlstat h join v$sql s on (
  h.sql_id = s.sql_id
)
where rownum < 3
;

-- subquery
select
  sql_id,
  loads_total
from dba_hist_sqlstat
where sql_id in (
  select sql_id from v$sql where rownum < 3
)
;

-- correlated subquery
select
  sql_id,
  loads_total
from dba_hist_sqlstat
where exists (
  select null from v$sql where sql_id = dba_hist_sqlstat.sql_id
)
and rownum < 3
;

-- lateral inline view (12c)
select
  s.sql_id,
  h.loads_total
from dba_hist_sqlstat, lateral(
  select sql_id from v$sql where sql_id = h.sql_id
) s
where rownum < 3
;

Tags: Database

Similar Questions

  • How to create a collection of apex to store and to loop through the values

    I couldn't find a simple example to do
    Apex 4.2

    I need to create a collection of the apex. I have a query that returns multiple roles for a user. I need to check to see if one of my values of point is within the collection, but I'm not sure how. So far, I have:

    Start
    APEX_COLLECTION. () CREATE_COLLECTION
    p_collection_name = > 'ALL_ROLES');

    Select count (granted_role) in the County of dba_role_privs where upper (grantee) = upper(:APP_USER);

    end;

    How would store the query results in the collection?

    Even shorter

    declare
      v_count number;
    begin
      if :P32_SUBMISSION_DATE is null
      then
        return false;
      end if;
      select count(*) into v_count
      from dba_role_privs
      where upper(grantee) = upper(:APP_USER)
      and  granted_role in ('SURVEY_SUID','SURVEY_JOB_SUID');
    --
      return v_count > 0;
    end;
    

    Note that with a combined function as count you will never get an exception no_data_found

  • How to loop through the values of token

    I am trying to create a simple loop that runs through a bunch of values delimited by commas in a string and add them up. What is the best way to do it?

    Currently, my code looks like this

    < cfset basevalue = "0" >
    < cfset count = "1" >
    < cfset token = getToken (myString, count, ",") >
    < cfloop condition = "token QNE NULL" >
    < cfset token = getToken (myString, count, ",") >
    < cfset basevalue = basevalue + token >
    < cfset count = count + 1 >
    < / cfloop >

    This doesn't seem to work. Any ideas?

    I think that the correct syntax is index = "token". If you have some other delimiter then,




    Thank you

  • I want to loop through the data from two different tables using for loop where the query should be replaced at runtime, please help me

    I have the data into two table with the structure of similar column, I want to loop through the data in these two tables

    based on some condition and runtime that I want to put the query in loop for example, the example is given, please help me

    create table ab (a number, b varchar2 (20));

    Insert into ab

    Select rownum, rownum. "" sample "

    of the double

    connect by level < = 10

    create table bc (a number, b varchar2 (20));

    Insert into BC.

    Select rownum + 1, rownum + 1 | "" sample "

    of the double

    connect by level < = 10

    declare

    l_statement varchar2 (2000);

    Boolean bool;

    Start

    bool: = true;

    If it is true, then

    l_statement: =' select * ab ';

    on the other

    l_statement: =' select * from bc';

    end if

    I'm in execute immediate l_statement - something like that, but I don't know

    loop

    dbms_output.put_line (i.a);

    end loop;

    end;

    Something like that, but this isn't a peace of the code work.

    Try this and adapt according to your needs:

    declare

    l_statement varchar2 (2000);

    c SYS_REFCURSOR;

    l_a number;

    l_b varchar2 (20);

    Boolean bool;

    Start

    bool: = true;

    If it is true, then

    l_statement: = "select a, b, AB;

    on the other

    l_statement: = "select a, b from bc;

    end if;

    --

    Open c for l_statement;

    --

    loop

    extract the c in l_a, l_b;

    When the output c % notfound;

    dbms_output.put_line (l_a |') -' || l_b);

    end loop;

    close c;

    end;

    /

  • loop through the layers defining the lock and visibility

    I need to loop through the layers in the active document and the value of the properties of the layer is false or true.  I tried to create a loop using a method 'for', but it doesn't seem to work. I have renounced the method 'for' because I kept running into a problem.  I have set all layers with these settings just the odd ones (2,4,6, etc.). Here is sample if it was written.

    myLayer = myDoc.layers var [2];

    myLayer.visible = false;

    myLayer.locked = true;

    myLayer = myDoc.layers var [4];

    myLayer.visible = false;

    myLayer.locked = true;

    myLayer = myDoc.layers var [6];

    myLayer.visible = false;

    myLayer.locked = true;

    myLayer = myDoc.layers var [8];

    myLayer.visible = false;

    myLayer.locked = true;

    I have 208 layers, so doing it this way would be way to long. Any help would be appreciated.

    Illustrator CC 2014 running.

    After I wrote this and tested, I saw that Carlos had already answered, but I thought that I would post it anyway. Carlos KNOWS how much I love JS... ;-)

    One difference is that, since it was not clear to me which layer you talk like layer #1, I started at the bottom of the scale.  I hope this helps.  -TT

    var aDoc = app.activeDocument;
    var lc = aDoc.layers.length;
    for (var i = 2; i <= lc; i+=2) {
        var curLayer = lc - i
        aDoc.layers[curLayer].visible = false;
        aDoc.layers[curLayer].locked = true;
    }
    
  • To loop through the array and check mouse events

    I have an array of objects. I want to continuously loop in the table and see if the user made a ROLL_OVER or click on one of these objects.

    I regularly did something similar where I loop in a table and look for collisions with a moving object (but who uses hitTestObject: see code below)

    Someone can help me please with how to do the same for the rollover, then click on?

    First of all, a little clean to make it more effective. It is best to declare variables once. If for you the current code I would as follows:

    var k: uint;
    var classRef_mybooth: Class;
    var MC_mybooth: *;
    for (k = 0; k< xmldata.booth_data.length();="" k++)="">
    class classRef_mybooth = getDefinitionByName(xmldata.booth_data[k].@asset);
    MC_mybooth = new classRef_mybooth ();
    MC_mybooth. Name=XMLDATA.booth_data[k].@name;
    MC_mybooth.x=XMLDATA.booth_data[k].@XPos;
    MC_mybooth.y=XMLDATA.booth_data[k].@yPos;
    MC_mybooth. Width=XMLDATA.booth_data[k].@XScale;
    MC_mybooth. Height=XMLDATA.booth_data[k].@yscale;
    MC_mybooth. Number=XMLDATA.booth_data[k].@number;
    boothArray.push (MC_mybooth);
    MC_booth_holder. AddChild (MC_mybooth);
    }

    Second, I guess that all classes whose names in XML are available for Flash (imported, etc.)

    Now, I add a listener that is unique to all of the objects and then do what I do with them based on the target of the event:

    inside the loop on each iteration:

    MC_mybooth.addEventListener (MouseEvent.ROLL_OVER, rollOverListener);

    Later:

    function rollOverListener(e:MouseEvent):void {}
    trace (e.Target.Name); or whatever the variables that you can use. Your target is the object that they roll.
    return;
    }

    Is this what you need?

  • Scripting inDesign: Loop through the layers

    I'm doing a script that will:

    To loop through all the layers in a document.

    Add the layers unlocked in table

    Loop in this table and glue them in place on each layer.

    I don't know how to loop through all the layers.

    Here is my script (I used? to represent where would the loop through all the part of layers):

    JavaScript document

    Set up a table to keep unlocked layers

    var layercollection = [];

    Browse layers and unlocked the layercollection table

    for (i = 0;? i ++) {}

    app.activeDocument.activeLayer = app.activeDocument.layers.itemByName (?);

    If (app.documents [0] .layers.) ([i]). Locked) == false;

    layercollection.push (Layers.itemByName ([i]))

    }

    Loop in table layercollection and paste in place

    for (i = 0; i < layercollection.length; i ++) {}

    app.activeDocument.activeLayer = app.activeDocument.layers.itemByName (tl [i]);

    app.pasteInPlace (); Dough

    }

    Can someone help me complete my script.

    Thank you!

    Did you test them all your solutions in a real world scenario?

    Theoretically, it should work this way (if one ignores that a layer is invisible, too), but even without the problem of invisible layers app.pasteInPlace () prefer to paste into the original layer, if the option "Paste remembers Layers" is checked.

    So I recommend you do the following:

    var oldPasteRem = app.clipboardPreferences.pasteRemembersLayers;
    //uncheck "Paste Remembers Layers"
    app.clipboardPreferences.pasteRemembersLayers = false;
    
    for (i = 0; i < app.activeDocument.layers.length; i++) {
    
        //Maybe the user does not want objects pasted to invisible layers:
        if(app.activeDocument.layers[i].visible == true && app.activeDocument.layers[i].locked == false) {
            app.activeDocument.activeLayer = app.activeDocument.layers[i];
            app.pasteInPlace();
        };
    };
    //Restore the old condition:
    app.clipboardPreferences.pasteRemembersLayers = oldPasteRem;
    

    Uwe

  • Loop through the list in flex 4 conclusion d buttons

    Anyone know how to completely recursively loops through the list in flex 4 by pulling the bodies of buttons.  This way I can apply my effects for buttons on the screen at the same time?

    You just create a subclass of button that has the desired effect and use it throughout your application.

    Gordon Smith

    Adobe Flex SDK team

  • loop through the list in flex 4

    I want to loop through the list and apply the following code to each button, the checkbox and the descent down in my application

    mouseOver = "animateHover ('theComponentID').

    How is that possible?

    Hello

    This should do what you want, you must add the eventlistener now your animated can be run from the th event handler.

    protected function button1_clickHandler(event:MouseEvent):void

    {

    for (var i: Number = 0; i<>

    {

    var obj:Object = this.getElementAt (i);

    If (flash.utils.getQualifiedClassName (obj) is 'spark.components::Button')

    {

    (obj as Button) .addEventListener (MouseEvent.MOUSE_OVER, onMouseOver);

    }

    If (flash.utils.getQualifiedClassName (obj) is 'spark.components::CheckBox')

    {

    (obj as CheckBox) .addEventListener (MouseEvent.MOUSE_OVER, onMouseOver);

    }

    }

    }

    private void onMouseOver(event:MouseEvent):void

    {

    animateHover (event.currentTarget);

    }

  • ÖAF - loop through a vo and get values of attribute associated with line

    HI people,

    I need code of the OPS to loop through a VO and retrieve the values of attribute associated with each line.

    I use following code in AM after - vo.invokeMethod ("initQuery", params, classes) - line.

    for (loop = 0 int; loop < vo.getRowCount (); loop ++) {}

    Line resultRow = vo.getCurrentRow ();

    If (resultRow! = null)

    System.out.println ("" + (String) resultRow.GetAttribute ("PARTYID"));

    }

    -resultRow - is done with the null value.

    Please share the code to achieve this.

    Thank you

    NGO

    You must call vo.next () to move to the next row, but this isn't a good method.

    You can browse the lines of the vo in two aspects.

    First one uses an iterator that is more reliable because it does not change the current line. You must create the java vo RowImpl file to do this.

    int fetchRowCount = vo.getFetchRowCount();
    voRowImpl row = null;
    if (fetchRowCount  > 0) {
        RowSetIterator iter = vo.createRowSetIterator("Iter");
            iter.setRangeStart(0);
            iter.setRangeSize(fetchBidderRowCount);
            for (int i = 0; i < fetchBidderRowCount; i++) {
                row = voRowImpl iter.getRowAtRangeIndex(i);
                 //use RowImpl getters
                 Number personId = row.getPersonId();
        }
        iter.closeRowSetIterator();
    }
    

    Second, one is your method proper form:

    for (Row row = rowsVo.first(); row != null; row = rowsVo.next()) {
         Number personId = (Number)row.getAttribute("PersonId");
    }
    

    Kind regards

    Anil.

  • To loop through a table

    Is it possible to write code that loops through a table in a form? I am currently writing separate sections of code for each row in a table of five rows to validate the data entries.

    Hello

    It would be easier if your table contained a line that repeats with an initial count of five (defined in the binding of the object palette tab).  This will change the XML that is generated, but assuming that it is not a problem your could loop so your table with the code;

    lines of the var = this.resolveNodes ("Table1.Row1 [*]");

    for (var i = 0; i)

    {

    currentRow var = rows.item (i);

    .

    .

    .

    }

    If you don't need the lines of uniquely named then go I and the result of "this.resolveNodes("Table1.Row"+i)" in a function.

    You back form... with only the first validation converted to the new approach.

    https://Acrobat.com/#d=akb0 * Ptvdr3KSYN0VP * 7zA

    Hope this gets you started.

    Concerning

    Bruce

  • nested loops pass the value

    Hello
    I have a small question:

    for v in c loop
    for v c1 loop
    AnyValue: = do some calc;
    end loop;
    end loop;

    How is it possible for me to get the value of AnyValue on both loops? So, how to pass this variable outside the loop?
    Thanks in advance.

    >
    END LOOP;
    v_test: = ANY_Value; -Get out of the loop on the inside of the loop
    >
    Assign the value once the ends of the loop will have access only the LAST value that was assigned in the loop. It is not clear if OP wants access to ALL values of the inside of the loop or only the last one.

  • I would like to summarize the values returned by a formula similar to the 'search', but for ranges or entire columns

    Thus,.

    I have three values in column K - 'A', 'B', 'C '. Column I is numeric values.

    I am trying to create a formula that selects all rows in the K column with a specfic value (in this case 'A' 'B' or 'C'), then grab the corresponding value (on the same line) of column I, then add up all the results for a total.

    IF rows in column K returns 'A', THEN take the VALUE of corresponding column I, and THEN SUM all the values returned.

    Or something like that.

    You can try something like this:

    The formula in B2, filled to the bottom, is:

    SUMIF (table 1::K, A2, table 1::L)

    SG

  • How to navigate to the next page based on the value returned by the method call inside the action attribute of the command key.

    How to navigate to the next page based on the value returned by the method call inside the action attribute of the command key.

    I use JDeveloper 12.1.2.0.0

    < af:button id = "tt_b2".

    rendered = "#{attrs.nextRendered} '"

    partialSubmit = 'true '.

    action = "#{attrs.backingBean.nextAction} '"

    Text = "next".

    Disabled = "#{attrs.nextDisabled}" / >

    private static final String NEXT_NAVIGATION_ACTION = "controllerContext.currentViewPort.taskFlowContext.trainModel.getNext";

    public String nextAction() {}

    If (validate()) {}

    updateModel();

    Return NEXT_NAVIGATION_ACTION;

    }

    Returns a null value.

    }

    Use case is made for model train, which is being implemented based on this blog: http://javacollectibles.blogspot.co.UK/2014/10/ADF-train-template.html

    We define a generic action following in the model, but the action must be called under certain conditions, based on the question of whether all validation controls had been passed on no.

    You can do this in two ways:

    1 returnValue = (String) ADFUtils.invokeEL("#{controllerContext.currentViewPort.taskFlowContext.trainModel.getNext}");

    return returnValue;

    2.

    public String getNextTrainStop() {}

    String nextStopAction = null;

    ControllerContext controllerContext = ControllerContext.getInstance ();

    ViewPortContext currentViewPortCtx = controllerContext.getCurrentViewPort ();

    TaskFlowContext taskFlowCtx = currentViewPortCtx.getTaskFlowContext ();

    TaskFlowTrainModel taskFlowTrainModel = taskFlowCtx.getTaskFlowTrainModel ();

    TaskFlowTrainStopModel currentStop = taskFlowTrainModel.getCurrentStop ();

    Terminus of TaskFlowTrainStopModel = taskFlowTrainModel.getNextStop (currentStop);

    nextStopAction = nextStop.getOutcome ();

    _logger.fine ("train, next stop:"+ nextStopAction ");

    Return nextStopAction;

    }

  • How can I retrieve all the values in a single query in the oracle XML

    Hi all

    I have xml format below, how do I retrieve all the values in a single query.

    < files >

    < job > MANAGER < / job >

    < details >

    < ename > JONES < / ename >

    < sal > 2975 < / sal >

    < ename > BLAKE < / ename >

    < sal > 2850 < / sal >

    < ename > CLARK < / ename >

    < sal > 2450 < / sal >

    < / details >

    < / documents >

    Thank you

    I prefer desgin a little more sophisticated xml and wrap the details in a separate label.

    Then you could something like that

    1 with testdata until)
    2. Select xmltype)
    3'
    4 MANAGER
    5


    6
    7 JONES
    8 2975
    9

    10
    11 BLAKE
    12 2850
    13

    14
    15 CLARK
    16 2450
    17

    18

    19
    20 ') in the form x
    21 double
    22)
    23 select
    24 j.job
    25, d.ename
    26, d.sal
    27 of testdata
    28 join
    29 xmltable ("Scriptures" in passing testdata.x)
    30 columns
    31 job varchar2 (30) path "job."
    32, details xmltype path «details»
    (33) j
    34 (1 = 1)
    left outer join 35
    36 xmltable (' details/emp' in passing j.details)
    37 columns
    path of varchar2 (30) 38 'ename' ename
    39, path of varchar2 (30) sal "sal".
    (40) d
    41 * (1 = 1)
    >/

    JOB                            ENAME                          SAL
    ------------------------------ ------------------------------ ----------
    JONES MANAGER 2975
    BLAKE MANAGER 2850
    MANAGER CLARK 2450

Maybe you are looking for

  • My drive HARD 160BG has been deleted and loads of files off itself

    HelloI had all my music and photos on my new hard drive, then one day they removed somehow themselves. Luckily I had backups of certain things, but not about this. When I copied stuff back it says you want to crush showing that files have been delete

  • Find the issue of my Mac

    Hello. I do not understand why my Mac find see my iMac, but is unable to see its location? + A sound was played on my iMac to my iPhone when I test the sound function. Please see the pictures on my preferences. PS: My iMac connected life ethernet no

  • How to recover files deleted in icloud

    How can I recover deleted emails icloud files?

  • R50E does not start after upgrading memory

    I tried to upgrade this laptop from the factory of 512 MB to 1.5 GB. I got a Kingston 1 GB DDR - 333 SO-DIMM, but after I installed it, the laptop does not turn. Only the power led is lit. I don't know why this happened, because all tests indicate th

  • HP8600 Server2003 shared printer will install in XP but not Win 7 profiles

    Printer is shared on a Windows Server 2003 box. The driver provided by the Web site does not work with Win 7 profiles, XP only. I found another issue even in the printer forum installation/configuration:here where a HP technician recommended to use t