PL/SQL loop to find the minimum value

I want to find the minimum value from a table using the pl/sql loop

I have data format below.

1 ABC 2

1 ABC 20

1 ABC 500

1 ABC 2000

XYZ 2 250

JKL 3 300

MNP 3 350

3 KLM 400

I wrote the code below. His does not work. Please suggest.

Set serveroutput on
declare
x number: = 3;
y VARCHAR2 (3): = 'ABC ';
fmin number: = 0;
number of Fmax: = 0;
Start
for rec in (select sal from test
where id = name and x = y) loop


If rec.sal > fmin then
fmin: = rec.sal;
on the other
FMAX: = rec.sal;
fmin: = fmax.
end if;
end loop;
dbms_output.put_line (Fmax);
end;
/

I want to output 2 on top of code.

Thanks in advance

Why PL/SQL? SELECT MIN (SAL) OF TEST will be more rapid and much less coding. In any case:

declare

number of v_min_sal;

Start

for v_rec in a loop (select sal from emp)

If nvl (v_min_sal, v_rec.sal + 1) > v_rec.sal

then

v_min_sal: = v_rec.sal;

end if;

end loop;

dbms_output.put_line (' lowest salaray is "' |") v_min_sal | '"');

end;

/

The lowest Salaray is "800".

PL/SQL procedure successfully completed.

SQL >

SY.

Tags: Database

Similar Questions

  • SQL - find the minimum value for each separate record...

    Hi all

    I have a table like this in SQL Server

    Date of sale of product
    A date
    A date
    A date
    B date of
    B date of
    C date
    C date
    C date

    I would like to write a query to find the minimum date (i.e. the date
    the first sale) for each product

    Thus, the expected results would be

    Date of sale of product
    A date min
    B date of min
    C date of min

    How can I do this using SQL Server?

    any help is greatly appreciated!

    Thank you!

    Product SELECTION, MIN (sale_date)
    From your_table
    GROUP BY product

    Etienne

  • Find the minimum value of the table in time...

    Firstly that it is not "find the min value in the table.

    It is:

    I have a table that changes its values at each iteration, and I want to compare the new values with previous values and make a new array with the minimum values...

    In C++, it would be like this:

    int main() {}

    int array [8];

    int min [8];

    int i;

    for (i = 0; i<>

    min [i] = 1000000; Initialize minimum table with a high value

    }

    {while (1)}

    Array = update_array ();

    for (i = 0; i<>

    If (array [i]<>

    min [i] = array [i];

    }

    }

    do things...

    }

    return 0;

    }

    IM new to labview and it always confuses me a lot...

    Thanks in advance.

    Using the function Max & Min regular (not table Max & min as you know) with tables and a good will of employment registry change.  Max Min &, as most of the digital functions, is polymorphic and works witt tables as well as scalars.

    Lynn

  • Find the minimum value in digital array that is greater than 0

    So far I have;

    $pfpp = min ($pflist);

    $pflist is the array of digital values and contains about 0.

    I need to change to $pfpp = min ($pflist); to return the lowest number which is greater than zero.

    I am stuck, can anyone help?

    Thank you

    Change the values in the table so I can't sort them in ascending order.

    Of course you can.  Or you can copy the table into a temporary array.

    $temp = $pflist;

    sort ($temp, SORT_NUMERIC)

    foreach ($temp as $value) {}

    If $value > 0; $number = $value; break;

    }

    echo "entry of zero smaller in pflist is $number";

  • SQL-MIN() don't not returns the minimum value

    This is my code;

    $SQLx = "SELECT MIN (price_from) AS minimumprice FROM AN_pricetable WHERE accomm_id =". "." $db_field ["accomm_id"];

    $resultx = mysql_query ($SQLx);

    $pricefrom = mysql_result ($resultx, $i, 'minimumprice');

    If ($pricefrom == 0) {}

    $pricefrom = 'TBC' ;}

    But for some reason, it is not the minimum value "price_from". For example, several rows in the table have the same "accomm_id", and their values in the field 'price_from' are: 8, 12, 50-7, but the SQL code returns the MIN 12. What I'm doing wrong here?

    Thank you

    What is the data type of price_from?  If it is a type of string (char), then 12 would be the lowest value.

  • Find the minimum date on multiple columns

    Hello

    I have two questions to find the minimum date on several columns:
    1. need a select query that should JOIN two tables and return any information (CASSEDTL) table with minimum date out of DATEISSUED, DATEPLACED, DATEENTERED and STATDATE.
    2. need of an update query that should update all cases in the CASEDTL table with the minimum date of DATEISSUED, DATEPLACED, DATEENTERED and STATDATE.

    The DDL:
    CREATE TABLE CASEMSTR 
    (   CASENBR     NUMBER,
        DATEISSUED  DATE,
        DATEPLACED  DATE,
        DATEENTERED DATE);
        
    CREATE TABLE CASEDTL 
    (   CASENBR     NUMBER,
        STATDATE    DATE,
        RCVDATE    DATE,
        MODDATE     DATE);
        
    INSERT INTO CASEMSTR VALUES (1, '1 JUL 2007', '1 JUL 2007', '12 JUL 2007');
    INSERT INTO CASEMSTR VALUES (2, '1 JAN 2008', '1 JAN 2008', '21 JAN 2008');
    INSERT INTO CASEMSTR VALUES (3, NULL, NULL, '3 DEC 2008');
    INSERT INTO CASEMSTR VALUES (4, '31 MAR 2009', NULL, '6 APR 2009');
    INSERT INTO CASEMSTR VALUES (5, NULL, '22 MAR 2009', '6 APR 2009');    
    INSERT INTO CASEMSTR VALUES (6, NULL, NULL, '16 JUL 2009');
    INSERT INTO CASEMSTR VALUES (7, '1 DEC 2008', '7 DEC 2008', '26 DEC 2008');
    INSERT INTO CASEMSTR VALUES (8, NULL, NULL, '17 MAY 2009');
    
    INSERT INTO CASEDTL VALUES (1, '25 JUN 2007', NULL, '2 AUG 2009');
    INSERT INTO CASEDTL VALUES (2, '1 JAN 2008', NULL, '2 AUG 2009');
    INSERT INTO CASEDTL VALUES (3, '11 NOV 2008', NULL, '2 AUG 2009');
    INSERT INTO CASEDTL VALUES (4, '31 MAR 2009', NULL, '2 AUG 2009');
    INSERT INTO CASEDTL VALUES (5, '19 JUL 2009', NULL, '2 AUG 2009');    
    INSERT INTO CASEDTL VALUES (6, '13 JUN 2009', NULL, '16 JUL 2009');
    INSERT INTO CASEDTL VALUES (7, '7 DEC 2008', NULL, '16 JUL 2009');
    INSERT INTO CASEDTL VALUES (8, '14 MAY 2009', NULL, '16 JUL 2009');
    COMMIT;
    The initial query I have is
    SELECT CD.CASENBR, CM.DATEISSUED, CM.DATEPLACED, CM.DATEENTERED, CD.STATDATE, CD.RCVDATE, NULL "NEW RCV DT" 
    FROM CASEDTL CD
        INNER JOIN CASEMSTR CM
            ON CD.CASENBR = CM.CASENBR;
    Need to know what is the best way to complete the new Date of RRS? Receive a new date should be the minimum date of DATEISSUED, DATEPLACED, DATEENTERED and STATDATE. And also how do I write an update statement unique to upade date of receipt in the detail table?

    Any help would be appreciated! Thanks in advance!

    Where is the function LESS? Refer to manual SQL.

    HTH - Mark D Powell.

    put1 > desc multdate
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     COL1                                               DATE
     COL2                                               DATE
     COL3                                               DATE
    
    put1 > select * from multdate;
    11-AUG-09 10-AUG-09 01-AUG-09
    
    put1 > select least(col1, col2, col3) from multdate;
    01-AUG-09
    

    Published by: MarkDPowell on August 11, 2009 15:53 added example

  • Take the minimum value for table data

    I'm storing test data in a table, with the hope that I can output the minimum value of the data. So far, I have used the table of max/min but can't make it work how I want. The test runs continuously in a loop of the holder. I get the minimum values in the table, but I would like to change the number of samples that the table contains, before it generates a minimum. The other option is that I run the test for a period of time (e.g. 3 seconds) and the table stores the data for this time then output 1 minimum value for the entire period.

    My current configuration VI is attached.

    Very appreciated

    Chris

    The size of the array in your VI is determined by the number of samples that you collect in your DAQ assistant, who is now 100 samples.  Never more, never less.

    How many samples do you want before you determine the minimum?

    Maybe what you really want to do is to build the table in the while loop and store it in a shift register, and when the loop has repeated enough times, then you take the minimum of built table.

  • Find the minimum distance between two SDO_GEOMETRY in Oracle Spatial?

    annular ring edit.png

    A circle (SDO_GEOMETRY)
    B - polygon (SDO_GEOMETRY)

    CASE:
    B contains A (or)
    The Interior of B.

    How to find the minimum distance between A and B in Oracle Spatial

    Hello guuid nameless person.

    What is

    my_answer := MDSYS.SDO_GEOM.SDO_DISTANCE(
       my_circle_geometry
      ,MDSYS.SDO_UTIL.POLYGONTOLINE(my_outer_polygon)
      ,my_tolerance
    );
    

    Now, you may need to pay attention to the holes in your polygon, would you the distance and an inner ring if it was closer to you?

    If the measure is only to outer rings, so something like

    my_answer := MDSYS.SDO_GEOM.SDO_DISTANCE(
       my_circle_geometry
      ,MDSYS.SDO_UTIL.POLYGONTOLINE(
          MDSYS.SDO_UTIL.EXTRACT(my_outer_polygon,1,1)
       )
      ,my_tolerance
    );
    

    And then also beware of the multipolygons as the foregoing only measured against the first polygon in the MultiPolygon.  You need to loop through the polygons of tests just the outer ring in this case.

    See you soon,.

    Paul

  • Problem with error ORA-06502: PL/SQL: numeric string or the error value

    Hello

    I use a loop for the coil just out of data using 'dbms_output.put_line' and I get this error after a few records. I've been using and it happens at a different interval. He would have to do with the length of the question, I am trying to spool? Thank you.

    ORA-06502: PL/SQL: numeric string or the error value

    SD wrote:
    Hello

    I use a loop for the coil just out of data using 'dbms_output.put_line' and I get this error after a few records. I've been using and it happens at a different interval. He would have to do with the length of the question, I am trying to spool? Thank you.

    ORA-06502: PL/SQL: numeric string or the error value

    Yes, it's a mistake to dependent data.

    Manage: SD
    Status level: Beginner
    Join date: November 21, 2001
    Messages total: 289
    Total Questions: 189 (183 pending)

    Why wasting you time here when you get rarely answers your questions?

  • How to find the ASCII value of the TAB?

    Hi friends,

    I'm trying to find the ASCII value of the TAB character using ASCII standard as:

    SELECT ASCII ('< TAB >') FROM DUAL;

    I'm running the command above in SQL * more.

    Is not treated as TAB.
    It is considered space and give the ASCII value of the space - 32.

    Please let me know how?

    Version of Database - 9i

    Concerning
    Anthony Alix.

    Its only editor that gives you the problem; Try it on TOAD or sql developer, it works perfectly.

    Is there a particular reason you want in sql * more?

  • Find the average value of a buffer

    Hello

    In my VI Panel, I have a digital control, a button and a digital display.

    When the user, enter a number in numerical order and press the button, the digital display should show the average value of all the past 5 values entered in the digital control, for example:

    1st entry: 10-online average = 10 (as sum = 10)

    2nd type: 0-online average = 5 (as sum = 10 + 0 = 10)

    3rd enter: 5-online average = 5 (you get the idea...)

    4 enter: 1-average online = 4

    5 enter: 14-online medium = 6

    6 enter: 2-online average = 4.4 (sum = 0 + 5 + 1 + 14 + 2 = 22, because the 1st value is thrown)

    How to write this VI?

    Thank you!!

    You can also use arrays to hold the data in a registry change and find the average value of the last five items.

    Good luck

  • What is the minimum value for the data type double?

    ... a more academic question: what is the minimum value of the data type double? I thought 'double', it is the 8-byte IEEE standard and what I remember, it's + - 1.7E + - 308.  The more different number of 0 should be 1.797E - 308.

    This is why I was a little surprised when I looked at the data output of my calculation of CVI, where I found the numbers with exponents of E-319 or E-324 as the smallest value...

    But I'm sure there's an explanation :-)

    Thank you for sharing with me,

    Wolfgang

    The largest number is indeed the order of + 1.7E + 308; There are a smaller number of - 1.7E + 308. Note that this is in fact the most negative number, which is the smallest by some reckoning. For the small beach of the Exhibitor, things get a little more complicated. 1E-308 can be represented with complete accuracy and resolution, but if you're willing to lose a few bits of precision, you can go down even further. For example:

    Double x, y, z:

    x = 1E-300;

    y = 1E7;

    z = x / y;               Give 1.000000000000000E - 307

    y = 1E8;

    z = x / y;               Give 9.999999999999999E - 309

    y = 1E18;

    z = x / y;               Give 9.999987484955998E - 319

    y = 1E23;

    z = x / y;               Give 9.881312916824931E - 324

    So, as you can see, values less than 1E-308 are possible, but they become increasingly more inaccurate and should not be relied upon.

    JR

  • Virtual Storage Manager - startTime does not meet the minimum value of 0 error

    Hello

    Someone at - it a fix for the problem in the region related to programming?

    When you attempt to add or change a schedule, we get the following error.

    Title: Too small
    Text: startTime does not meet the minimum value of 0

    What another user has said there US no customer impact and workaround has been to change the region of the computer you were using. I tried this and it doesn't work.

    This error is now a few years old.

    For anyone having this problem, add a parameter string regional en_US to the URL.

    For example .../vsphere-client/?locale=en_us

    Schedules can now be modified properly.

    Here's hoping for a permanent solution in the next major release.

  • SQL query to find the total number of source based nonsource passangersbetween source and destination station and passenger station on the same chekindate

    Hello

    SQL query to find the total number of source based nonsource passangersbetween source and destination station and passenger station on the same chekindate.

    Please help on this script and let me know if you need more details.

    ---

    You use a SELECT statement.  Let me know if you need more details.

  • Find the max value

    Hi team,

    I have the following query where I need to find the max value

    [code]

    with t as)

    Select 'L1' R_nm, R_Data 'Data', 'Obj' R_Obj, r_prec 'Wd', '2' double val

    Union of all the

    Select 'L1', 'Data', 'Obj', 'No', '4' double

    Union of all the

    Select 'L2', 'Data', 'Obj', 'No', '4' double)

    Select t.*, max (val) on rk (partition r_nm, r_data, r_obj) of t

    [/ code]

    My results should be

    [code]

    r_nm r_data r_obj r_prec rk val

    L1 Data Obj 1 2 Wd

    L1 data Obj 4 No.2

    L2 Data Yes 1 1 Obj

    [/ code]

    Thank you


    Hello

    It seems that you are not interested in the MAX at all.  Looks like you want to classify the lines, such as one that has the lowest value is assigned the number 1, the 2nd line with the lowest values gets 2,... and line with him gets N-th lowest value N.  If is not serious if the MAX is 4, 2 or 420.

    Here's a way to do it:

    SELECT T.*

    , RANK () OVER (PARTITION BY r_nm, r_obj)

    ORDER BY val

    ) AS rk

    T

    ORDER BY r_nm, r_obj

    val

    ;

    Depending on how you want to deal with links, you can use ROW_NUMBER or DENSE_RANK instead of RANK.

Maybe you are looking for