Unexpected result with select max (colmn) in anonymous block

Hello

The following query gives me 28 800 like sum (sal)
SELECT SUM(salary)
FROM employees 
    WHERE department_id =60
O/P is :  28800
But when I use the above query in anonymous block, it gives me 684400
DECLARE
 v_sum_sal NUMBER;
 department_id employees.department_id%TYPE := 60;
BEGIN
    dbms_output.put_line ('The department_id is'||department_id);
   SELECT SUM(salary)
      into v_sum_sal 
    FROM employees 
    WHERE department_id = department_id ;
   dbms_output.put_line ('The sum of sal is'||v_sum_sal);
END;
Exit instructions above gives me 684400 as output... But the grounds are 28800

You can me why the output differs block anonymous reference please

Hello

What about prefixing all your PL/SQL variables so that they do not match a column_name :

DECLARE
 v_sum_sal NUMBER;
 v_department_id employees.department_id%TYPE := 60;
BEGIN
    dbms_output.put_line ('The department_id is'||v_department_id);
   SELECT SUM(salary)
      into v_sum_sal
    FROM employees
    WHERE department_id = v_department_id ;
   dbms_output.put_line ('The sum of sal is'||v_sum_sal);
END;

Because, with the first names, where clause was equivalent to:

where 1=1

Tags: Database

Similar Questions

  • DAQmxReadAnalogF64 gives unexpected results with 9239 of Ni - DAQmx

    Hi all

    I use a NI 9239 with a laser sensor, and I would like to acquire some pressure readings of the probe which measures the height. It works very well with Ni Max, but not in C + c++ / MFC app I am developing. I get something that looks like amplidied noise:
    1 reading scale doesn't seem fair (pressure readings I get from range - 2E9 to 2E9)
    2 changes in what the sensor is supposed to measure does not appear in my measurements at all, there is nothing other than the noise (as if I were acquires bad chain - this I double checked)
    I would like to get the same result as in Ni Max, but may not know what wrong with my code (below).

    Thanks for your help,

    Ben

    DAQmx Configure Code
    DAQmxErrChk (DAQmxCreateTask ("LaserReading", & taskHandle));
    DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"cDAQ1Mod1/ai0","",DAQmx_Val_Diff,-10,10,DAQmx_Val_Volts,));
    DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,,10000,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,5000));

    Starting code DAQmx
    DAQmxErrChk (DAQmxStartTask (taskHandle));

    Reading DAQmx code
    DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,NUM,-1,DAQmx_Val_GroupByChannel,data,5000,&read,));

    TRACE sends the readings to the debug output

    TRACE ('%d points\n acquis', read);
    for (i = 0; i<5000;>
    {
    TRACE("%d\n",data[i]);
    }

    DAQmxStopTask (taskHandle);
    DAQmxClearTask (taskHandle);

    Found the answer to this problem, the problem was in the function TRACE which data acquired to the debugger output. %D %f for the float to TRACE("%f\n",data[i values changed]) - things are great now.

    Thank you

    Ben

  • Oracle 12 c - unexpected result with the insertion of the DBA_VIEWS view

    Hello

    I try inserting the DBA_VIEWS fields in a table belonging to a common C a PDB file ##SA user:

    (a) the PDB PDBORCL using user C ##SA connection:

    SQL * more: Production of liberation 12.1.0.1.0 kills him Sep 10 16:21:39 2013

    Copyright (c) 1982, 2013, Oracle.  All rights reserved.

    Enter the password:

    Last successful login time: kills Sep 10-2013 16:18:26 + 02:00

    Connected to:

    Database Oracle 12 c Enterprise Edition Release 12.1.0.1.0 - 64 bit Production

    With the options of partitioning, OLAP, advanced analytics and Real Application Testing

    C##SA@pdborcl 10.09.2013 > see the con_name

    CON_NAME

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

    PDBORCL

    C##SA@pdborcl 10.09.2013 > see the con_id

    CON_ID

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

    3

    (b) I create the table user SA_VIEWS_V

    C##SA@pdborcl 10.09.2013 > select count (*) in the dba_views;

    COUNT (*)

    ----------

    6220

    1 selected line.

    C##SA@pdborcl 10.09.2013 > create table sa_views_v (owner varchar2 (128), view_name varchar2 (128));

    Table created.

    (c) the insertion in the table SA_VIEWS_V gave me only 65 rows at the same time lines of content 6220 dba_views:

    C##SA@pdborcl 10.09.2013 > INSERT INTO SA_VIEWS_V (OWNER, VIEW_NAME) SELECT MASTER, VIEW_NAME DBA_VIEWS;

    65 lines were created.

    C##SA@pdborcl 10.09.2013 > commit;

    Validation complete.

    C##SA@pdborcl 10.09.2013 > SELECT MASTER, VIEW_NAME DBA_VIEWS;

    ...

    IX

    IX

    IX

    SH

    6220 selected lines.

    (d) you will find above the executed plan of the insert and the single select statement:

    C##SA@pdborcl 10.09.2013 > select * from table (dbms_xplan.display_cursor ('aj3vkggtvv9d9'));

    PLAN_TABLE_OUTPUT

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

    SQL_ID, aj3vkggtvv9d9, number of children 0

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

    INSERT INTO SA_VIEWS_V (OWNER, VIEW_NAME) SELECT VIEW_NAME, MASTER OF

    DBA_VIEWS

    Hash value of plan: 1585970530

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

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |

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

    |   0 | INSERT STATEMENT.                  |       |       |   136 (100) |          |

    |   1.  LOAD TABLE CLASSIC |                  |       |       |            |          |

    |*  2 |   FILTER                         |                  |       |       |            |          |

    |*  3 |    HASH JOIN |                  |    65.  6045.   136 (0) | 00:00:01 |

    |*  4 |     HASH JOIN |                  |    65.  4875.   132 (0) | 00:00:01 |

    |   5.      NESTED LOOPS |                  |       |       |            |          |

    |   6.       NESTED LOOPS |                  |    65.  3315 |   131 (0) | 00:00:01 |

    |   7.        INDEX SCAN FULL | I_VIEW1 |    65.   325.     1 (0) | 00:00:01 |

    |*  8 |        INDEX RANGE SCAN | I_OBJ1 |     1.       |     1 (0) | 00:00:01 |

    |   9.       TABLE ACCESS BY INDEX ROWID | OBJ$             |     1.    46.     2 (0) | 00:00:01 |

    |  10.      INDEX SCAN FULL | I_USER2 |   131.  3144 |     1 (0) | 00:00:01 |

    |  11.     TABLE ACCESS FULL | USER$ |   131.  2358.     4 (0) | 00:00:01 |

    | * 12 |    TABLE ACCESS FULL | USER_EDITIONING$ |     1.     6.     2 (0) | 00:00:01 |

    |  13.    SEMI NESTED LOOPS.                  |     1.    29.     2 (0) | 00:00:01 |

    | * 14 |     INDEX SKIP SCAN | I_USER2 |     1.    20.     1 (0) | 00:00:01 |

    | * 15 |     INDEX RANGE SCAN | I_OBJ4 |     1.     9.     1 (0) | 00:00:01 |

    | * 16.    TABLE ACCESS FULL | USER_EDITIONING$ |     1.     6.     2 (0) | 00:00:01 |

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

    Information of predicates (identified by the operation identity card):

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

    2 filter (((IS NULL AND "O". ("TYPE #" <>88) OR BITAND ("O". ("" FLAGS ", 1048576) = 1048576 OR

    BITAND ("U". "" SPARE1»(, 16) = 0 OR (((SYS_CONTEXT ('userenv', 'current_edition_name') = ' ORA$ BASE ", AND)))"

    "U"." TYPE #"(<>2) OR ('U'." ' TYPE # '= 2 AND 'U'. "SPARE2" = TO_NUMBER (SYS_CONTEXT ('userenv ',' current_e)) "

    dition_id'))) or IS NOT NULL) AND IS NOT NULL)))

    3 - access("O".") SPARE3 '=' U '. ("" USER # ")

    4 - access("O".") "OWNER # '=' U '. ("" USER # ")

    8 - access("O".") ' OBJ # '=' V '. (' ' OBJ # ")

    12 filter (("TYPE #" =: B1 ET "UE".)) "THE USER #" =:B2))

    14 - access("U2".") TYPE # "= 2, AND"U2"." SPARE2 "= TO_NUMBER (SYS_CONTEXT ('userenv ',' current_editi))"

    on_id')))

    filter (("U2". "TYPE #"= 2, AND "U2"."" SPARE2 "= TO_NUMBER (SYS_CONTEXT ('userenv ',' current_edit))"

    ion_id')))

    15 - access("O2".") DATAOBJ #"=: B1 AND 'O2'." ' TYPE # '= 88 AND 'O2'. "OWNER #"= "U2". ("" USER # ")

    16 filter ((' EU'. "TYPE #" =: B1 AND 'EU '. "THE USER #" =:B2))

    47 selected lines.

    C##SA@pdborcl 10.09.2013 > select * from table (dbms_xplan.display_cursor ('bc4f1jh1snwdp'));

    PLAN_TABLE_OUTPUT

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

    SQL_ID, bc4f1jh1snwdp, number of children 0

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

    SELECT THE OWNER, DBA_VIEWS NOM_DE_VUE

    Hash value of plan: 1508506130

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

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Pstart. Pstop |

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

    |   0 | SELECT STATEMENT |                  |       |       |     1 (100) |       |       |

    |   1.  PARTITION LIST ALL |                  | 10000 |  1289K |     0 (0) |     1.     2.

    |   2.   TABLE FIXED FULL | X$ COMVW$ 5885ef62 | 10000 |  1289K |     0 (0) |       |       |

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

    14 selected lines.

    You have an idea about this result?

    Thank you in advance,

    Arnaud.

    Arnaud,

    This has a fairly simple explanation.

    In 12cR1, there are common objects, and there are local objects. The definition of a common object is stored in the ROOT, and only a stub for the object is stored in the PDB. The definition of a local object is stored in the PDB.

    When DBA_VIEWS is questioned in a PDB file, so we must return to lines of views both as common as the result of the query. If views Commons are not returned, then several views that a client is used to see in the result of a query DBA_VIEWS to 11.2 and earlier versions not will be seen in paragraph 12.1. For example, ALL_TABLES, DBA_OBJECTS, etc.

    When DBA_VIEWS is questioned in a PDB file, then we extraction of lines for local opinions of PDB and common views of ROOT lines. The first has value ORIGIN_CON_ID equal to the ID of the container of the PDB to which you are connected, and they value ORIGIN_CON_ID equal to the ID of the ROOT container. Given that the recovery of these lines should be done in two different containers, we go through a fixed table X$ COMVW$ *.

    The gap that you are experiencing is because this fixed table based assessment is used only to SELECT and not for etc. SELECT, INSERT AS SELECT, CREATE TABLE AS.

    Let me know if that makes sense.

    Thank you

    Thomas

  • Unexpected result with Array.sort

    There seems to be a problem with the sort function when sorting the table contains several elements that are equal. I tried to illustrate this in the most simple form below:

    var test1:Array = ['a', 'b', 'this,' would be '];

    var test2:Array = [', 'c', 'b', 'a'];

    var test3:Array = ['a', 'b', 'c', ' a'];

    var test4:Array = ['a', ' a ',' b ', 'a'];

    trace (test1.sort (Array.RETURNINDEXEDARRAY)); Should be 0,1,2,3 (well!)

    trace (test2.sort (Array.RETURNINDEXEDARRAY)); Should be 3,2,1,0 (good!)

    trace (test3.sort (Array.RETURNINDEXEDARRAY)); Must be 0,2,3,1 (evil)

    trace (test4.sort (Array.RETURNINDEXEDARRAY)); Must be 0,1,3,2 (evil)

    / * Output

    0,1,2,3

    3,2,1,0

    3,0,1,2

    3,1,0,2

    */

    Can anyone find a reason of incompatibility, or is this a bug in the sorting method?

    test3: must be 0,3,1,2 or 3,0,1,2.  They are the same.

    test4: 0,1,3,2 is the same as 3,1,0,2 is the same as 1,0,3,2 is the same as 0,3,1,2 etc.  That is to say, as long as the index 2 is the last, they still.

    Oh, I see the problem.  you think flash is assign an index to the elements of the original array.

    It is not the case.  the method released the list of indices in the sort order.  IE, 0,3,1,2 means the original elements of 0th and 3rd tables are first and 2nd and the 1st element is the third and the 2nd element is the last.

    so, if you wanted to list the elements of original paintings using your sort order for test3, for example, you would use:

    test3 [0], test3 [3], test3 [1], test3 [2] and you expect, a, b, c

  • With the help of SELECT MAX (Substr (in a subquery to return specific lines

    Oracle v10

    Here is an example of a query and the output
    SELECT ID, SAMPLEID, COMPOUNDNAME, REQUISITION, SUBSTR(REQUISITION,2,4) FROM SEARCH PL1 WHERE SAMPLEID = 'IA 0005 0166';
    
    86907     IA 0005 0166     IA 0005     R2004:001160     2004
    98158     IA 0005 0166     IA 0005     R2005:000956     2005
    I try to return only the last line of data, in this case the line 2005.

    I tried
    SELECT ID, SAMPLEID, COMPOUNDNAME, REQUISITION, SUBSTR(REQUISITION,2,4) FROM SEARCH PL1 
    WHERE SAMPLEID = 'IA 0005 0166' AND
    REQUISITION IN 
    (SELECT MAX(SUBSTR(REQUISITION,2,4)) FROM SEARCH PL2 
    WHERE SUBSTR(PL2.REQUISITION,2,4) = SUBSTR(PL1.REQUISITION,2,4));
    But it returns no results. According to me, only missing me something simple.

    TIA

    You probably meant it?

    SELECT ID, SAMPLEID, COMPOUNDNAME, REQUISITION, SUBSTR(REQUISITION,2,4)
    FROM SEARCH PL1
    WHERE SAMPLEID = 'IA 0005 0166'
    AND SUBSTR(REQUISITION,2,4) = (
      SELECT MAX(SUBSTR(PL2.REQUISITION,2,4))
      FROM SEARCH PL2
      WHERE PL2.SAMPLE_ID = PL1.SAMPLE_ID
    );
    

    that could also be achieved with a single table access:

    SELECT id, sampleid, compoundname, requisition, sub_req
    FROM (
      SELECT id, sampleid, compoundname, requisition, substr(requisition,2,4) sub_req,
             row_number() over(order by substr(requisition,2,4) desc) rn
      FROM search PL1
      WHERE sampleid = 'IA 0005 0166'
    )
    WHERE rn = 1
    ;
    
  • Unexpected behavior with the Option "record in the result.

    Hello

    I have unexpected behavior with the Option "record in the result.

    I have a few steps in the subsequence 'X', this subsequence passes a Boolean parameter. According to the value of the parameter I change the "Recorgind results" Option to report it or not. The thing is that if 'result Recorgind' set at race time I modofy by changing the value of Step.ResultRecordingOption to "Enable" and "Disable", the step is not reported until the same sous-suite 'X' is called for the second time (without changing the parameter passed).

    For example: (Preconditon: result Recorgind Option of all value sous-suite x are defined as Disable)

    1 CallSubsequenceX(Parameter: Enable)

    2 CallSubsequenceX(Parameter: Enable)

    3 CallSubsequenceX(Parameter: Disable)

    4 CallSubsequenceX(Parameter: Disable)

    Expected result:

    1. measures have been reported.

    2. measures have been reported.

    3. measures have not been reported.

    4. measures have not been reported.

    Result:

    1. measures would not same value Step.ResultRecordingOption has been changed to 'enable '. (Not Ok)

    2. measures have been reported. (Ok)

    3. measures reported same value Step.ResultRecordingOption has been changed to 'disable '. (Not Ok)

    4. measures have not been reported. (Ok)

    I use TestStand 2013 (5.1.0.226)

    Thanks in advance.

    -Josymar.

    Hi josymar_guzman,

    I just review the sequence and indeed we´re experience unexpected behavior with the Step.ResultRecordingOption callback. By a reason when you run the callback in the expression before each step section, the statement runs only until the next sequence is called, which is not what we want.

    To avoid this, you can place a statement before each step of the sequence, so you can change the State of the Option "record result" for the sequence running (and it is only the following). You can try something like this

    where the expression of the statement will be the recall "RunState.NextStep.ResultRecordingOption is YourCondition". With this, we guarantee that the results of the next step will be saved or not. I also remove the expression in the expression prior to each step section, because the condition is now on the statement before each step.

    I tried and it works fine. I´ll set the sequence that you share with me, with the changes. I hope this will help you and solve your problem.

  • Select the rows with values max.

    SELECT MOFFER.DELIVERYPURCHASE,
      MOFFER.OFFERSTART,
      MOFFER.OFFEREND,
      MOFFER.RANKING,
      MMTDEMANDBID.BALANCEGROUPPK
    FROM EMTMOFFER MOFFER
    INNER JOIN MMTDEMANDBID ON MOFFER.OFFERID = MMTDEMANDBID.MMTDEMANDBIDPK
    WHERE MOFFER.DELIVERYPURCHASE = 'P'
    AND MOFFER.OFFERSTART        >= '2012-01-18T00:00:00'
    AND MOFFER.OFFEREND          <= '2012-01-19T00:00:00'
    AND MMTDEMANDBID.BALANCEGROUPPK = '10393'
    DELIVERYPURCHASE OFFERSTART          OFFEREND            RANKING                BALANCEGROUPPK         
    ---------------- ------------------- ------------------- ---------------------- ---------------------- 
    *P                2012-01-18T23:00:00 2012-01-19T00:00:00 2                      10393*                  
    P                2012-01-18T23:00:00 2012-01-19T00:00:00 3                      10393                  
    P                2012-01-18T00:00:00 2012-01-18T01:00:00 2                      10393                  
    P                2012-01-18T01:00:00 2012-01-18T02:00:00 2                      10393           
    *P                2012-01-18T02:00:00 2012-01-18T03:00:00 1                      10393*         
    P                2012-01-18T02:00:00 2012-01-18T03:00:00 2                      10393                  
    P                2012-01-18T03:00:00 2012-01-18T04:00:00 2                      10393                  
    P                2012-01-18T04:00:00 2012-01-18T05:00:00 2                      10393                  
    *P                2012-01-18T05:00:00 2012-01-18T06:00:00 1                      10393*
    P                2012-01-18T05:00:00 2012-01-18T06:00:00 2                      10393                  
    P                2012-01-18T06:00:00 2012-01-18T07:00:00 2                      10393                  
    P                2012-01-18T07:00:00 2012-01-18T08:00:00 2                      10393                  
    P                2012-01-18T08:00:00 2012-01-18T09:00:00 2                      10393                  
    P                2012-01-18T09:00:00 2012-01-18T10:00:00 2                      10393                  
    P                2012-01-18T10:00:00 2012-01-18T11:00:00 2                      10393                  
    P                2012-01-18T11:00:00 2012-01-18T12:00:00 2                      10393                  
    P                2012-01-18T12:00:00 2012-01-18T13:00:00 1                      10393                  
    P                2012-01-18T13:00:00 2012-01-18T14:00:00 1                      10393                  
    P                2012-01-18T14:00:00 2012-01-18T15:00:00 1                      10393                  
    P                2012-01-18T15:00:00 2012-01-18T16:00:00 2                      10393                  
    P                2012-01-18T16:00:00 2012-01-18T17:00:00 2                      10393                  
    P                2012-01-18T17:00:00 2012-01-18T18:00:00 2                      10393                  
    P                2012-01-18T18:00:00 2012-01-18T19:00:00 2                      10393                  
    P                2012-01-18T19:00:00 2012-01-18T20:00:00 2                      10393                  
    P                2012-01-18T20:00:00 2012-01-18T21:00:00 2                      10393                  
    P                2012-01-18T21:00:00 2012-01-18T22:00:00 2                      10393                  
    P                2012-01-18T22:00:00 2012-01-18T23:00:00 2                      10393                  
     27 rows selected 
    Help, please. How to select lines with RANKING max, OFFERSTART and OFFEREND if the same.
    Get 24 ranks. One for every hour.

    SELECT MOFFER. DELIVERYPURCHASE,
    MOFFER. OFFERSTART,
    MOFFER. OFFEREND,
    Max (MOFFER. (Rank CLASSIFICATION),
    MMTDEMANDBID. BALANCEGROUPPK
    OF EMTMOFFER MOFFER
    INNER JOIN MMTDEMANDBID ON MOFFER. OFFERID = MMTDEMANDBID. MMTDEMANDBIDPK
    WHERE MOFFER. DELIVERYPURCHASE = 'P '.
    AND MOFFER. OFFERSTART > = ' 2012 - 01-18T 00: 00:00'
    AND MOFFER. OFFEREND<=>
    AND MMTDEMANDBID. BALANCEGROUPPK = '10393'
    Group of MMTDEMANDBID. BALANCEGROUPPK, deliverypurchase, offerstart, offerend

  • Anonymous block with Variable and SELECT

    Hi guys,.
    I'm fighting to connect the material that I am learning. I read on the anonymous blocks and variable so I want to write a
    Nice and neat select with all the fancy stuff (variables, exceptions) to get it right and what I read in the book.

    DECLARE
    MYSTRING AS VARCHAR (10);
    MYSTIRNG: = 'X '.
    BEGIN
    SELECT * FROM DUAL WHERE DUMMY = MYSTRING
    END;


    but... This causes an error after another. I get the wrong concept here or is this a syntax error?

    PL/SQL, you will need to use SELECT... IN...
    http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14261/sqloperations.htm#sthref1348

    SQL> declare
      2    mystring varchar(10) := 'X';
      3    myvar varchar(10);
      4  begin
      5    select dummy into myvar
      6    from   dual
      7    where  dummy = mystring;
      8    dbms_output.put_line(myvar);
      9  end;
     10  /
    X
    
    PL/SQL procedure successfully completed.
    
  • Update statement Select MAX

    Hello guys, small head scratcher here (probably just my mind head)

    Summary of the issue: Updated between two tables, try to use the rank, will not work.

    I took a few of the fields of interest here: -.
    CREATE TABLE spell_tags (
          Spell_ID             varchar2(50) ,
          service_line_spell     varchar2(25) );
    CREATE TABLE ranked_spells(
         spell_ID varchar2(10) ,
         dominant_SSNDS varchar2(25) ,
         service_line varchar2(25) ,
         Rank varchar2(3) NOT NULL ) ;
    Samples: -.
    INSERT INTO RANKED_SPELLS ("SPELL_ID" ,"DOMINANT_SSNDS" ,"SERVICE_LINE" ,"RANK" ) VALUES ('100002' ,'08' ,'SD08o' ,'213' );
    INSERT INTO RANKED_SPELLS ("SPELL_ID" ,"DOMINANT_SSNDS" ,"SERVICE_LINE" ,"RANK" ) VALUES ('100002' ,'08' ,'SD08s' ,'210' );
    INSERT INTO RANKED_SPELLS ("SPELL_ID" ,"DOMINANT_SSNDS" ,"SERVICE_LINE" ,"RANK" ) VALUES ('100003' ,'08' ,'SD22m' ,'416' );
    INSERT INTO RANKED_SPELLS ("SPELL_ID" ,"DOMINANT_SSNDS" ,"SERVICE_LINE" ,"RANK" ) VALUES ('100003' ,'08' ,'SD23x' ,'207' );
    INSERT INTO SPELL_TAGS ("SPELL_ID" , "SERVICE_LINE_SPELL"  ) VALUES ('100002' ,'' );
    INSERT INTO SPELL_TAGS ("SPELL_ID" , "SERVICE_LINE_SPELL"  ) VALUES ('100003' ,'' );
    Data looks like this: -.
     Select * from spell_tags;
    
    SPELL_ID                                           SERVICE_LINE_SPELL
    -------------------------------------------------- -------------------------
    100002
    100003
    
    2 rows selected.
    
    
     Select * from ranked_spells;
    
    
    SPELL_ID   DOMINANT_SSNDS            SERVICE_LINE              RANK
    ---------- ------------------------- ------------------------- ---
    100002     08                        SD08o                     213
    100002     08                        SD08s                     210
    100003     08                        SD22m                     416
    100003     08                        SD23x                     207
    
    4 rows selected.
    Basically, I need to run and update the declaration (not plsql) to update the Spell_tags table service_line_spell field with the service_line of the ranked_spells table (lowest rank)

    Here are a few failed attempts, do not laugh ;)
    update spell_tags
    set service_line_spell = (select max(service_line) from ranked_spells
    where spell_tags.spell_id = ranked_spells.spell_ID
    group by service_line, rank
    having rank = min(rank))
    where spell_ID in (select distinct spell_ID from ranked_spells);
    
    ERROR at line 2:
    ORA-01427: single-row subquery returns more than one row
    
    
    update speccom.spell_tags
    set service_line_spell = (select b.service_line from ranked_spell b
    where spell_tags.spell_id = ranked_spells.spell_ID
    and ranked_spells.rank = min(ranked_spells.rank) group by service_line, rank)
    where exists
    (select spell_ID from ranked_spells
    where spell_ID in (select distinct spell_ID from ranked_spells);
    
    ERROR at line 4:
    ORA-00934: group function is not allowed here
    This is the result, I need: -.
     Select * from spell_tags;
    
    SPELL_ID                                           SERVICE_LINE_SPELL
    -------------------------------------------------- -------------------------
    100002                                             SD08s
    100003                                               SD23x
    Any ideas guys?

    Something like that?

    update spell_tags
    set service_line_spell = (select max(service_line) keep (dense_rank last order by rank desc)
                              from ranked_spells
                              where spell_tags.spell_id = ranked_spells.spell_ID
                              )
    where spell_ID in (select distinct spell_ID from ranked_spells);
    

    Published by: UW (Germany) on 16.08.2012 16:48 (changed min at the maximum, but it makes only a difference when there is same ranking values)

  • GROUP BY with HAVE (MAX)

    The SELECT statement with the GROUP BY clause shows the incomplete result.

    The result of this query should display only the Group of the automaker, which shows the maximum hourly way (DFC).

    How should the clause be here?



    SELECT type, AVG (c_h) DFC

    GROUP BY type

    HAVING?


    The result is:

    TYP DFC     
    5000 MG
    Jaguar 7000
    Triumph 9000



    Thank you very much in advance for the help.

    Edited by: user3227321 14.08.2010 11:55

    You need to address as below

    having avg (c_h) = (select max (avg(c_h))
                               from tabname
                               group by typ)
    

    You can also use as below in your sql

    with c as
    (
    SELECT typ, AVG (c_h) DFC
    GROUP BY typ
    )
    select typ,dfc
    from c
    where dfc = (select max(dfc)
                       from c)
    

    Try it!

  • Select max (length) - how to display the length of a group MAX

    Hello

    I have a table with the name of DVD and names of files on the DVD.
    I would like to know how to change this query to get another column, MAX_LENGHT, the MAXIMUM length of the name of FILE to a DVD of return
    This doesn't work request
    select DVD, FILENAME, (SELECT max(length(FILENAME)) / 2 + 4 FROM TABLE) AS MAX_LENGHT from TABLE
    DESIRED RESULT
    DVD    FILENAME     MAX LENGHT
    DVD1     Alina     8
    DVD1     Aidan     8
    DVD1     Aiden     8
    DVD1     Akira     8
    DVD1     Alex     8
    DVD1     Alyssa     8
    DVD1     Arianna     8
    DVD1     Ashley     8
    DVD1     Ava     8
    DVD1     Benjamin8
    DVD1     Bianca     8
    DVD1     Blake     8
    DVD1     Brandon     8
    DVD1     Brayden     8
    DVD1     Brayden     8
    DVD1     Brianna     8
    DVD1     Brielle     8
    DVD1     Brooklyn8
    DVD2     Dakota     11
    DVD2     Dalia     11
    DVD2     Daniel     11
    DVD2     Dante     11
    DVD2     David     11
    DVD2     Diego     11
    DVD2     Dingbang11
    DVD2     Dominic     11
    DVD2     Dylan     11
    DVD2     Chase     11
    DVD2     Chloe     11
    DVD2     Christopher     11
    DVD2     Claire     11
    DVD2     Cole     11
    DVD2     Connor     11
    Thank you

    Roseline

    You can use the analytic version of the function max:

    SELECT  DVD
    ,       FILENAME
    ,       MAX(LENGTH(FILENAME)) OVER (PARTITION BY DVD) AS MAX_LENGTH
    FROM    TABLE
    
  • HELP! : SELECT &amp; MAX

    I had a few difficulties to do a sql query.

    Table 1: Master

    2 columns: name, Contact_ID
    Name1, contact_id_1
    name 2, contact_id_2
    name 3, contact_id_3

    ...

    Table 2: details
    2 columns: Version Contact_id, address,.
    contact_id_1, address_a, 1
    contact_id_1, address_b, 2
    contact_id_2, address_c, 1
    contact_id_2, address_d, 2
    contact_id_2, address_e, 3
    contact_id_3, address_f, 1
    ......

    Question I have:

    How can I make a query showing the list of names with the address with the latest version?

    Result: I'm looking:

    Name1, address_b
    name 2, address_e
    name 3, address_f
    .......

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

    Thank you very much for the help in advance!
    with master as
    (
      select 'name1' as name, 'contact_id_1' as contact_id from dual union all
      select 'name2' as name, 'contact_id_2' as contact_id from dual union all
      select 'name3' as name, 'contact_id_3' as contact_id from dual
    ),
    detail as
    (
      select 'contact_id_1' as contact_id, 'address_a' as address, 1 as version from dual union all
      select 'contact_id_1' as contact_id, 'address_b' as address, 2 as version from dual union all
      select 'contact_id_2' as contact_id, 'address_c' as address, 1 as version from dual union all
      select 'contact_id_2' as contact_id, 'address_d' as address, 2 as version from dual union all
      select 'contact_id_2' as contact_id, 'address_e' as address, 3 as version from dual union all
      select 'contact_id_3' as contact_id, 'address_f' as address, 1 as version from dual
    )
    --
    -- end of test data, query is below
    --
    select m.name,
           d.address
    from   master m,
           detail d
    where  m.contact_id = d.contact_id
    and    d.version = (select max(version) from detail d2 where d2.contact_id = d.contact_id)
    /
    
    NAME  ADDRESS
    ----- ---------
    name1 address_b
    name2 address_e
    name3 address_f 
    
    3 rows selected
    

    Published by: Cyn on December 17, 2009 16:39

  • When I subtract two numbers DBL and try to compare the result with another DBL, it fails

    I found a curious problem with subtraction and compare numbers DBL in LabVIEW (8.6). Here's how it works:

    1. subtract two numbers DBL such that the result is not incorporated. (Say, 3.2 - 3.1)

    2. compare the result with a constant/control that is on the result of the subtraction (in the example, 0.1)

    3 see the output of the comparison.

    If the result of the subtraction is an integer, the Boolean result is (as expected). If the result is not complete, the comparison fails.

    (Now, if I simply compare two floating point numbers, it works, so the issue is not with the node comparison itself, but with the data that is entered to the node). Can someone understand why this happens? It's unexpected, it's a pretty serious bug.

    It is provided with all programming languages. Numbers do not have an exact binary floating-point representation. This has been discussed endlessly. Never use the equal function with floats. You can use the function in the range and force.

  • Computer started to delay the result with a click of a button, etc. by seveal seconds.

    Have aw computer laptop Dell Inspiron 1501 XP SP3. Computer started to delay the result with a click of a button, etc. by seveal seconds.  A ran the anti-virus, malware search, keylogers search and found nothing.  The delay also occurs when you use an application such as CorelDRAW, Word, WordPerfect programs, etc.  any ideas what is happening or where to look? Thank you.

    You experience this delay all the time, or they occur from time to time?

    Could complete you the following procedure to obtain information about your current system and post here, so I can be more specific in suggestions.
    0 close the programs as open as you can before the first step.
    1 copy the following line below exactly as it appears:
    Taskpad cmd /C /V > tempo & tempo notebook
    2. press on + R
    3. paste copied line run window and press enter or click Ok.
    4 copy all the information from the Notepad window. (The list can be long, you can use + a combination to select all)
    5 paste info copied to the next reply.
    6. after that you can close the Notepad window.

  • Tabular with nvl (max (col), 0) + 1

    Hi all

    I have a table block, I want to generate sequence for the key item numbers primary with nvl (max (col), 0) + 1

    I wrote this in a w-n-r-i trigger:

    "LAST_RECORD;

    SELECT NVL (MAX (ALERT_ID), 0) + 1 ON: EX_ALERT_SETUP. ALERT_ID EX_ALERT_SETUP; "

    but when I enter a new record with the cursor, it also gets the '1', body I have not saved the first '1 ',.

    How to deal with this situation?

    Thank you

    ORA-01400 wrote:

    Hi all

    I have a table block, I want to generate sequence for the key item numbers primary with nvl (max (col), 0) + 1

    I wrote this in a w-n-r-i trigger:

    "LAST_RECORD;

    SELECT NVL (MAX (ALERT_ID), 0) + 1 ON: EX_ALERT_SETUP. ALERT_ID EX_ALERT_SETUP; "

    but when I enter a new record with the cursor, it also gets the '1', body I have not saved the first '1 ',.

    How to deal with this situation?

    Thank you

    If it's a bad design, simply change the trigger as before Insert at the block level. Sequences of database is suggested.

    Hope this helps

    Hamid

Maybe you are looking for

  • When I try to sync, I get a message that I need to update iTunes.

    When I try to sync, I get a message that I need to update iTunes. I used this button on iTunes 11.4 since it was bought, then today he refused to sync. I deleted and restored, which erased all the data and my music. I always get the same message, but

  • Network during the passage of the users problem

    Hello, when I change users on a Windows XP computer, wireless stops working. To stop this problem, I have to restart my computer. After I change user once again, the problem recurs. Any suggestions would help! Thank you!

  • SPA942 flipping to the next line

    I install several SPA942s on a SPA9000 PBX to our Church.  The SPA9000 is connected to a SPA400 with 4 incoming lines.  Each phone has an extension with the same extension showing all the appearance of the line.  I expect that when a line is busy wit

  • 1813 and 1053 Printer Spooler error... I can't print

    Help me! I bought a new dell inspiron 1545 in December and a new printer Dellp713w after Christmas. I was able to print until this week (April 1) and now I get the 1813 and 1053 error when I go to start my spooler.That's happened? I ran the scan from

  • BlackBerry Smartphones Disney Bedtime stories ringtone?

    Good day to all! I was wondering if someone took the new movie with Adam Sandler "Bedtime Stories"?  There is a unpleasant ringtone on his cell phone "RING RING" real strong and funny... It kind of sounds like the Aflac bird!  Anyone know where I cou