Why this CASE statement would not work?

If I use a CASE in my SELECT statement and met a strange thing and just need help to understand why he did it.

When I type this, it does not work:

CASE TRIM (Column1)
WHEN NULL THEN Column2
WHEN 'foo' THEN Column2
Of ANOTHER Column1
END AS NewColName

I use this query in an Oracle procedure to insert data into another table. The data inserted in the column of NewColName end up being 4 empty spaces, located in Column1. In the logic of this, TRIM must remove all the empty spaces, and he should get mapped to the first statement WHEN, who must insert the value of Column2, but that does not occur. I tried the following versions of the first line as well:

LTRIM (RTRIM (Column1)) CASE
CASE of REPLACE (Column1, ' ', ")

and they all produce the same result. I also tried to change WHEN NULL for WHEN " and it changed nothing. However, when I rewrite the statement in this way it works the way it should:

CASE
WHEN TRIM (Column1) IS NULL, Column2
WHEN TRIM (Column1) = 'foo' THEN Column2
Of ANOTHER Column1
END AS NewColName

In my mind, it seems that these two methods are trying the same thing, why we could work and the other not? Only, it has no sense to me.

Thank you

Hello

Welcome to the forum.

In your first statement, you have

WHEN NULL THEN.

This is the same as x = NULL.

Nothing is never equal to NULL, if you find yourself in your ELSE clause.

Concerning
Peter

Tags: Database

Similar Questions

  • Case statement does not work

    Dear all,

    We have the database oracle 11g r2 on windows.

    I created under function: -.

    SQL > CREATE OR REPLACE FUNCTION FUNC_TEST (P_TEST VARCHAR2)

    2 RETURN VARCHAR2

    3 AS

    4 V_TEST VARCHAR2 (20);

    5

    6 BEGIN

    7

    8 V_TEST: = P_TEST;

    9

    10

    11 CASES

    12. WHEN V_TEST = UPPER ('%UU%') THEN V_TEST: = REPLACE (V_TEST, 'UU', 'U');

    13. WHEN V_TEST = UPPER ('%OO%') THEN V_TEST: = REPLACE (V_TEST, 'OO', 'O');

    14. WHAT V_TEST = UPPER ('%NN%') THEN V_TEST: = REPLACE(V_TEST,'NN','N');

    15 ELSE V_TEST: = "CHANCHAL";

    END 16 CASES;

    17

    18

    19 V_TEST RETURN;

    20 EXCEPTION SO THAT OTHERS THEN

    21 DBMS_OUTPUT. PUT_LINE (' THERE IS AN ERROR ');

    22 END;

    23.

    The function is created.

    SQL > SHOW ERR

    No errors.

    SQL > SELECT FUNC_TEST('toon') FROM DUAL;

    FUNC_TEST ('TOON')

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

    CHANCHAL

    above function should show 'YOUR' build 'Toon' but its display "CHANCHAL";

    I train hard get the result OK but could not get it.

    Any suggestions would be very helpful.

    Kind regards
    Chanchal wankhade.

    Hello

    Chanchal Wankhade wrote:

    Dear all,

    We have the database oracle 11g r2 on windows.

    I created under function: -.

    SQL > CREATE OR REPLACE FUNCTION FUNC_TEST (P_TEST VARCHAR2)

    2 RETURN VARCHAR2

    3 AS

    4 V_TEST VARCHAR2 (20);

    5

    6 BEGIN

    7

    8 V_TEST: = P_TEST;

    9

    10

    11 CASES

    12. WHEN V_TEST = UPPER ('%UU%') THEN V_TEST: = REPLACE (V_TEST, 'UU', 'U');

    13. WHEN V_TEST = UPPER ('%OO%') THEN V_TEST: = REPLACE (V_TEST, 'OO', 'O');

    14. WHAT V_TEST = UPPER ('%NN%') THEN V_TEST: = REPLACE(V_TEST,'NN','N');

    15 ELSE V_TEST: = "CHANCHAL";

    END 16 CASES;

    17

    18

    19 V_TEST RETURN;

    20 EXCEPTION SO THAT OTHERS THEN

    21 DBMS_OUTPUT. PUT_LINE (' THERE IS AN ERROR ');

    22 END;

    23.

    The function is created.

    SQL > SHOW ERR

    No errors.

    SQL > SELECT FUNC_TEST('toon') FROM DUAL;

    FUNC_TEST ('TOON')

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

    CHANCHAL

    above function should show 'YOUR' build 'Toon' but its display "CHANCHAL";

    I train hard get the result OK but could not get it.

    Any suggestions would be very helpful.

    Kind regards
    Chanchal wankhade.

    I think you meant:

    CASE

    WHEN SUPERIOR (V_TEST) LIKE "% UU" THEN V_TEST: = REPLACE (UPPER (V_TEST), 'UU', 'U');

    WHEN SUPERIOR (V_TEST) LIKE '% OO %' THEN V_TEST: = REPLACE (UPPER (V_TEST), 'OO', 'O');

    ...

    '%' is a wildcard character only on the right-hand side of the LIKE operator. '%' has no particular meaning when you use the = operator.

    You can also use a CASE expression, rather than a CASE statement to this:

    v_test: = UPPER (p_test);

    v_test: = BOX

    WHEN v_test LIKE "% UU" THEN REPLACE (v_test, 'UU', 'U')

    WHEN v_test LIKE "% UU" THEN REPLACE (v_test, 'OO', 'o')

    ...

    END;

    Whatever it is, if v_test contains different models (for example "HOOVER VACUUM"), only 1 of them will be changed.  Is that what you want?

    If this isn't the case, after a few examples of data (CREATE TABLE and INSERT statements) and the results desired from these sample data.  Explain how you get these results from these data.

    See the FAQ forum: https://forums.oracle.com/message/9362002#9362002

  • Why this SQL statement is not recovering this indicator of index?

    Hello

    We use Oracle 10.2.0.4.

    I'm trying to understand why the following query will not use the index indicator. Anyone know? This is an index of compost.
    select   
    /*+ INDEX(pa_cost_distribution_lines_all pa_cost_distribution_lines_n5) */ 
    system_reference2, system_reference3 , system_reference1,
     EXPENDITURE_ITEM_ID 
    from pa_cost_distribution_lines_all
    where 
    --eXPENDITURE_ITEM_ID = 734145
     system_reference2=407530
    and  system_reference3 = 1
    and  system_reference1 = 669014
    Here is the plan of the explain command.
    Plan
    SELECT STATEMENT  ALL_ROWSCost: 20,326  Bytes: 13  Cardinality: 1       
         1 TABLE ACCESS FULL TABLE PA.PA_COST_DISTRIBUTION_LINES_ALL Cost: 20,326  Bytes: 13  Cardinality: 1  
    Here's the script for the index.
    CREATE INDEX PA_COST_DISTRIBUTION_LINES_N5 ON PA_COST_DISTRIBUTION_LINES_ALL
    (SYSTEM_REFERENCE2, SYSTEM_REFERENCE3, SYSTEM_REFERENCE1)
    LOGGING
    TABLESPACE APPS_TS_TX_IDX
    PCTFREE    5
    INITRANS   11
    MAXTRANS   255
    STORAGE    (
                INITIAL          128K
                NEXT             128K
                MINEXTENTS       1
                MAXEXTENTS       2147483645
                PCTINCREASE      0
                BUFFER_POOL      DEFAULT
               )
    NOPARALLEL;
    Thank you.

    SYSTEM_REFERENCE1/2/3 are VARCHAR2 columns.

    Oracle is to resolve the query by using an implicit "TO_NUMBER" on each column, which makes the path of the index not available, you can check it out using SET AUTOTRACE ON and observing:

    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       1 - filter(TO_NUMBER("SYSTEM_REFERENCE2")=407530 AND
                  TO_NUMBER("SYSTEM_REFERENCE1")=669014 AND TO_NUMBER("SYSTEM_REFERENCE3")=1)
    

    If you explicitly put quotes or "TO_CHAR" around the values then the index will be used. For example:

    select
    /*+ INDEX(pa_cost_distribution_lines_all pa_cost_distribution_lines_n5) */
    system_reference2, system_reference3 , system_reference1,
     EXPENDITURE_ITEM_ID
    from pa_cost_distribution_lines_all
    where
    --eXPENDITURE_ITEM_ID = 734145
     system_reference2='407530'
    and  system_reference3 = '1'
    and  system_reference1 = '669014'
    /
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       2 - access("SYSTEM_REFERENCE2"='407530' AND "SYSTEM_REFERENCE3"='1' AND
                  "SYSTEM_REFERENCE1"='669014')
    
  • Can someone tell me why this refund calculator does not work on Business Catalyst?

    Hi, I hope someone can see what is happening here, I don't know if it's a matter of Business Catalyst or a code issue itself, which I think is not.

    Pretty easy fix, you forgot to download jquery - 1.8.2.min.js and modernizr - 2.6.2.min.js

  • Why this UL CSS does not work as expected

    I try to add a picture as a bullet in a UL, but just appears on a start page, it will be in a standard HTML5 page.

    Here is the code in the start page:

    {.bluesquare}

    list-style - image: URL(images/bullet.png);

    }

    < side class = "col-lg-4 4-md-col col-sm-4 mtop" >

    < section class = "greypnl" >

    < ul class = "bluesquare" >

    < li > links side here < /li >

    < li > links side here < /li >

    < /ul >

    < / item >

    < / side >

    Here's the code in a HTML5 page:

    {.bluesquare}

    list-style - image: URL(images/bullet.png);

    }

    < side class = "col-lg-4 4-md-col col-sm-4 mtop" >

    < section class = "greypnl" >

    < ul class = "bluesquare" >

    < li > links side here < /li >

    < li > links side here < /li >

    < /ul >

    < / item >

    < / side >

    There is no difference between the two that I see, so preventing it from working?

    I can only get the image to appear as the point of the ball when I add an inline style to the AMT itself as follows: < ul class = "bluesquare" style = "list-style - image: url(images/bullet.png);" ">.

    No matter what control of image for the chip set could only inline code as follows: < style li = "background: url(images/bullet.png) non-repetition 0px 0px;" padding: 0 0 5px 30px; ">

    Any thoughts on what is predominant images of ball in a start page layout? I don't really want to encode each ball that will appear like this!

    Thank you.

    I just did a test using Bootstrap and everything worked as expected - hand coded. Nothing in the Bootstrap css file overides the ball style here.

  • Why this simple trigger does not work?

    For one of our Test environments, I was asked to implement a trigger which limits users based on ip.
    IP addresses of eligible users is stored in the maint.ip_dtls table. But, does not seem the trigger to trigger the application error and reject the connection when a user with an IP address that is not present in the table ip_dtls try to connect.
    create or replace trigger sys.testlogon after logon on database
    declare
    v_ipadd varchar2(100);
    ip_exists number;
    
    begin
    -- Getting the IP
    select sys_context('USERENV','IP_ADDRESS') into v_ipadd from dual ;
    select count(*) into ip_exists from maint.ip_dtls where ip = v_ipadd;
    
    if ip_exists = 0
       then raise no_data_found;
    end if;
    
    exception
    when no_data_found then
    raise_application_error (-20103, 'Insufficient privileges to login');
    
    end ;
    /
    The code works when tested from an anonymous block.

    Published by: Steve_74 on November 25, 2010 06:36

    Probably the fact that you create the trigger in the SYS schema could cause problems.
    Have you tried to create the trigger in another schema/as another user?
    SYS (and SYSTEM) belong to Oracle, and you should not create objects in the schema.

    Edit
    See:
    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:3236035522926

    Published by: hoek on November 25, 2010 15:53

  • Why can I no longer right click to get the NewFolder option? I realize now, there is a button for this, but it does not work.

    Why can I no longer right click to get the NewFolder option? I realize now, there is a button for this, but it does not work.

    Hello

    I understand that you are facing problems with the creation of a "New folder" option in the context menu.

    Have you made changes on the computer before this problem?

    I suggest to follow the methods provided below and we update on the State of the question.

    Method 1: I suggest you to follow the steps suggested by "Linda Yan" and check if it helps.
    http://social.technet.Microsoft.com/forums/en-us/w7itproui/thread/9ee6ecdf-5958-4AF4-B640-c659ada57bc4/

    Registry WARNING: This section, method, or task contains steps that tell you how to modify the registry. However, serious problems can occur if you modify the registry incorrectly. Therefore, make sure that you proceed with caution. For added protection, back up the registry before you edit it. Then you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, see this link: http://windows.microsoft.com/en-US/windows7/Back-up-the-registry

    Method 2: If the problem persists, I suggest you follow the steps proposed by "Linda Yan" and check if it helps.
    http://social.technet.Microsoft.com/forums/en-us/w7itprogeneral/thread/97de8a2a-12f2-4381-A409-a78f4ae551cf/
    Hope this information is useful.

  • The Remote option for matching seems to have disappeared (file/devices/Remote). This discovered after the last updated at 12.4 and Remote app would not work. Suggestions?

    The Remote for iPhone & Remote app matching option seems to have disappeared (file/devices/Remote). This discovered after the last updated at 12.4 and Remote app would not work. Suggestions?

    Fixed. I removed the Remote, reloaded app to my iPhone and then reinstated the info Apple ID and password in the app all connected immediately. The 'Remote' option is not always present under file/devices/Remote, but everything works well at this point.

  • Why Silverlight don't is not supported in future versions of Firefox Silverlight is a necessary component of the STAN does this mean Stan will not work in future versions

    I read that Silverlight is not supported in Firefox 52 + Stan requires silverlight to function does this mean STAN will not work with Firefox 52 +.

    This one? https://www.Stan.com.au/

    At some point, all THE plugins using the NPAPI interface are intended to stop working in Firefox. If all goes as planned, the Firefox 'support extended-release' (ESR) next spring will allow you to continue to use Silverlight for the rest of the year, while Stan has plenty of time to switch to alternatives. Or you can use Internet Explorer, if they are not.

  • Case statement is not spend.

    Hello

    I'm having a strange problem with a case statement.  I'm passing is a Boolean value that is set to false, but the case statement never switches to the loop of "false".  I have attached a word doc who did the screen has a step of this unique through being shot.  The photo of the top has the case highlighted with the probe #8 beside him indicate 'False. '  In the lower screen shot is the very next step that highlights the outside circle while ' loop', but the case statement is always 'True '.  Anyone seen this before?

    Gary Tyrna

    Hey Mello,

    Well, I see what you're saying and you are right, the problem is the case statement works when highlight of execution.  But I have a main case statement in the loop that either allows the state machine to execute a loop or hides them and that case is triggered for no steps to true or false.  So that was the reason why I sent the first e-mail because I could see this case change, but not the smallest.  But if this is the fix well I'll run with it and lets see case statement switch the highlight of the performance.

    Thanks again.

    Gary Tyrna

  • When my DVD drive would not work, I bought an external. I get the same message when I go into properties. Pilots have been disabled.

    When my DVD drive would not work, I bought an external. I get the same message when I go into properties. Pilots have been disabled.

    Hello

    Check with the manufacturer of the system, their online documentation and drivers, diagnostics, and
    Ask problems known in their forums. You may also check those similar
    resources on the site of the manufacturer of the actual device (for the original drive).

    =================================================================

    It is not surprising that the same issue affects the old and the new drive.

    This problem may be caused by the presence of too many CD/DVD programs competing for resources,
    especially by these programs that run at startup.

    Even if the error is not Code 22 check these:

    Code 22
    http://TechNet.Microsoft.com/en-us/library/cc731267 (v = ws.10) .aspx

    How to fix the Code 22 errors
    http://pcsupport.about.com/od/errorc/a/code-22-error.htm

    How to enable a device in Device Manager in Windows Vista
    http://pcsupport.about.com/od/windowsvista/HT/enabledevvista.htm

    If necessary:

    Step 1: Please do all the same underneath if you did some before as is often total
    a process that solves the problem.

    Try this - Panel - Device Manager - CD/DVD - double click on the device - driver tab.
    Click on update drivers (this will probably do nothing) - RIGHT click ON the drive - uninstall.
    RESTART this will refresh the default driver stack. Even if the reader does not appear to continue
    below.

    Then, work your way through these - don't forget the drive might be bad, could be a coward
    cable or slight corrosion on the contacts (usually for a laptop) and other issues.

    Your CD or DVD drive is missing or is not recognized by Windows or other programs
    http://support.microsoft.com/kb/314060 - a Mr Fixit

    Try this fix manually if the Fixit 314060 does not work
    http://www.pchell.com/hardware/cd_drive_error_code_39.shtml

    Your CD or DVD drive is missing or is not recognized by Windows or other programs-
    a Mr Fixit
    http://support.Microsoft.com/kb/982116

    The CD drive or the DVD drive does not work as expected on a computer that you upgraded to
    for Windows Vista
    http://support.Microsoft.com/kb/929461

    When you insert a CD or a DVD, Windows Vista may not recognize the disc
    http://support.Microsoft.com/kb/939052

    Your CD or DVD drive cannot read or write media - A Mr Fixit
    http://support.Microsoft.com/GP/cd_dvd_drive_problems

    CD/DVD drive does not appear in Windows Vista, or you receive this error in Windows
    Vista installation after booting from the DVD (AHCI)
    http://support.Microsoft.com/kb/952951
    Drive CD - R or CD - RW Drive is not recognized as a recordable device
    http://support.Microsoft.com/kb/316529/

    Hardware devices not detected or not working - A Mr Fixit
    http://support.Microsoft.com/GP/hardware_device_problems

    Another possibility is that the cables are loose. Remove ALL power, then make sure that the cables in both
    ends. Remove and replace, do not just tight. For laptops, you can often clean power and
    contacts data with a pencil eraser.

    Some DVD players do not use the Windows default drivers so check with the manufacturer of system and
    manufacturer of device to see if there is a firmware or drivers for your drive if necessary.

    ===============================

    Step 2: You have disc problems as the CD/DVD is actually 4 discs in 1 case (CD & DVD
    Burn and CD and DVD read). So it is not unusual for 1 or 2 operational so that other parts
    do it right.

    Did you follow the Troubleshooting Guide for the reader who still does not work? There are
    the entries in registry that the troubleshooter does not solve and those who "might" be the cause.

    Check with your Maker system and a device for the two possible firmware updates and
    the correct registry entries for your car.

    Here are the keys that I of course are those in question - for the subkeys of the CD/DVD drive
    as there will be other subkeys in these keys. Do not forget to ask specific keys involved as well as
    the parameters.

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\IDE

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Hardware Profiles\0001\System\CurrentControlSet\Enum\IDE

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\ {4D36E965-E325-11CE-BFC1-08002BE10318}

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

    You can probably find more info here and maybe even the exact registry for your CD/DVD settings
    drive from someone with the same model.

    Forums - a lot of expert real help
    http://Club.myce.com/

    CD/DVD units
    http://www.myce.com/storage/

    Use DevManView to locate the CD/DVD in the registry (be careful and do a prior Restore Point)
    nothing change) - find the DevManView device and then make a right click on it free in RegEdit.

    DevManView - free - an alternative to the standard Windows Device Manager, which displays all the
    devices and their properties in flat table, instead of the tree viewer
    http://www.NirSoft.NET/utils/device_manager_view.html

    I hope this helps.

    Rob Brown - Microsoft MVP<- profile="" -="" windows="" expert="" -="" consumer="" :="" bicycle="" -="" mark="" twain="" said="" it="">

     
  • Why any screen recorder does not work on my computer? __

    Why any screen recorder does not work on my computer?

    Hi I formatted my computer and downloaded all the conditions for this, I downloaded hypercam and installed, I tried to open it in the tool bar and the start menu, it still does not work.
    I downloaded another program for recording of the screen, it also did not work, I tried 3 programs, they all did not work
    by the way my computer: windows vista service pack 2 and the screen recorders have worked before I formatted my laptop
    I need a solution pleaseeeeee

    I got this error in the three programs

    Signature of the problem:
    Problem event name: APPCRASH
    Application name: ScreenVCR.exe
    Application version: 1.5.34.0
    Application timestamp: 2a425e19
    Fault Module name: StackHash_b4c3
    Fault Module Version: 0.0.0.0
    Fault Module Timestamp: 00000000
    Exception code: c0000096
    Exception offset: 02e42a3b
    The system version: 6.0.6002.2.2.0.768.3
    Locale ID: 1033
    Additional information 1: b4c3
    More information 2: d2a8bebd21e0e9bfa99e084d53ece2b6
    3 more information: 74a 3
    Additional information 4: 0480b6e0a2e7a1df44ee618ae8d0084f

    Read our privacy statement:
    http://go.Microsoft.com/fwlink/?LinkId=50163&clcid=0x0409

    Please give me a solution... :(

    my laptop computers Info

    Windows is Windows Vista Home Premium
    Intel (r) core (TM) 2 Duo CPU 26500 2.10 GHz
    3.00 GB RAM
    Mobile Intel (r) 4 Series Express Chipset Family

    =============================================
    Just a thought... maybe your video driver or DirectX needs and update?

    Have you tried the following applications:

    (1) Windows Media Encoder 9 Series
    http://www.free-codecs.com/download/Windows_Media_Encoder_9_Series.htm

    Direct Download Link:
    http://www.free-codecs.com/download_soft.php?d=571&s=327

    First steps with screenshot
    Using Windows Media Encoder
    http://www.Microsoft.com/windows/windowsmedia/HOWTO/articles/ScreenCap.aspx

    (2) Microsoft Expression Encoder 4
    http://www.Microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=75402be0-C603-4998-A79C-becdd197aa79

    Expression Encoder training videos
    http://expression.Microsoft.com/en-us/cc197144.aspx

    Volunteer - MS - MVP - Digital Media Experience J - Notice_This is not tech support_I'm volunteer - Solutions that work for me may not work for you - * proceed at your own risk *.

  • CASE STATEMENT DOES NOT HIERARCHY

    Hi Experts

    I have this case statement:

    BOX WHEN ' @{pvCalType} "="Cal1"THEN"Calendar Cal1"". "" Year. "

    WHEN ' @{pvCalType} "="Cal2"THEN"Calendar Cal2"". "" Year

    ANOTHER NULL

    END

    All the columns in the YEAR of different sizes have properties of the hierarchy.

    When I view my results of this statement, there is no hierarchy.

    I want the hierarchy in order to drill down of the YEAR > QUARTER > MONTHS

    Help, please.

    Hello

    do you have other possible values for "pvCalType"?

    If not try this formula: "@{pvCalType} schedule". " Year. "

    (not sure this is the right syntax, if it does not work after the return of the error and I get the right thing...)

  • Why the object_not_found exception does not work?

    Posters,

    I have the following statement in a package.procedure:

    -- (...)
    Start

    Select dbms_metadata.get_dependent_ddl ('INDEX', 'OWNER', sTableName)
    in the cDDL - clob for index DDL
    of the double
    -- (...)

    exception
    When dbms_metadata.object_not_found then
    null;

    end;
    -- (...)

    Execution is stopped in the select, not enter the exception and the following message is displayed in PL/SQL Developer MicroHelp:

    + "ORA-31608: specified object type INDEX not found." + "

    I did it another way by adding the following clause:

    -- (...)
    Start

    Select dbms_metadata.get_dependent_ddl ('INDEX', 'OWNER', sTableName)
    in the cDDL - clob for index DDL
    of the double
    where exists (select 1+)
    of all_indexes+.
    where table_owner = 'OWNER'+.
    and table_name = sTableName); +
    -- (...)

    exception
    + When no_data_found then +.
    null;

    end;
    -- (...)

    It works, but: why the object_not_found exception does not work?

    Thanks in advance for everyone!
    Philips

    Oh I just noticed:

    What happens if instead of this:

    Select dbms_metadata.get_dependent_ddl ('INDEX', 'OWNER', sTableName)
    in the cDDL - clob for index DDL
    of the double

    you say:

    cDDL: = dbms_metadata.get_dependent_ddl ('INDEX', 'OWNER', sTableName);

    ?

  • Why addChild (new Shape()) does not work?

    I would like to know why the following code does not work:

    < mx:Application >
    ..
    private function doShape (): void {}
    var aShape:Shape = new Shape();
    this.addChild (aShape);
    }
    ..
    < mx:Button click = "doShape ()" / > "
    < / mx:Application >

    According to the docs, addChild() takes a DisplayObject instance as a parameter. The shape is a DisplayObject. However, I get an error (#1034) that the form cannot be converted to mx.core.IUIComponent

    I don't understand what the problem...

    Yes, it's always a witch hunt in a first time. Flex containers (for example, canvas, Panel, etc) may have only UIComponents and children, not only of DisplayObject. The thing is, one UIComponent can have simple DisplayObjects as children, so you have to wrap your form:

    var temp: UIComponent = new UIComponent();
    temp.addChild (aShape);
    this.addChild (temp);

Maybe you are looking for