Why Scalar Subquery expression cannot be used in HAVING clauses?

Hi All,
I'm new to SQL. I'm confused with Scalar Subquery.
Is there anyone who can answer me why Scalar Subquery expression cannot be used in HAVING clauses.
Can you show me a example?
Thanks very much,
Xianyi.Ye
Edited by: 908428 on 2012-1-16 下午7:24

Hi,
908428 wrote:
Hi Frank,
Thank you for your quick reply. I also agree with your point.
But when I read the book, "OCA Oracle Database SQL Certified Expert Exam Guide",( link to illegal copies of book removed by moderator )
on Page 359, it said that
Scalar subquery expressions cannot be used in the following locations:
1. In CHECK constraints
2. In GROUP BY clauses
3. In HAVING clauses
4. In a function-based index (which is coming up in Chapter 11)
5. As a DEFAULT value for a column
6. In the RETURNING clause of any DML statement
7. In the WHEN conditions of CASE
8. In the START WITH and CONNECT BY clauses, which we discuss in
Chapter 16.7 and 8 are wrong. Scalar sub-queries can be used in WHEN conditions and START WITH and CONNECT BY clauses. (At least in Oracle 10.2. Is the book based on some earlier version?)
Edited by: BluShadow on 17-Jan-2012 09:08

Similar Messages

  • Why my credit card cannot be used in iTunes?

    Why my credit card cannot be used in iTunes?

    Very vague question
    No way for anyone here to know

  • PLS-00363: expression cannot be used as an assignment target

    Hi,
    Oralce9.2
    when I run the insert procedure I get the below error:
    Procedure
    PROCEDURE proc_one_insert(col1 IN OUT numeric,
    col2           IN num,
    col3     IN numeric
    BEGIN
    execute immediate proc_one_insert(2,1,111);
    END;
    Error
    PLS-00363: expression '2' cannot be used as an assignment target
    How to solve the above error ?
    With Regards
    Edited by: user640001 on Dec 2, 2010 3:04 AM

    Arun has shown you an example using PL/SQL. If you want to do something similar in other languages you have to use their style of variable declaration e.g. if you wanted to do it through SQL*Plus, you need to declare the variable within SQL*Plus itself and bind that into your calls e.g.
    SQL> create procedure p_inout (p_val in out number) is
      2  begin
      3    p_val := p_val*10;
      4  end;
      5  /
    Procedure created.
    SQL> var mynum number
    SQL> exec :mynum := 10;
    PL/SQL procedure successfully completed.
    SQL> print mynum
         MYNUM
            10
    SQL> exec p_inout(:mynum);
    PL/SQL procedure successfully completed.
    SQL> print mynum
         MYNUM
           100
    SQL>

  • PLS-00363: expression '' cannot be used as an assignment target - HELP :-(

    Hi Guys,
    This is a procedure I have in the body of a package:
    PROCEDURE SUM_EVENTS (p_trial_no IN NUMBER,
                                  p_country_resion IN VARCHAR2,
                                  p_loc_no IN NUMBER,
                                  p_setup_flag IN VARCHAR2,
                                  p_event_changed IN OUT NUMBER) ISWhen I call this in SQLplus with this:
    exec DB_CALC.sum_events(340,'USA',1,'Y',3700);I get this:
    ERROR at line 1:
    ORA-06550: line 1, column 54:
    PLS-00363: expression '3700' cannot be used as an assignment target
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignoredAny ideas what I'm doing wrong?
    Thanks!

    p_event_changed is declared as an IN OUT parameter. You need to provide a variable in which the OUT values can be written to..
    something like
    declare
    out_val number := 3700;
    begin
    DB_CALC.sum_events(340,'USA',1,'Y',out_val);
    end;

  • Expression   cannot be used as an INTO-target of a SESELECT/FETCH Statement

    Hello guys
    Iam new to oracle and this my first post
    I have written this code in sql
    declare
    2 cursor madecursor is select bus_id ,bus_destination ,seat_no ,
    3 driver_name from bus for update of seat_no nowait ; myseat bus.seat_no%type
    4 ; begin
    5 for bus_id in madecursor loop
    6 select myseat into bus.bus_id from bus where
    7 bus_id = bus_id
    8 ; if
    9 myseat < 5 then
    10 update bus set seat_no = seat_no*2 WHERE CURRENT OF madecursor
    11 ; DBMS_OUTPUT.PUT_LINE('Updated');
    12 end if ;
    13 end loop;
    14 end;
    but I have the following errors:-
    ERROR at line 6:
    ORA-06550: line 6, column 27:
    PLS-00403: expression 'BUS.BUS_ID' cannot be used as an INTO-target of a SELECT/FETCH statement
    ORA-06550: line 6, column 2:
    PL/SQL: SQL Statement ignored
    please help me.
    Thanks in advance.
    user613283

    Firstly thank you for replies , I get use of your suggestions and change my code but still having errors please suggest.
    SQL> declare
    2 I_myseat bus.seat_no%type;
    3 begin
    4
    5
    6 select I_myseat into I_myseat from
    7 bus where
    8 bus_id = bus.bus_id
    9 ;
    10 if I_myseat < 5 then
    11 update bus set seat_no = seat_no*2
    12 where I_myseat<5
    13 ; DBMS_OUTPUT.PUT_LINE('Updated');
    14
    15 end if;
    16 end;
    17 / declare
    ERROR at line 1:
    ORA-01422: exact fetch returns more than requested number of rows
    ORA-06512: at line 6

  • Problems mac os x 10.6.8  system extension cannot be used, am having prob mac os x 10.6.8  system extension cannot be used

    today  i tried to  install new software  when suddenly appear this message    and said  it needed to be reinstall  or call for  support    and  since i got this new version   i  play  videos on internet   and  suddenly only the screen of the video becomes black  i need to restart the cumputer and  then it start working  again  it happens like twice every two days  or  it doesn't  really need  help with  it   
    i will apreciate it

    You can use this as a starting point.
    Go to applications/utilities/disk utility, select your volume (default name is Macintosh HD) and click repair permissions. Reboot.
    If you are refering to watching You Tube videos (I believe english is not your first language, so I am guessing here)
    You may have a out dated version of Adobe Flash.
    to fix this, uninstall flash:
    http://helpx.adobe.com/flash-player/kb/uninstall-flash-player-mac-os.html
    Then reinstall the latest version 11.9.900.117
    http://get.adobe.com/flashplayer/otherversions/

  • Objects containing objects.Expr cannot be used as an assignment.PLS-00363.

    Hi,
    My database: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0.
    I'm working with Object types containing other object types, and I'm getting the error PLS-00363 (Expression cannot be used as an assignment).
    I'm putting exlpicity all 'SELF' parameters as 'IN OUT', but still get the error...
    CREATE OR REPLACE TYPE TYP_PERSON AS OBJECT (
    strName VARCHAR2(100),
    --+
    CONSTRUCTOR FUNCTION TYP_PERSON RETURN SELF AS RESULT,
    --+
    MEMBER      FUNCTION getName (SELF IN OUT TYP_PERSON) RETURN VARCHAR2,
    MEMBER     PROCEDURE setName (SELF IN OUT TYP_PERSON, pNewName VARCHAR2)
    +) NOT FINAL;+
    +/+
    --+
    CREATE OR REPLACE TYPE BODY TYP_PERSON AS
    --+
    CONSTRUCTOR FUNCTION TYP_PERSON RETURN SELF AS RESULT IS
    BEGIN
    SELF.strName := NULL;
    RETURN;
    END;
    --+
    MEMBER      FUNCTION getName (SELF IN OUT TYP_PERSON) RETURN VARCHAR2 IS
    BEGIN
    RETURN SELF.strName;
    END;
    --+
    MEMBER     PROCEDURE setName (SELF IN OUT TYP_PERSON, pNewName VARCHAR2) IS
    BEGIN
    SELF.strName := pNewName;
    END;
    END;
    +/+
    --+
    CREATE OR REPLACE TYPE TYP_PERSONS AS TABLE OF TYP_PERSON;
    --+
    CREATE OR REPLACE TYPE TYP_CREW AS OBJECT (
    strName VARCHAR2(100),
    persons TYP_PERSONS,
    --+
    CONSTRUCTOR FUNCTION TYP_CREW RETURN SELF AS RESULT,
    --+
    MEMBER      FUNCTION getName    (SELF IN OUT TYP_CREW) RETURN VARCHAR2,
    MEMBER     PROCEDURE setName    (SELF IN OUT TYP_CREW, pNewName VARCHAR2),
    --+
    MEMBER     PROCEDURE addPerson  (SELF IN OUT TYP_CREW, pPersonName IN VARCHAR2),
    MEMBER      FUNCTION getPerson  (SELF IN OUT TYP_CREW, pIndex IN NUMBER) RETURN TYP_PERSON,
    MEMBER      FUNCTION getPersons (SELF IN OUT TYP_CREW) RETURN TYP_PERSONS
    +) NOT FINAL;+
    +/+
    --+
    CREATE OR REPLACE TYPE BODY TYP_CREW AS
    --+
    CONSTRUCTOR FUNCTION TYP_CREW RETURN SELF AS RESULT IS
    BEGIN
    SELF.strName := NULL;
    SELF.persons := TYP_PERSONS();
    RETURN;
    END;
    --+
    MEMBER      FUNCTION getName (SELF IN OUT TYP_CREW) RETURN VARCHAR2 IS
    BEGIN
    RETURN SELF.strName;
    END;
    --+
    MEMBER     PROCEDURE setName (SELF IN OUT TYP_CREW, pNewName VARCHAR2) IS
    BEGIN
    SELF.strName := pNewName;
    END;
    MEMBER     PROCEDURE addPerson  (SELF IN OUT TYP_CREW, pPersonName IN VARCHAR2) IS
    BEGIN
    SELF.persons.EXTEND();
    SELF.persons(SELF.persons.LAST) := TYP_PERSON(pPersonName);
    END;
    MEMBER      FUNCTION getPerson  (SELF IN OUT TYP_CREW, pIndex IN NUMBER) RETURN TYP_PERSON IS
    BEGIN
    IF SELF.persons.COUNT > 0 THEN
    RETURN SELF.getPersons()(pIndex);
    END IF;
    RETURN NULL;
    END;
    MEMBER      FUNCTION getPersons (SELF IN OUT TYP_CREW) RETURN TYP_PERSONS IS
    BEGIN
    RETURN SELF.persons;
    END;
    END;
    +/+
    --+
    DECLARE
    crew_one    TYP_CREW;
    BEGIN
    crew_one    := TYP_CREW();
    crew_one.setName('The last crew on Earth');
    crew_one.addPerson ('Michael Knight');
    crew_one.addPerson ('Agent Mulder');
    crew_one.addPerson ('Agent Scully');
    crew_one.addPerson ('Frodo Bolson');
    for i in crew_one.persons.FIRST..crew_one.persons.LAST LOOP
    dbms_output.put_line('Person ['||i||']: '||crew_one.persons(i).getName());
    end loop;
    crew_one.getPerson(1).setName ('Michael Knight-----');
    crew_one.getPerson(2).setName ('Agent Mulder---');
    crew_one.getPerson(3).setName ('Agent Scully---');
    crew_one.getPerson(4).setName ('Frodo Bolson----');
    for i in crew_one.persons.FIRST..crew_one.persons.LAST LOOP
    dbms_output.put_line('Person ['||i||']: '||crew_one.persons(i).getName());
    end loop;
    END;
    How can I do this ParentObject().getChildObject().setChildFunction()?
    Thanks in advance,
    Donato.

    You completely misunderstand objects. Use:
    DECLARE
        crew_one TYP_CREW;
    BEGIN
        crew_one := TYP_CREW();
        crew_one.setName('The last crew on Earth');
        crew_one.addPerson ('Michael Knight');
        crew_one.addPerson ('Agent Mulder');
        crew_one.addPerson ('Agent Scully');
        crew_one.addPerson ('Frodo Bolson');
        for i in crew_one.persons.FIRST..crew_one.persons.LAST LOOP
          dbms_output.put_line('Person ['||i||']: '||crew_one.persons(i).getName());
        end loop;
        TYP_PERSON.setName (crew_one.persons(1),'Michael Knight-----');
        TYP_PERSON.setName (crew_one.persons(2),'Agent Mulder---');
        TYP_PERSON.setName (crew_one.persons(3),'Agent Scully---');
        TYP_PERSON.setName (crew_one.persons(4),'Frodo Bolson----');
        for i in crew_one.persons.FIRST..crew_one.persons.LAST LOOP
          dbms_output.put_line('Person ['||i||']: '||crew_one.persons(i).getName());
        end loop;
    END;
    Person [1]: Michael Knight
    Person [2]: Agent Mulder
    Person [3]: Agent Scully
    Person [4]: Frodo Bolson
    Person [1]: Michael Knight-----
    Person [2]: Agent Mulder---
    Person [3]: Agent Scully---
    Person [4]: Frodo Bolson----
    PL/SQL procedure successfully completed.
    SQL> SY.

  • I've seen all the posts for fixing the wifi on the 4s, none of them work!  So, who can tell me why my iPhone 4S cannot find any wifi when it used to easily, and when it does it can never connect?

    I've seen all the posts for fixing the wifi on the 4s, none of them work!  So, who can tell me why my iPhone 4S cannot find any wifi when it used to find wifi, and when it does find a wifi network it can never connect?  You think apple would have a clue how to fix it!  Because turning the wifi on and off doesn't work, resorting network settings doesn't work, even restoring phone to factory default doesn't work...

    Did not work. I've selected iMessage to ON and left it. After a few hours I recieved a message "activation unsuccessful. Turn on iMessage to try again". This has been going on for the past 3 days.

  • SSRS countrow Aggregate error(Aggregate and lookup functions cannot be used in query parameter expressions.)

    Below expression works fine with text box but gives error in dataset expression.
    ="SET FMTONLY OFF select  "+ join(Parameters!Column.Value,",") +" FROM pamcustom.dbo.vw_HFL_HFD_HotfileData INNER JOIN pamcustom.dbo.HFL_HFB_HotFileBatch  on BatchID = HFB_intBatchID where BatchID ="+Parameters!BatchId.Value+"
    and "+Parameters!cmbTranType.Value+" "+ iif(CountRows("DS_Aml_Mnr_Iss_Desc")=Parameters!Mnr_Iss_Desc.count," "," and aml_mnr_iss_desc in "+"('" & join(Parameters!Mnr_Iss_Desc.Value,"','")
    & "')")+iif(CountRows("ds_ReportingCategory")=Parameters!ReportingCategory.count," "," and ReportingCategory in "+"('" & join(Parameters!ReportingCategory.Value,"','") & "')")+iif(CountRows("ds_NAICSubGroup")=Parameters!NAICSubGroup.count,"
    "," and naicsubgroup in "+"('" & join(Parameters!NAICSubGroup.Value,"','") & "')")+iif(CountRows("ds_PortTrading")=Parameters!PortTrading.count," "," and porttrading in "+"('"
    & join(Parameters!PortTrading.Value,"','") & "')")+iif(CountRows("ds_GL_LE")=Parameters!GL_LE.count," "," and gl_le in "+"('" & join(Parameters!GL_LE.Value,"','") &
    "')")+iif(CountRows("ds_coagroup")=Parameters!cmbCoaGrp.count," "," and coagroup in "+"('" & join(Parameters!cmbCoaGrp.Value,"','") & "')")+iif(CountRows("Portfolio")=Parameters!cmbPort.count,"
    "," and portfolio in "+"('" & join(Parameters!cmbPort.Value,"','") & "')")+IIf(IsNothing(Parameters!txtSecID.Value)," "," and secid in ('"+Replace(Parameters!txtSecID.Value,",","','")+"')")+iif(IsNothing(Parameters!minPortFilter.Value)
    and IsNothing(Parameters!MinPort.Value)," "," and portfolio "+Parameters!minPortFilter.Value+Parameters!MinPort.Value)+iif(IsNothing(Parameters!maxPortFilter.Value) and IsNothing(Parameters!MaxPort.Value)," ","
    and portfolio "+Parameters!maxPortFilter.Value+Parameters!MaxPort.Value)+iif(IsNothing(Parameters!minCoaFilter.Value) and IsNothing(Parameters!txtMinCoa.Value)," "," and portfolio "+Parameters!minCoaFilter.Value+Parameters!txtMinCoa.Value)+iif(IsNothing(Parameters!maxCoaFilter.Value)
    and IsNothing(Parameters!txtMaxCoa.Value)," "," and portfolio "+Parameters!maxCoaFilter.Value+Parameters!txtMaxCoa.Value)
    I guess the error " Aggregate and lookup functions cannot be used in query parameter expressions." is because I am using CountRow to ensure that if all values of multi select all selected i will not use that filter in where clause.
    Pls. guide...

    Hi, Include your parameter total count in the dataset for parameter and instead of using countrows() function use the count from dataset in the expression.
    Hope this helps.........
    Ione

  • Aggregate functions cannot be used in group expressions

    Hi have report showing sales by Vendor. I need to list all the vendors with Monthly Total>5000 and combine the rest as "OTHER VENDORS"
    Vendor is a Group in my report, so I tried to put an expression as a Group on:
    =IIF(Sum(Fields!Mth_1_Sales.Value)>5000,Fields!Vendor_No.Value,"OTHER VENDORS")
    I've got an error: "aggregate functions cannot be used in group expressions"
    How do I get Vendors with Sales < 5000 into  "OTHER VENDORS" ?

    Hi,
    You need to group by Month on group expression,
    And you can use the same expression in the report column as 
    =IIF(Sum(Fields!Mth_1_Sales.Value)>5000,Fields!Vendor_No.Value,"OTHER VENDORS")
    Many Thanks
    ..................................................................................................................................................................Please
    mark the post as Please mark the post as answered if this post helps to solve the post.

  • Why do I get an error message when I try to sync my IPAD with ITunes? Message reads Cannot be used because Apple Mobile Device Service has not been started.

    Why do I get an error message when I try to sync my IPAD with ITunes? Message reads Cannot be used because Apple Mobile Device Service has not been started.

    AMDS for Windows
    http://support.apple.com/kb/TS1567

  • Why cannot I use hidden or display only item to store value for insert?

    hi, Gurus:
    I have a question:
    I implemented a form with report region in a page, the update works OK, but the add function has a problem:
    There is a column, offender_ID, which is a foreign key for another table, it should not be null during insert. However, even I pass the offender ID from master page when user click the create button, and it did shows in the form, it must be a text filed to insert successfully, why cannot I use hidden or display only item to store this value for insert? (If I use hidden or display only item, insert won't be successful, apex reports I tried to insert a null value to offender_ID column.)
    Many Thanks in advance.
    Sam

    Hi,
    There is a column, offender_ID, which is a foreign key for another table, it should not be null during insert. However, even I pass the offender ID from master page when user click the create button, and it did shows in the form, it must be a text filed to insert successfully, why cannot I use hidden or display only item to store this value for insert? (If I use hidden or display only item, insert won't be successful, apex reports I tried to insert a null value to offender_ID column.)I think both hidden and display items have attributes that can cause problems because of different ways these items function than non-hidden and non-display-only items function. Display Only items have a "Setting" of "Save Session State" Yes/No? That can be a problem.
    Would you do this? Make these items regular items instead and see if you can get those working. Then, we will try to change the fields back to hidden or display only.
    Howard
    Congratulations. Glad you found the solution.
    Edited by: Howard (... in Training) on Apr 11, 2013 10:26 AM

  • HT1848 why to transfer purchases from iphone to mac if they cannot be used?

    why to transfer purchases from iphone to mac if they cannot be used?

    Huh?
    Please explain.
    You can listen to  your music on your computer.  you can wathc video on your computer.

  • I am on a trial version of  InDesign in Creative Cloud and before I purchase need to know why and the files cannot be opened by others using CS6.  Isn't Cloud compatible with CS6 design software?

    I am on a trial version of  InDesign in Creative Cloud and before I purchase need to know why and the files cannot be opened by others using CS6.  Isn't Cloud compatible with CS6 design software?

    Industry standard files such as JPEG are compatible with many brands/versions of programs
    Proprietary files such as those created by InDesign are often not backwards compatible, due to new features in newer program versions
    This is not unique to Adobe... MS Word DOCX files are not backwards compatible with earlier versions of MS Word

  • PLS-00363: expression 'I' cannot be used as an assignment target

    Hello all
    I have a Package and I have one procedure in it .
    I have use dmlset inside this .
    Inside that procedure I have a cursor and inside the FOR loop I have mentioned something .
    FOR i IN 1 .. No_of_rec LOOP
    If....
    End if ;
    i := i+1 ;
    END LOOP;
    I have mentioned before end loop i := i+1 ; when i execute this package it is showing this error .
    "PLS-00363: expression 'I' cannot be used as an assignment target"
    What could be the problem?

    Of course,
    My example is showing that index I in loop is same thing as parameter IN in procedure1. Its value, not reference. I is passed as VALUE to LOOP just like PARAM1 is passed as value to PROCEDURE1. Trying to assignment something to I or PARAM1 will generate same error.
    Also another interesting example is
    CREATE OR REPLACE
    PROCEDURE procedure1(
        param1 IN OUT NUMBER)
    AS
    BEGIN
      param1 := 0;
    END procedure1;
    BEGIN
      FOR i IN 1..3
      LOOP
        procedure1(i);
      END LOOP;
    END;
    In this case procedure1 is correct but loop stmt is not. It will generate same error.
    After doing this examples i also concluded that procedure cant return value it can modify existing value of variable which is declared (uninitialized or initialized, OUT or IN OUT ) in upper PLSQL block (named or unnamed PLSQL block)

Maybe you are looking for

  • Can't download iPhoto from App store to my MacBook

    Hi I have been trying to  download iPhoto from the desktop app store to my MacBook Pro. No probs downloading other apps. Signed in with my Apple ID to make the purchase etc. After I click on "Install" it loads up - takes quite a while -  then nothing

  • Satellite M70 - blue screen during the WinXP installation

    hi I bought a new M70 with Win XP HOME installed on it! but i want to install my Win XP PROFESSIONAL on the notebook. So i put in the WinXPpro-CD and boot from CD/DVD-Drive. The first blue screen with some information in the bottom grey line come, an

  • CD-Rom for Audition 2.0 Classroom in a book

    Hi folks - Just gettng to grips with Audition 3.0 so I bought a Classroom in a Book for Audition 2.0, second hand from the US. (I'm told that versions 2 and 3 are similar enough for the book to be useful). It arrived today. Unfortunately, the CD-Rom

  • Has anyone needed to use AppleCare for the AppleTV2?

    My complimentary 90-day support ends soon, and I'm wondering if it's worthwhile to buy the extended care for this particular device?

  • Error rep-1401 in report 6i

    dear sirs, when i run the report i got this error rep_1401 cf_2formula fatal pl/sql error occurred known that after i trace i find that the error come because report not see the value inside the paramater :budg_type the code is here function CF_2Form