Using CASE and CAST in a INSERT statment

Can I have a CASE condition or a CAST condition within an INSERT statement?
For example:
Insert into table1 (
Value1,
Value2,
Value3,
Value4)
Select
Seq1.nextval,
Case when (color.grade in (6,5,7,8) or color.grade2 in (6,5,7,8,11,12)
Then 2
Else 1
End case,
‘GREAT’,
CAST(color.client as varchar2)
From color;
Must I specify a column name in the CASE statement? If so, how can I do it if it is based on values from 2 columns?

Satyaki_De wrote:
Yes.
A little modification in your query ->
Insert into table1(
Value1,
Value2,
Value3,
Value4
Select Seq1.nextval Value1,
Case
when color.grade in (6,5,7,8)
or color.grade2 in (6,5,7,8,11,12) Then
2
Else
1
End case Value2,
‘GREAT’ Value3,
CAST(color.client as varchar2) Value4
From color;Regards.
Satyaki De.I don't think that the "END CASE" is supported in SQL, it's the PL/SQL syntax of the CASE statement that requires an END CASE.
In addition if you cast to VARCHAR2 you need to specify the length of the VARCHAR2, e.g. VARCHAR2(100).
So the statement probably should look something like this (untested):
Insert into table1(
                   Value1,
                   Value2,
                   Value3,
                   Value4
Select Seq1.nextval Value1,
       Case
       when color.grade in (6,5,7,8)
         or color.grade2 in (6,5,7,8,11,12)
       Then
         2
       Else
         1
       End Value2,
       'GREAT' Value3,
       CAST(color.client as varchar2(100)) Value4
From color;Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/

Similar Messages

  • Using Case and Joins in update statement

    Hi all,
    I need to update one column in my table...but need to use case and joins...I wrote the query and it is not working
    I am getting an error msg saying...the SQL command not ended properly...
    I am not that good at SQL...Please help...
    update t1 a
    set a.name2=
    (case
    when b.msg2 in ('bingo') then '1'
    when b.msg2 in ('andrew') then '2'
    when b.msg2 in ('sam') then '3'
    else '4'
    end )
    from t1 a left outer join t2 b
    on a.name1 = b.msg1 ;
    Waiting for help on this...!
    Thanks in Advance... :)

    Another approach is to update an inline view defining the join:
    update
    ( select a.name2, b.msg2
      from   t1 a
      join   t2 b on b.msg1 = a.name1 ) q
    set q.name2 =
        case
          when q.msg2 = 'bingo' then '1'
          when q.msg2 = 'andrew' then '2'
          when q.msg2 = 'sam' then '3'
          else '4'
        end;which could also be rewritten as
    update
    ( select a.name2
           , case q.msg2
                when 'bingo'  then '1'
                when 'andrew' then '2'
                when 'sam'    then '3'
                else '4'
             end as new_name
      from   t1 a
      join   t2 b on b.msg1 = a.name1 ) q
    set name2 = new_name;The restriction is that the lookup (in this case, t2.msg1) has to be declared unique, via either a primary or unique key or unique index.
    (You don't strictly need to give the view an alias, but I used 'q' in case you tried 'a' or 'b' and wondered why they weren't recognised outside the view.)

  • Using distinct and orderby in the select statment

    Hi All,
    Can anyone tell me what is the purpose of using distinct and orderby in the select statment.

    Hi,
    Using the distinct function with more than one column yields some substantial results. SQL will return the rows with distinct or unique combinations of those columns. Assume this same employee table has another column including the salary of each employee. With the use of the distinct function we can pull a list of unique job titles - salaries.
    SQL Code:
    SELECT DISTINCT job_titles, salary FROM employees;
    SQL has returned all the rows with unique combinations of job titles and salaries. Any duplicate combinations of job titles and salaries will be ignored. For example if we had two CEOs in the table making the same salary each year, only one row would be returned but if we had two CEOs with different salaries, both rows would be returned.
    Order by
    The SQL ORDER BY clause comes in handy when you want to sort your SQL result sets by some column(s). For example if you want to select all the persons from the already familiar Customers table and order the result by date of birth, you will use the following statement:
    SELECT * FROM Customers
    ORDER BY DOB
    As you can see the rows are sorted in ascending order by the DOB column, but what if you want to sort them in descending order? To do that you will have to add the DESC SQL keyword after your SQL ORDER BY clause:
    SELECT * FROM Customers
    ORDER BY DOB DESC
    If you don't specify how to order your rows, alphabetically or reverse, than the result set is ordered alphabetically, hence the following to SQL expressions produce the same result:
    SELECT * FROM Customers
    ORDER BY DOB
    SELECT * FROM Customers
    ORDER BY DOB ASC
    You can sort your result set by more than one column by specifying those columns in the SQL ORDER BY list. The following SQL expression will order by DOB and LastName:
    SELECT * FROM Customers
    ORDER BY DOB, LastName
    if its useful reward points

  • HP Prime crashes while using CAS and loses stored variables

    As the title suggests I'm experiencing some problems while using CAS whit my new Prime (it arrived 3 days ago). While doing operations like scrolling up the screen and copying/pasting things, or simply defining new variables it happens that the prime crashes (sometimes it also restart itself) and loses all the variables I've stored.
    The prime is running the latest FW (6030).  I've also noticed that after the firmware upgrade the DataStreamer icon in the app library has became grey and an exclamation mark appears when I try to start it.
    Any help or suggestion would be great.
    Thank you in advnce,
    M1cha3l

    I have only a little experience with Primes RPN.
    It does seem that for user variable, you do need to first create them before storing anything to them.  a ENTER OK creates user variable a and puts a 0 on stack 1:
    123 ENTER, 'a' ENTER,  Shift Sto>  or 123_'a'_Shift Sto> ( _ = space key) store 123 in a and put 123 on stack 1:
    Other more expert users may offer better advice.

  • What tools does Microsoft use to mock UI interfaces, flowchart, use cases, and UML diagrams?

    I have searched google, but was not able to find article or blogs to answer this question. The questions asked here are very old. So I think this is a very relevant question today.
    We are a .NET group and we to update how we storyboard our application development. What tools does Microsoft use to mock UI interfaces, flowcharts, and use cases? Specifically for projects that are either C# .NET MVC 5 and above (looking forward to
    vNext).
    In the past, power point was able to do some of these things, but it seems it has been deprecated? Does Visio use these things? Also, is Visual Studio's 2013 UML diagram any good or is there another tool in Microsoft's bag of goodies that has more options?
    I have read about blend, but it does not seem to be .NET MVC specific.  
    Again, this is asking about what tools Microsoft teams usually use to storyboard as our team would like to mimic the more contemporary processes. We are in the process of upgrading our .NET applications and feel it is time to update our workflow process
    as well.
    Any book recommendations on TFS 2013 and agile are welcomed as well.  

    hlyates,
    Sorry but you have posted to a forum that deals exclusively with questions/issues about Microsoft Project, a project management application.
    I suggest you delete this post and start with the following: http://social.technet.microsoft.com/Forums/projectserver/en-US/home?forum=whatforum
    John

  • Using Cursor and FOR LOOP to INSERT the data into table

    Hi all,
    I have SELECT statement that returns 3 rows:
    PROCESSNAME
    PROTDATE
    IMM
    2013-12-18
    Metrology
    2013-11-18
    CT
    2013-12-04
    SELECT  processName, MAX(NVL(protStartDate, protCreateDate)) AS protDate
        FROM TABLE(SEM_MATCH("{
                ?ipc rdf:type s:Protocol .
                ?ipc s:protocolNumber ?protNum .
                ?ipc s:protocolCreateDate ?protCreateDate .
                OPTIONAL {?ipc s:protocolSchedStartDate ?protStartDate }
                ?ipra rdf:type s:ProcessAggregate .
                ?ipra s:hasProtocol ?iprot .
                ?iprot s:protocolNumber ?protNum .
                ?ipra s:processAggregateProcess ?processName.
        }",sem_models("PROTS", "LINEARS"),NULL, SEM_ALIASES(SEM_ALIAS("","http://VISION/Data/SEMANTIC#"),SEM_ALIAS("s","http://VISION/DataSource/SEMANTIC#")),NULL))
            Group by processName
    Now I need to INSERT these values into the table along with the other values.
    these other values come from different table.
           INSERT INTO MODEL_CLASS_COUNTS (MODEL_NAME, CLASS_NAME, INS_COUNT, COUNT_DATETIME, PROCESS_NAME, PROT_DATE)
           VALUES
           ("$MODEL",     
                "${i}",
            (SELECT COUNT (DISTINCT S)  FROM TABLE(SEM_MATCH(
                            "{?s rdf:type :${i} . }",SEM_Models("$MODEL"),NULL, SEM_ALIASES(SEM_ALIAS("","http://VISION/DataSource/SEMANTIC#")),NULL))),
             SYSTIMESTAMP, %%here need to insert PROCESSNAME, PROTDATE%%
    t was giving me error:
    PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    so i enclosed sparql query into single quotes.
    The code is as follows:
    declare
    type c_type is REF CURSOR;
    cur c_type;
    v_process varchar2(200);
    v_pdate varchar2(200);
    begin
    open cur for
           ' SELECT processName,  MAX(NVL(protStartDate, protCreateDate)) AS protDate   <-- it's complaining about this being too long identifier, i think...
            FROM TABLE
              (SEM_MATCH (
                            ?ipc rdf:type s:Protocol .
                            ?ipc s:protocolNumber ?protNum .
                            ?ipc s:protocolCreateDate ?protCreateDate .
                            OPTIONAL {?ipc s:protocolSchedStartDate ?protStartDate }
                            ?ipra rdf:type s:ProcessAggregate .
                            ?ipra s:hasProtocol ?iprot .
                            ?iprot s:protocolNumber ?protNum .
                            ?ipra s:processAggregateProcess ?processName.
                        }",SEM_Models("XCOMPASS", "XPROCESS"),NULL,    
              SEM_ALIASES(SEM_ALIAS("","http://VISION/Data/SEMANTIC#"),
              SEM_ALIAS("s", "http://VISION/DataSource/SEMANTIC#")),NULL))
               Group by processName';  
    loop
    fetch cur into v_process, v_pdate;
    exit when cur%NOTFOUND;
    --here I need to insert v_process , v_pdate into my table along with other values...
    dbms_output.put_line('values for process and prod_date are: ' || v_process || v_pdate );
    end loop;
    close cur;
    end;
    exit;
    Now, I get an error:
    ORA-00972: identifier is too long
    Does anyone know way around this?

    Hi,
      I tested something similar with insert into select  and it worked fine :
    insert into t_countries(ID,CITY ,POPULATION, DESCRIPTION, located, insdate )
    SELECT 1 id, city, o , city||' is a nice city' description,  max(nvl(locatedAt,'unknown')) as located,
      SYSTIMESTAMP
      FROM TABLE(SEM_MATCH(
        '{GRAPH :gCH {<http://www.semwebtech.org/mondial/10/countries/CH/> :hasCity ?cityID .
           ?cityID :name ?city .
           OPTIONAL{?cityID :locatedAt ?locatedAt .}
           ?cityID :population ?o .
        SEM_Models('VIRT_MODEL_MONDIAL'),
        SEM_Rulebases(null),
        SEM_ALIASES(SEM_ALIAS('','http://www.semwebtech.org/mondial/10/meta#'),
        SEM_ALIAS('prv','http://www.semwebtech.org/mondial/10/countries/CH/provinces/')
        null))
        group by city,o
        order by city;
    Or with execute immediate :
    declare
      v_country varchar2(200) :='http://www.semwebtech.org/mondial/10/countries/F/';
      v_text varchar2(2000);
    begin
    v_text := 'insert into t_countries(ID,CITY ,POPULATION, DESCRIPTION, located, insdate )
    SELECT 1 id, city, o , city||'' is a nice city'' description,  max(nvl(locatedAt,''unknown'')) as located,
      SYSTIMESTAMP
      FROM TABLE(SEM_MATCH(
        ''{<'||v_country||'> :hasCity ?cityID .
           ?cityID :name ?city .
           OPTIONAL{?cityID :locatedAt ?locatedAt .}
           ?cityID :population ?o .
        SEM_Models(''VIRT_MODEL_MONDIAL''),
        SEM_Rulebases(null),
        SEM_ALIASES(SEM_ALIAS('''',''http://www.semwebtech.org/mondial/10/meta#'') ),
        null))
        group by city,o
        order by city';
        dbms_output.put_line(v_text);
        delete from t_countries;
        execute immediate v_text ;
        commit;
    end;
    Marc

  • How to use case and decode to extract the data

    Hello PL/SQL Gurus,
    I am using Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production version
    I have a table in following format -
    drop table TT2;
    create table TT2(College, Class,gender,status,fees) as select
    'IITB','MBA','M','P',255600 from dual union all select
    'IITK','MTech','M','P',300000 from dual union all select
    'IITD','MBA','F','P',450000 from dual union all select
    'IITKH','MBA','F','P',350000 from dual union all select
    'IITC','MTech','F','P',420000 from dual union all select
    'IITB','MTech','M','P',185000 from dual union all select
    'IITC','MTech','M','P',235000 from dual union all select
    'IITD','MBA','F','F',175000 from dual union all select
    'IITM','MBA','M','F',257000 from dual union all select     
    'IITKH','MTech','F','P',335000 from dual union all select
    'IITD','MBA','F','P',540335 from dual union all select
    'IITC','MBA','F','F',125089 from dual union all select
    'IITD','MTech','M','P',290756 from dual union all select
    'IITM','MBA','M','P',200000 from dual union all select     
    'IITKH','MBA','F','F',534990 from dual union all select
    'IITD','MBA','F','P',221000 from dual ;some of the extraction conditions are as following -
    CASE CONDITION
    College in 'IITB' and status='P'- 'WestRegion Passed'
    College in 'IITC' and status='P'- 'SouthRegion Passed'
    College in 'IITD' and 'IITK' and status='P' and Gender='F' - 'NothRegion Female Passed'
    College not in 'IITK' and status='F' - 'Ex Kanpur Failed'
    Expected output -
    Region Statnding     Fees
    WestRegion Passed     440460
    SouthRegion Passed     655000
    NothRegion Female Passed     1386335
    Ex Kanpur Failed     1092079SQL Used
    I am using the following query which only make sure of case but this is not how i want the output , if i try to use the case within decode then how to work on this -
    SELECT (CASE WHEN College in ('IITB') and status='P' then sum(fees) else 0 end) WP,
    (case when College in ('IITC') and status='P' then sum(fees) else 0 end) SP,
    (case when College in ('IITD','IITK') and gender='F' and status='P' then sum(fees) else 0 end) NFP,
    (case when College in ('IITK') and status='F' then sum(fees) else 0 end) ExKF
    FROM
    TT2
    GROUP BY College, Class,gender,status

    user555994 wrote:
    Thank you so much jeneesh i am really thankful to you ...vov.
    one more query in case if any of the selection don't have the output data , then values will be displayed like -One way..
    with t as
    --"Add all your descriptions
    (select 'WestRegion Passed' region_standing from dual union all
    select 'SouthRegion Passed' region_standing from dual union all
    select 'NothRegion Female Passed' region_standing from dual union all
    select 'Ex Kanpur Failed' region_standing from dual)
    select region_standing,sum(fees) fees
            from (
            (SELECT CASE WHEN College in ('IITB') and status='P'
                                then 'WestRegion Passed'
                        when College in ('IITC') and status='P'
                                then 'SouthRegion Passed'  
                        when College in ('IITD','IITK') and gender='F' and status='P'
                                then 'NothRegion Female Passed'
                        when College in ('IITK') and status='F'
                                then 'Ex Kanpur Failed'
                        else 'Others' end region_standing,
                        sum(fees) fees
            FROM TT2
            GROUP BY  CASE WHEN College in ('IITB') and status='P'
                                then 'WestRegion Passed'
                        when College in ('IITC') and status='P'
                                then 'SouthRegion Passed'  
                        when College in ('IITD','IITK') and gender='F' and status='P'
                                then 'NothRegion Female Passed'
                        when College in ('IITK') and status='F'
                                then 'Ex Kanpur Failed'
                        else 'Others' end
            union all
            select region_standing,0
            from t
    group by   region_standing;
    REGION_STANDING              FEES
    Others                     2567835
    NothRegion Female Passed   1211335
    WestRegion Passed           440600
    Ex Kanpur Failed                 0
    SouthRegion Passed          655000
    {code}
    Edited by: jeneesh on Nov 5, 2012 5:07 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Insert using case when

    hello ,
    i wanna use "case when" statement in the insert , i implement it like this :
    currentyear:=1;
    insert into test1 (ATTRIB1,ATTRIB2) values ((case when currentyear=1 then 'ok' else 'notOK' end),'val2' );
    but it didn't work, i got this error :
    ORA-14551: cannot perform a DML operation inside a query
    Regards
    Elyes
    Edited by: user10393090 on 5 janv. 2009 03:32

    Better approach is ->
    insert into test1 (ATTRIB1,ATTRIB2)
    select case
             when &currentyear=1 then
              'ok'
           else
             'notOK'
           end AS attrib1,
           'val2' AS attrib2
    from dual;N.B.: Not Tested...
    Regards.
    Satyaki De.

  • Update statement using case

    Hello my friends
    I have one table "encompasses": continent,country,percentage
    now the update should change the continent field, all "Europe" to "Asia" and all "Asia" to "America" and "America" to "Europe" by using case and just one update statement.
    I wrote so and i got this error
    Error starting at line 2 in command:
    UPDATE encompasses
       SET continent=    
          CASE  WHEN continent='Europe'  THEN 'Asia'  
          WHEN continent='Asia'  THEN 'America' 
          WHEN continent='America' THEN 'Europe'
          END
    Error report:
    SQL Error: ORA-01407: cannot update ("intern"."ENCOMPASSES"."CONTINENT") to NULL
    01407. 00000 -  "cannot update (%s) to NULL"
    *Cause:   
    *Action:please give me hints,thank u.
    --  File created - Monday-May-13-2013  
      CREATE TABLE "intern"."ENCOMPASSES" ("COUNTRY" CHAR(2), "CONTINENT" VARCHAR2(20), "PERCENTAGE" NUMBER)
       COMMENT ON COLUMN "intern"."ENCOMPASSES"."COUNTRY" IS 'the country code'
       COMMENT ON COLUMN "intern"."ENCOMPASSES"."CONTINENT" IS 'the continent name'
       COMMENT ON COLUMN "intern"."ENCOMPASSES"."PERCENTAGE" IS 'percentage, how much of the area of a country belongs to the
                continent'
       COMMENT ON TABLE "intern"."ENCOMPASSES"  IS 'information to which continents a country belongs'
    REM INSERTING into intern.ENCOMPASSES
    SET DEFINE OFF;
    Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('cx','Asia',100);
    Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('eg','Asia',10);
    Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('ge','Asia',100);
    Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('id','Asia',100);
    Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('ad','Europe',100);
    Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('al','Europe',100);
    Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('at','Europe',100);
    Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('ba','Europe',100);
    Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('pa','America',100);
    Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('pe','America',100);
    Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('pm','America',100);
    Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('pr','America',100);
    Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('py','America',100);
    Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('sr','America',100);
    Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('sv','America',100);thank you, im using oracle 11g and ubuntu12
    best,david
    Edited by: 1003209 on 13-May-2013 10:12

    1003209 wrote:
    Hello my friends
    I have one table "encompasses": continent,country,percentage
    now the update should change the continent field, all "Europe" to "Asia" and all "Asia" to "America" and "America" to "Europe" by using case and just one update statement.
    I wrote so and i got this error
    Error starting at line 2 in command:
    UPDATE encompasses
        SET continent=    
           CASE  WHEN continent='Europe'  THEN 'Asia'  
           WHEN continent='Asia'  THEN 'America' 
           WHEN continent='America' THEN 'Europe'
           END
    Error report:
    SQL Error: ORA-01407: cannot update ("intern"."ENCOMPASSES"."CONTINENT") to NULL
    01407. 00000 -  "cannot update (%s) to NULL"
    *Cause:   
    *Action:This seems the column Continent has not null contraint on it, hence when there is a continent other than the three you mentioned above the case statement is evaluating it to null and hence failing e.g. if there is a record with continent = 'Antartica' it will try to update that as null.
    so either add this:
    WHERE continent in ('Europe' ,'Asia','America')this will update only for this continents and ignore other values.
    If you want to update other continents as well then have a else condition in CASE statement to assign defualt value.
    Regards,
    Santosh

  • Case and Decode query

    Hi,
    I am running below statement.
    create table test_abc
    (cnt number,
    outcome varchar2(20));
    insert into test_abc values(1,'EXISTINGDOMFUELCUST');
    insert into test_abc values(1,'Answer Phone');
    insert into test_abc values(1,'Answer Phone');
    insert into test_abc values(1,'Answer Phone');
    insert into test_abc values(1,'Answer Phone');
    insert into test_abc values(1,'Answer Phone');
    commit;
    Now I used case and decode
    select count(*),ot from (
    select (case when outcome ='EXISTINGDOMFUELCUST' then 'Existing Domestic Fuel Customer'
    when outcome='Answer Phone' then 'Answer Phone'
    when outcome='Answer Phone' then 'Answer Machine' end) ot
    from test_abc)
    group by ot;
    select count(*),decode(outcome,'EXISTINGDOMFUELCUST','Existing Domestic Fuel Customer','Answer Phone',
    'Answer Phone','Answer Phone','Answer Machine')
    from test_abc
    group by decode(outcome,'EXISTINGDOMFUELCUST','Existing Domestic Fuel Customer','Answer Phone',
    'Answer Phone','Answer Phone','Answer Machine')
    and getting same output
    cnt ot
    5 Answer Phone
    1 Existing Domestic Fuel Customer
    but I want output should be
    cnt ot
    5 Answer Phone
    5 Answer Machine
    1 Existing Domestic Fuel Customer
    please suggest

    Indra Budiantho wrote:
    /* Formatted on 8/28/2012 3:10:28 PM (QP5 v5.139.911.3011) */
    SELECT CASE
    WHEN outcome = 'EXISTINGDOMFUELCUST'
    THEN
    'Existing Domestic Fuel Customer'
    WHEN outcome = 'Answer Phone'
    THEN
    'Answer Phone'
    END
    outcome,
    COUNT (*)
    FROM test_abc
    GROUP BY outcome
    union
    SELECT CASE
    WHEN outcome = 'EXISTINGDOMFUELCUST'
    THEN
    'Existing Domestic Fuel Customer'
    WHEN outcome = 'Answer Phone'
    THEN
    'Answer Machine'
    END
    outcome,
    COUNT (*)
    FROM test_abc
    where outcome = 'Answer Phone'
    GROUP BY outcomeo/p
    Answer Machine     5
    Answer Phone     5
    Existing Domestic Fuel Customer     1This can be simplified..
    Also, UNION will unnecessarily do a distinct operation.
    SELECT CASE
                WHEN outcome = 'EXISTINGDOMFUELCUST'
                THEN
                   'Existing Domestic Fuel Customer'
                WHEN outcome = 'Answer Phone'
                THEN
                   'Answer Phone'
             END
                outcome,
             COUNT (*)
        FROM test_abc
    GROUP BY outcome
    union all
    SELECT 'Answer Machine'
                outcome,
             COUNT (*)
        FROM test_abc
        where outcome = 'Answer Phone'
    GROUP BY outcome

  • A Use Case question.

    Hello all
    I am currently developing an event management assignment for my degree.
    A subset of problem statment
    Attendee is a person, who would register with the application
    in order to view the posted events.
    For this part of the problem statment i have identified a usecase
    "register attendee".
    I will type the use case here. Since i am a novice, I would really like
    design gurus to throw some light on the use case and suggest me changes
    I will really appreciate it.
    Use case : register attendee
    Pre-condition: Attendee decides to register.
    Main Success Scenario:
         Actor                         System
    1. Attendee requests to register.
                        2. Provides registration form.
    3. Attendee fills the form and
    submits.                     
                        4. System checks for valid
                        authentication.
    (//for eg. unique username)
                        5. System validates the information
    (//for eg.compulsory fields
                             present or not)
                        6. System notifies through mail.
                        7. Displays registration was
                        successful.
    Alternative Flow :
    4 a) Invalid authentication : Displays appropriate message.
    5 a) Invalid information : Displays appropriate message.
    6 a) Mail notification failure : Logs the failure message and email.
    Please guide me friends. I am a bit confused.
    Thanks in advance.
    Jenny               

    Use case are pretty good for both of these. You know
    your system needs to allow an ATTENDEE to register
    with the SYSTEM using a REGISTRATION FORM. These sound
    like things that either you need to model (what
    attributes do the form and attendee have) or a thing
    that you need to build the "system".
    The steps in the use case tell you how the system must
    behave. It needs to "getRegistrationForm" and give it
    the attendee. The Attendee needs to
    "completeRegistrationForm" and
    "submitRegistrationForm". So, with the authentication
    and validation rounding out the process you have a
    good idea of what kind of methods you need as a base
    in order to deal with the real world concepts you have
    identified.I am through with what behaviour my system will need to provide in
    order to realize the use case. But I will have to assign the behaviour
    appropriately to classes of objects. I would like to go to the design model once i have a good understanding of the domain model. This is where the problem starts, should i identify, AuthenticationVerifier,InformationVerfier as different concepts and give later say AuthenticationVerifier the responsibility of verifying unique authentication and InformationVerfier the responsibility of verifying information received with the form or should I only take one concept of say Administrator that would perform the above two stated behaviours. I understand that it is always good to overspecify concepts rather than under specify but at some point of time i will have to make that decision.
    If its a libray system, it is easy to identify certain priliminary concepts say book, patron, etc. as they occupy some physical space. But here nothing is clear. There isn't any entity in my use case, that occupies a physical space that i can easily identify as a real world concept.
    My question is, how in this case, do someone define the notion of concept when there is nothing in the main success scenario that occupies space. My use case, only specifies what will be done with the
    attendee information, not who will do it. So as a use case developer, am i responsible to map these processes with some physical entities that i have derived for eg. AuthenticationVerfier.
    ps. You will need to add the Attendee as an Actor. She
    is the one that is initiating the activity.Does it mean that as Attendee is an actor, he/she cannot be a concept?

  • Use case export to text document

    In Jdeveloper you can export generated UML use case with scenarios, to HTML format, however is it possible to generate to say .txt or .doc type files?
    I am looking at a very good commercial product called Visual Use Case and wondered if JDeveloper's generated documentation has/can have similar features.
    Thank you

    Hi,
    there is SDE plugin for JDeveloper ( http://www.visual-paradigm.com/product/sde/jd/ ) but it only works with older - 10.1.2 version of JDev.
    Kuba

  • Code generation from use cases

    I have to build a system that inputs use cases and outputs code. I am as yet unsure how to do this. I assume the easiest way would be to go via class diagrams because code generation seems not a huge leap from there, but how would you suggest I get from the text use cases to a class diagram? Any help and pointers would be very very welcome.
    Cheers,
    Nicholas

    If you invent this, they will have to create a new Nobel prize for computing. And we as developers will all be out of business. Best of luck.
    - Saish

  • Regarding case and decode.

    Hi !
    I need to return all the employess, and indicate with "YES" or "NO" wherther they receive a commission.
    I am trying to get this by using CASE and DECODE but result is comming different.
    USING DECODE:
    SELECT ename,
    sal,
    DECODE(comm,NULL,'NO',
    'YES') COMM
    FROM emp;
    USING CASE:
    SELECT ename,
    sal,
    CASE comm
    WHEN NULL THEN 'NO'
    ELSE 'YES'
    END
    FROM emp;
    DECODE is returning actual data(comm is NO where comm is null and comm is YES where comm is not null). Where as CASE is retunring YES for all employees commission even comm is null..
    I am not able to understand where I was wrong.
    Can any one help me out?
    Thanks
    Rajesh

    Hi Rajesh,
    I tried to solve your query this way, check if it serves the purpose
    /***Using Decode***/
    SELECT EMPLOYEE_ID, DECODE(NVL(COMMISSION_PCT, 0), 0, 'NO', 'YES')
    FROM EMPLOYEES
    /****Using Case***/
    SELECT EMPLOYEE_ID, CASE NVL(COMMISSION_PCT, 0)
    WHEN 0 THEN 'NO'
    ELSE 'YES'
    END CASE
    FROM EMPLOYEES
    /

  • Get runtime class and cast object to it?

    Hi,
    public interface Msg
    Msg msg=msgLib.get(msgType);
    Msg msg2=msg.clone(); //problem! cannot find clone in  x.y.Msg!
    ...Shouldn't msg be resolved to the implementing class (MsgReply for example) and use the "clone()" method, that i have declared in that class -which overrides the one of Object class?
    If no, is there a way to find the runtime class -probably use "getClass"- and cast to it? How?
    Thanks

    There are many implementing classes; i want to get the runtime class. Something like:
    (msg.getClass())msg.clone();
    Message was edited by:
    uig

Maybe you are looking for