In PL/SQL CASE statement

Hi experts, PL/SQL,.

I'm going a little crazy here, so could someone please point out what I am doing wrong with this case statement:

Test procedure is:

CREATE or REPLACE procedure SCOTT.postcode_validate_2 (input_post_code VARCHAR2) as


alphabet_string VARCHAR2 (52): = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxwyz";
number_string VARCHAR2 (10): = '012345789';
last_part_postcode VARCHAR2 (3): = NULL;

BEGIN


IF INSTR (input_post_code,' ') = 0
THEN
DBMS_OUTPUT. Put_line ("' it takes a space in the zip code please");
GOTO end;
ELSIF LENGTH (SUBSTR (input_post_code, instr (input_post_code,' ') + 1)) > 3
THEN
DBMS_OUTPUT. Put_line ("the last part of the postcode can be 3 characters");
GOTO end;
ON THE OTHER

last_part_postcode: = SUBSTR (input_post_code, instr (input_post_code,' ') + 1);
END IF;


CASE input_post_code

WHEN (length (substr (input_post_code, 1, instr(input_post_code,' ')-1)) = 2)
AND instr (alphabet_string, substr(input_post_code,1,1)). = 0
AND instr (number_string, substr(input_post_code,2,1)). = 0)
THEN
DBMS_OUTPUT. Put_line ('we have a valid postal code in the format A9')
-OTHER
-DBMS_OUTPUT. Put_line ("sorry, but this is an incorrect postal code!") Format A9');
-GOTO end;
-END IF;

WHEN (length (substr (input_post_code, 1, instr(input_post_code,' ')-1)) = 3)
AND instr (alphabet_string, substr(input_post_code,1,1)). = 0
AND instr (alphabet_string, substr(input_post_code,2,1)). = 0
AND instr (number_string, substr(input_post_code,3,1)). = 0)
THEN
DBMS_OUTPUT. Put_line ('we have a valid postal code in the format AA9')
-OTHER
-DBMS_OUTPUT. Put_line ("sorry, but this is an incorrect postal code!") AA9 format');
-GOTO end;
-END IF;

WHEN (length (substr (input_post_code, 1, instr(input_post_code,' ')-1)) = 3)
AND instr (alphabet_string, substr(input_post_code,1,1)). = 0
AND instr (number_string, substr(input_post_code,2,1)). = 0
AND instr (number_string, substr(input_post_code,3,1)). = 0)
THEN
DBMS_OUTPUT. Put_line ('we have a valid postal code in the A99 format')
-OTHER
-DBMS_OUTPUT. Put_line ("sorry, but this is an incorrect postal code!") A99 format');
-GOTO end;
-END IF;

WHEN (length (substr (input_post_code, 1, instr(input_post_code,' ')-1)) = 3)
AND instr (alphabet_string, substr(input_post_code,1,1)). = 0
AND instr (number_string, substr(input_post_code,2,1)). = 0
AND instr (alphabet_string, substr(input_post_code,3,1)). = 0)
THEN
DBMS_OUTPUT. Put_line ('we have a valid postal code in the format A9A')
-OTHER
-DBMS_OUTPUT. Put_line ("sorry, but this is an incorrect postal code!") A9A format');
-GOTO end;
-END IF;

WHEN (length (substr (input_post_code, 1, instr(input_post_code,' ')-1)) = 4)
AND instr (alphabet_string, substr(input_post_code,1,1)). = 0
AND instr (alphabet_string, substr(input_post_code,2,1)). = 0
AND instr (number_string, substr(input_post_code,3,1)). = 0
AND instr (number_string, substr(input_post_code,4,1)). = 0)
THEN
DBMS_OUTPUT. Put_line ('we have a valid postal code in the format AA99')
-OTHER
-DBMS_OUTPUT. Put_line ("sorry, but this is an incorrect postal code!") AA99 format');
-GOTO end;
-END IF;

WHEN (length (substr (input_post_code, 1, instr(input_post_code,' ')-1)) = 4)
AND instr (alphabet_string, substr(input_post_code,1,1)). = 0
AND instr (alphabet_string, substr(input_post_code,2,1)). = 0
AND instr (number_string, substr(input_post_code,3,1)). = 0
AND instr (alphabet_string, substr(input_post_code,4,1)). = 0)
THEN
DBMS_OUTPUT. Put_line ('we have a valid postal code in the format AA9A')
-OTHER
-DBMS_OUTPUT. Put_line ("sorry, but this is an incorrect postal code!") AA9A format');
-GOTO end;
-END IF;
END;


-Check the last part of the format, should be AA9
IF (instr (number_string, substr(input_post_code,1,1))! = 0)
AND instr (alphabet_string, substr(input_post_code,2,1)). = 0
AND instr (alphabet_string, substr(input_post_code,3,1)). = 0)
THEN
DBMS_OUTPUT. Put_line ('end part of the code postal is the appropriate format, 9AA');
ON THE OTHER
DBMS_OUTPUT. Put_line ("' end part of the postcode is in a wrong format!");
END IF;

< < output > >
DBMS_OUTPUT. Put_line ("Please try again");
END;
/

However, I get the following error:

LINE/COL ERROR
-------- -----------------------------------------------------------------
37/6 PLS-00103: encountered the symbol "WHEN" what awaits an of
What follows:
:= . ( % ;

On a second note, can't be incorporated into the (currently commented) case ELSE structure?

Thank you very much in advance.

Dev

The initial error was just a problem with your procedure. The other has to do with how you use the CASE statement.
The code seems a bit long for what you're trying to do. Could you describe what your needs are?

Tags: Database

Similar Questions

  • Using SQL case statement

    I have a table as follows. The return of the role-based query. If the role is 'a', the result should be abc, edf, and xxx. If the role is b results should be abc, yyy. When the role is * (all) then means that the results should be possible all the code.
    role of Code
    an abc
    an edf
    a xxx
    abc b
    b yyy
    c     *

    I'm trying to build something like this, but it gives me the error. Could someone help me?
    Select the case ID when ' *' then (select Code separate from table_name)
    end
    table_name from where role =: input_role

    Thank you very much!

    Hello

    I think I uderstand. Try this:

    SELECT  xxx, yyy, zzz
    FROM      another_table a
    WHERE      a.code           IN (
                              SELECT  CASE
                                     WHEN  b.code = '*'
                             THEN  a.code
                             ELSE  b.code
                             END
                        FROM    this_table b
                        WHERE   b.role = :input_from_user
                    )
    ;
    

    NULL in (...) is never true, so I assume that you do not want to include all rows where another_table.code is NULL, even if the subquery is a ' *'.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data. Give some examples of: input_from_user and the resutls, you want the same data for each of them.
    Explain, using specific examples, how you get these results from these data.
    Another_table.code can be null? Is there any value (such as ' ~? ~') that you can never occurs in another_table.code? The combination (xxx, yyy, zzz) is unique in another_table?
    Always tell what version of Oracle you are using.

  • Problem in the counting by SQL case statement

    I have a table with 3 columns-

    create table execution_stg)
    number of alc_td_id
    number of exe_td_id
    src_sys varchar2 (50)
    )

    I want to get the number of records with alc_td_id not null and not null exe_td_id and total count by src_sys.

    When to use a query like this-

    SELECT src_sys,
    CASE
    WHEN alc_td_id IS NOT NULL
    THEN THE SUM (1)
    END as alc_ac_cnt,
    CASE
    WHEN exe_td_id IS NOT NULL
    THEN THE SUM (1)
    END AS td_ac_cnt, COUNT (*) AS total_cnt
    Of execution_stg
    GROUP BY src_sys


    I get ORA-00979 - isn't a group by expression.

    What should I do?

    Thank you
    -Christian Plantier S

    Edited by: girija_pathak may 3, 2010 12:55

    Edited by: girija_pathak may 3, 2010 13:05

    Never mind...

    Edited by: AlanWms may 3, 2010 16:09

  • using the case statement


    Hello

    How can I convert a code for the below sql case statement:

    If)

    (length of (tmp_co_orig_val) < = 0 OR tmp_co_orig_val < = 0 OR tmp_co_orig_val == 1 OR tmp_co_orig_val > = 9999999)

    OR

    ((tmp_co_orig_val == 999999 AND (length of (tmp_rcr_orgn_ltv_rt) < = 0 OR tmp_rcr_orgn_ltv_rt < tmp_rcr_orgn_ltv_rt > 1.3 GOLD 0.15)))

    Start

    tmp_collatvalue = «»

    tmp_msg_cd = 115

    end

    Is the case statement below that I wrote is correct. I don't have an environment now to test.  Please advice.

    BOX WHEN (CHAR_LENGTH (tmp_co_orig_val) < = 0 OR tmp_co_orig_val < 0 OR tmp_co_orig_val = 1 OR tmp_co_orig_val = > = 9999999)

    OR (tmp_co_orig_val = 999999 AND (CHAR_LENGTH (tmp_rcr_orgn_ltv_rt) < = 0 OR tmp_rcr_orgn_ltv_rt < tmp_rcr_orgn_ltv_rt > 1.3 GOLD 0.15))

    THEN tmp_collatvalue IS NULL AND tmp_msg_cd = 115

    END

    Hello

    937454 wrote:

    Thanks Frank. Really helps. But I have to write a sql statement

    But can you also specify, if I made a mistake in my code, or it's ok.

    There are no CASES reported in Oracle SQL.

    Oracle SQL has BOX expressions, but they only return a single value.  You cannot set 2 columns in the same expression BOX.

    Perhaps the best thing to do in pure SQL for you is to write a CASE expression, very similar to the CASE statement above, in a subquery and use the results of this in 2 separate expressions of BOX (very simple) in a Super application.

  • Case statement in the SQL Query prompt dashboard

    Hi Experts,

    I use the following case statement to generate default values in the prompt dashboard based on a condition (the other guest-generated values). Below are two of the query I've tried and the syntax error. I tried all the possibilities (like giving apostrophes, double quotes, don't quote not etc.), but could not understand the question. Don't know what exactly I'm missing here.

    Query 1:

    SELECT

    CASE

    WHEN @{PRType} = monthly THEN 'Participant pay '. "" Amount of PayRate "="15000"

    WHEN @{PRType} = daily THEN 'Participant pay '. "" Amount of PayRate "="650"

    WHEN @{PRType} = hourly THEN 'Participant pay '. "" Amount of PayRate "="1"

    ELSE ' 0'

    END

    OF 'PA-Participant pay. '

    Query 2:

    SELECT

    CASE

    WHEN @{PRType} = monthly THEN "15000"

    WHEN @{PRType} = daily THEN "650"

    @{PRType} = schedule THEN '1'

    ELSE ' 0'

    END

    OF 'PA-Participant pay. '

    This is the query that is generated in the log with error message file.

    1 log message:


    SELECT CASE WHEN Hourly = Monthly THEN "Participant Payroll"."Payrate Amount" = '15000' WHEN Hourly = Daily THEN "Participant Payroll"."Payrate Amount" = '650' WHEN Hourly = Hourly THEN "Participant Payroll"."Payrate Amount" = '1' ELSE '0' END FROM "PA-Participant Payroll"

    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 43113] The message returned by OBIS. [nQSError: 27002] Near <>=: Syntax error [nQSError: 26012]. (HY000)



    Comment 2:

    ;CASE WHEN To_Char (Hourly) = 'Hourly' THEN 1 ELSE 0 END 

    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 43113] The message returned by OBIS. [nQSError: 27002] Near <>(): syntax error [nQSError: 26012]. (HY000)

    Sorry, I wasn't clear... you must always put this CASE statement in a valid SQL SELECT statement.

    SELECT

    CASE

    When ' @{PRType}' = 'Monthly' THEN '15000'

    When ' @{PRType}' = 'Daily' THEN '650'

    ELSE '0' END

    OF 'PA-Participant pay. '

  • Problem SQL querry (case statement...)

    Hi to everyone who reads this.

    I have a huge problem (at least for me) with a SQL I try to write in Oracle forms6 (yes I know... old app).

    OK, here it goes...

    We have a table like:
    create table temp (
      year     number 
      month    number,
      konto    number,
      DEBET    number, 
      KREDIT   number,
      date_tr  date,
      ind      number
    );
    The data in the table are:
     YEAR        MONTH    KONTO      DEBET     KREDIT DATE_TR  IND
    ---------- ---------- ----- ---------- ---------- -------- -
          2011          1 12101   4674,32           0 05.06.11
          2011          6 12101  -4674,32           0 05.06.11 R
          2011          6 12182   4674,32           0          R
    Now, to explain a little what I want to do...
    case when p_date > NVL(date_tr,'01012004') then
    date_tr is null;
    else
    ind is null
    end
    What I need is when p_date is entered by a user SQL should check if the date is less or greater than date_tr...
    in this case it should show only the record that has a null value in date_tr cullum.

    Or if it isn't... it should display records which is null in ind cullum.


    The main problem is that I do not know how to write the case statement in SQLs where clause... maybe someone can give me a hint
    or a partial code how do I solve this problem.

    Any ideas would be greatly apreciated.

    Thanks to you all!
    SQL> with temp as
      2  (select 2011 YEAR,1 MONTH, 12101 KONTO, 4674,32 DEBET, 0 KREDIT, to_date('05.06.11','DD.MM.YY') DATE_TR, NULL IND from dual union all
      3  select 2011, 6, 12101, -4674,32, 0, to_date('05.06.11','DD.MM.YY'), 'R' from dual union all
      4  select 2011, 6, 12182,  4674,32, 0, NULL, 'R' from dual
      5  )
      6  SELECT *
      7  FROM   temp
      8  WHERE  CASE
      9           WHEN To_date('&dt, 'DD.MM.YYYY') > (SELECT MAX(date_tr)
     10                                               FROM   temp) THEN To_char(date_tr)
     11           ELSE ind
     12         END IS NULL;
    Enter value for dt: 30.06.2011
    
          YEAR      MONTH      KONTO       4674      DEBET     KREDIT DATE_TR   I
    ---------- ---------- ---------- ---------- ---------- ---------- --------- -
          2011          6      12182       4674         32          0           R
    
    SQL> /
    Enter value for dt: 30.05.2011
    
          YEAR      MONTH      KONTO       4674      DEBET     KREDIT DATE_TR   I
    ---------- ---------- ---------- ---------- ---------- ---------- --------- -
          2011          1      12101       4674         32          0 05-JUN-11
    
    SQL>
    
  • CASE in SQL Server statement

    I'm working on a project for ambulance response times. In the following query, which is in my coldfusion code, I use a CASE statement on a subquery to count of ambulance response times in stores. An ambulance should arrive at an incident of emergency in less than 08:59 (539 seconds), otherwise it is considered to be late. In my coldfusion Transact-SQL code, I am:
    1.) is a subquery.
    2.) counting "number of events"time-based, it took the ambulance to arrive. "
    3.) only count the ambulances of Lee County and excluding A6 type (non-emergency) calls.
    (4.) grouping of date parts.

    SELECT DATENAME ("M", I.I_tTimeDispatch) in the month, (DATEPART ("yyyy", I.I_tTimeDispatch)) AS year,.
    COUNT (CASE WHEN (DATEDIFF ("S", I.I_tTimeDispatch, I.I_tTimeArrival)) BETWEEN 0 AND 539 SO evnt END) AS OnTime.
    COUNT (CASE WHEN (DATEDIFF ("S", I.I_tTimeDispatch, I.I_tTimeArrival)) BETWEEN 540 AND 1028 THEN evnt END) AS of late.
    COUNT (CASE WHEN (DATEDIFF ("S", I.I_tTimeDispatch, I.I_tTimeArrival)) > 1028 THEN evnt END) AS aberrant
    (SELECT I_EventNumber AS evnt, I_tTimeDispatch, I_tTimeArrival, I_kTypeInfo, I_Agency FROM dbo. IIncident) as I
    INNER JOIN dbo. ITypeInfo AS T ON I.I_kTypeInfo = T.ITI_TypeInfo_PK
    WHERE I.I_Agency = 'LC'
    AND T.ITI_TypeID NOT LIKE ' A6. "
    GROUP BY (DATEPART ("M", I.I_tTimeDispatch)), (DATENAME ("M", I.I_tTimeDispatch)), (DATEPART ("yyyy", I.I_tTimeDispatch))
    ORDER BY (DATEPART ("yyyy", I.I_tTimeDispatch)) ASC, ASC (DATEPART ("M", I.I_tTimeDispatch))

    Here's my problem!
    I go in Microsoft Access to check my stats and I get different counts. For example, in April 2008, my coldfusion query returns 3 944 response ambulance in time. My query Access for the same period of time, using only ambulances in Lee County and excluding non A6-emergency returns only 3 805 answers. There is an undercounting of 139 responses. Even for my other tanks of the time, I get a undercount.

    Here is my SQL Access to the tray of response time (< seconds 539 or 08:59):

    SELECT Count (dbo_IIncident.I_EventNumber) AS CountOfI_EventNumber
    FROM dbo_IIncident INNER JOIN dbo_ITypeInfo ON dbo_IIncident.I_kTypeInfo = dbo_ITypeInfo.ITI_TypeInfo_PK
    WHERE (((dbo_IIncident.I_Agency) = "lc") AND ((dbo_ITypeInfo.ITI_TypeID) not as ' a6 * ') AND ((dbo_IIncident.I_tTimeDispatch) between # #4/1/2008 and may 1, 2008 #) AND ((DateDiff ("s", [dbo_IIncident].) [I_tTimeDispatch], [dbo_IIncident]. [I_tTimeArrival])) Between 0 and 539));

    How two queries that are supposed to do the same could return different results?


    In order to dispel any confusion, I write the page temporarily. Please look at because it can help you visualize the problem.
    http://lcfcfn01/secure/GTandLT_8_59.cfm

    Instead of counting, why don't you change your SQL to list the incidents in the two queries instead, then you can see who is included in the T - SQL that are not captured in Access code.

    Phil

  • Help with making SQL query references to column aliases in the Case statement

    I need help with a sql query that I'm trying. I can go about it the wrong way, but I would be grateful if I could get any suggestions on possible solutions. This is my query:


    SELECT DISTINCT spriden_pidm, spriden_id id, spriden_last_name | ',' | spriden_first_name name,

    CASE
    WHEN rcresar_comm_code_01 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_01
    WHEN rcresar_comm_code_02 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_02
    WHEN rcresar_comm_code_03 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_03
    WHEN rcresar_comm_code_04 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_04
    WHEN rcresar_comm_code_05 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_05
    WHEN rcresar_comm_code_06 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_06
    WHEN rcresar_comm_code_07 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_07
    WHEN rcresar_comm_code_08 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_08
    WHEN rcresar_comm_code_09 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_09
    WHEN rcresar_comm_code_10 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_10
    END acg_elig_comm_code

    CASE
    WHEN acg_elig_comm_code = ' 268' THEN 'rigorous HS course. "
    WHEN acg_elig_comm_code = '269' THEN ' 2 or several AP or IB"
    WHEN acg_elig_comm_code = '270' THEN 'NOC as possible ".
    END comm_code_description

    OF spriden, rcresar, rcrapp1

    WHERE (rcresar_comm_code_01 IN ('268 ', '269', ' 270')

    OR rcresar_comm_code_02 ('268 ', '269', ' 270')

    OR rcresar_comm_code_03 ('268 ', '269', ' 270')

    OR rcresar_comm_code_04 ('268 ', '269', ' 270')

    OR rcresar_comm_code_05 ('268 ', '269', ' 270')

    OR rcresar_comm_code_06 ('268 ', '269', ' 270')

    OR rcresar_comm_code_07 ('268 ', '269', ' 270')

    OR rcresar_comm_code_08 ('268 ', '269', ' 270')

    OR rcresar_comm_code_09 ('268 ', '269', ' 270')

    OR rcresar_comm_code_10 ('268 ', '269', ' 270'))


    Rcresar_aidy_code = & aidy_code

    AND rcrapp1_aidy_code = rcresar_aidy_code

    AND rcrapp1_curr_rec_ind = 'Y '.

    AND rcrapp1_seq_no = rcresar_seq_no


    AND spriden_pidm = rcresar_pidm

    AND rcrapp1_pidm = rcresar_pidm


    AND spriden_change_ind IS NULL

    ORDER BY name


    The second case statement is where I don't know exactly what it takes to get what I want.

    Output should be like:
    spriden_pidm name ID acg_elig_comm_code comm_code_description
    «0000000000', ' 1111111111 ","John Doe","268", «rigorous HS race"»

    If I take the second case statement it works great except that I do not have my comm_code description column. My question is how can I use my first statement value box to determine this column? I think that I need a case statement as I have, but I don't know how to reference the value of acg_elig_comm_code. Any help would be greatly appreciated. Thank you.

    Published by: blackhole82 on January 20, 2009 09:20

    Hello

    You cannot use the alias column in the query, even where it is set (except in the ORDER BY clause).
    You can set the alias in a subquery and then use it in a great query, like this:

    WITH  sub_q  AS
    (
        SELECT DISTINCT spriden_pidm,spriden_id id, spriden_last_name||', '||spriden_first_name name,
            CASE
                WHEN rcresar_comm_code_01 IN ('268','269','270') THEN rcresar_comm_code_01
                WHEN rcresar_comm_code_02 IN ('268','269','270') THEN rcresar_comm_code_02
                WHEN rcresar_comm_code_03 IN ('268','269','270') THEN rcresar_comm_code_03
                WHEN rcresar_comm_code_04 IN ('268','269','270') THEN rcresar_comm_code_04
                WHEN rcresar_comm_code_05 IN ('268','269','270') THEN rcresar_comm_code_05
                WHEN rcresar_comm_code_06 IN ('268','269','270') THEN rcresar_comm_code_06
                WHEN rcresar_comm_code_07 IN ('268','269','270') THEN rcresar_comm_code_07
                WHEN rcresar_comm_code_08 IN ('268','269','270') THEN rcresar_comm_code_08
                WHEN rcresar_comm_code_09 IN ('268','269','270') THEN rcresar_comm_code_09
                WHEN rcresar_comm_code_10 IN ('268','269','270') THEN rcresar_comm_code_10
            END acg_elig_comm_code   -- Originally posted with , here (error)
        FROM spriden, rcresar, rcrapp1
        WHERE (rcresar_comm_code_01 IN ('268','269','270')
                OR rcresar_comm_code_02 IN ('268','269','270')
                OR rcresar_comm_code_03 IN ('268','269','270')
                OR rcresar_comm_code_04 IN ('268','269','270')
                OR rcresar_comm_code_05 IN ('268','269','270')
                OR rcresar_comm_code_06 IN ('268','269','270')
                OR rcresar_comm_code_07 IN ('268','269','270')
                OR rcresar_comm_code_08 IN ('268','269','270')
                OR rcresar_comm_code_09 IN ('268','269','270')
                OR rcresar_comm_code_10 IN ('268','269','270'))
        AND rcresar_aidy_code = &aidy_code
        AND rcrapp1_aidy_code = rcresar_aidy_code
        AND rcrapp1_curr_rec_ind = 'Y'
        AND rcrapp1_seq_no = rcresar_seq_no
        AND spriden_pidm = rcresar_pidm
        AND rcrapp1_pidm = rcresar_pidm
        AND spriden_change_ind IS NULL
    )
    SELECT    sub_q.*,
              CASE
                  WHEN acg_elig_comm_code = '268' THEN 'Rigorous HS course'
                  WHEN acg_elig_comm_code = '269' THEN '2 or more AP or IB'
                  WHEN acg_elig_comm_code = '270' THEN 'ACG possible'
              END comm_code_description
    FROM      sub_q
    ORDER BY  name
    

    Furthermore, you might think to rearrange your table, so that you do not have 10 columns (rcresar_comm_code_01, rcresar_comm_code_02,...) that essentially do the same thing. The usual way to handle this kind of one-to-many relationship is to have all rcresar_comm_codes in a separate table, one per line, with a pointer to the table where you have them now.

    Published by: Frank Kulash, January 20, 2009 11:35
    Syntax error has been corrected

  • Case statement in the process Page

    Request Express 3.2.1.00.11

    I put the following code in an anonymous block (will return no error) for a process Page;

    BEGIN
    INSERT
      INTO DAD_ASSESSMENT_REQUEST
    ( tenure_id
    , client_id
    )
    VALUES
    ( :P10101_TENURE_ID
    , :P10101_CLIENT_ID 
    );
    END;
    

    But when I put a statement case it throws the following error;

    1 error has occurred
    ORA-06550: line 7, column 3: PL/SQL: ORA-01747: invalid user.table.column, table.column, or column specification ORA-06550: line 3, column 1: PL/SQL: SQL Statement ignored
    

    BEGIN
    INSERT
      INTO DAD_ASSESSMENT_REQUEST
    ( tenure_id
    , client_id
    , (CASE 
       WHEN (:P10101_MEASURE_OPTION = 'AREA') THEN estimated_area_ha 
       WHEN (:P10101_MEASURE_OPTION = 'LINE') THEN estimated_length_km 
     END)
    )
    VALUES
    ( :P10101_TENURE_ID
    , :P10101_CLIENT_ID 
    , :P10101_X
    );
    END;
    

    Why is this code not work and it is possible to use a case statement in a Page Apex process

    Concerning

    Ben

    Benton says:

    Request Express 3.2.1.00.11

    I put the following code in an anonymous block (will return no error) for a process Page;

    1. BEGIN
    2. INSERT
    3. IN DAD_ASSESSMENT_REQUEST
    4. (tenure_id
    5. client_id
    6. )
    7. VALUES
    8. (: P10101_TENURE_ID)
    9. ,: P10101_CLIENT_ID
    10. );
    11. END;

    But when I put a statement case it throws the following error;

    1. 1 error has occurred
    2. ORA-06550: line 7, column 3: PL/SQL: ORA-01747: specification user.table.column, table.column or invalid column ORA-06550: line 3, column 1: PL/SQL: statement ignored
    1. BEGIN
    2. INSERT
    3. IN DAD_ASSESSMENT_REQUEST
    4. (tenure_id
    5. client_id
    6. (CASE
    7. WHEN (: P10101_MEASURE_OPTION = 'SPACE') THEN estimated_area_ha
    8. WHEN (: P10101_MEASURE_OPTION = 'LINE') THEN estimated_length_km
    9. END)
    10. )
    11. VALUES
    12. (: P10101_TENURE_ID)
    13. ,: P10101_CLIENT_ID
    14. ,: P10101_X
    15. );
    16. END;

    Why is this code not work and it is possible to use a case statement in a Page Apex process

    Of course, it is possible to use a CASE statement or expression (it is the latter) in a page APEX process. However, it is not possible to use an invalid syntax while doing so. Part of a clause INSERT INTO can contain only static column names.

    In general the SQL expressions (and also the bind variable, another cause frequent errors of syntax) can be used only in

    • the projections of the SELECT queries and subqueries
    • the right side of the disposals in the SET update clause
    • the lists of VALUES of INSERTs
    • WHERE clause predicates

    ReemaPuri wrote:

    Try this

    INSERT

    IN DAD_ASSESSMENT_REQUEST

    (tenure_id

    client_id

    estimated_area_ha

    estimated_length_km

    )

    VALUES

    (: P10101_TENURE_ID)

    ,: P10101_CLIENT_ID

    , (SELECT CASE WHEN: P10101_MEASURE_OPTION = 'SPACE' AND THEN: P10101_X)

    OTHERWISE, NULL END OF DOUBLE)

    , (SELECT CASE WHEN: P10101_MEASURE_OPTION = 'LINE' THEN: P10101_X)

    OTHERWISE, NULL END OF DOUBLE)

    );

    It's a good idea, but it can be simplified, eliminating unnecessary subqueries:

    insert into dad_assessment_request (
        tenure_id
      , client_id
      , estimated_area_ha
      , estimated_length_km)
    values (
        :p10101_tenure_id
      , :p10101_client_id
      , case
          when :p10101_measure_option = 'AREA' then :p10101_x
        end
      , case
          when :p10101_measure_option = 'LINE' then :p10101_x
        end);
    
  • Case statement

    Hi all

    I wrote the code that gives the same number below:

    Select

    Count (case when dm_recd_load_dt < add_months(sysdate,-12) then 1 else 0 end) as count_recd_ly,

    Count (case when dm_recd_load_dt < end (sysdate) then 1 else 0) as count_recd

    of cr_customer

    where nvl (primary_cust_flag, 'Y') = 'Y '.

    and the brand = 'The Commission'

    Hello

    Whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) of all the tables involved, so that people who want to help you can recreate the problem and test their ideas.

    Also post the exact results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.

    Post earlier in this forum.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

    2849981 wrote:

    Hi all

    I wrote the code that gives the same number below:

    Select

    Count (case when dm_recd_load_dt< add_months(sysdate,-12)="" then="" 1="" else="" 0="" end)="" as="">

    Count (case when dm_recd_load_dt< (sysdate)="" then="" 1="" else="" 0="" end)="" as="">

    of cr_customer

    where nvl (primary_cust_flag, 'Y') = 'Y '.

    and the brand = 'The Commission'

    Remember that ACCOUNT (exp) done: it returns the number of lines where the expression exp is not NULL.  Neither 1 nor 0 have the value NULL, then

    COUNT (CASE WHEN... THEN 0 OTHERWISE 1 END)

    is equivalent to

    COUNT (*)

    Perhaps you meant

    Count (case when dm_recd_load_dt)< add_months="" (sysdate,-12)="" then="" 1="" end) ="" as="">

    Count (case when dm_recd_load_dt)<            (sysdate)    ="" then="" 1="" end) ="" as="">

    She a CASE expression is not a clause ELSE, ELSE NULL by default.

    Moreover, these are CASES expressions.  A CASE statement is something else, found in PL/SQL, but not in SQL.

  • Syntax of the case statement / WHEN

    The table I use a depreciation per fiscal year and the fiscal period.  I try to have the amount of depreciation to go to 2 different columns based on the fiscal year and the fiscal year.  I'm doing it with a nested case statement. I know that is not correct, because I get the message ORA-00905.  I'm relatively new to sql and it is contribtuing to my problem as well.  Here is the code I have and suggestions / corrections would be appreciated.  Thanks for the help...

    SELECT

    lao PDR. DEPTID as DEPTID,

    lao PDR. ASSET_ID as ASSET_NO,

    PA. Descr as DESCRIPTION,

    lao PDR. ACCOUNT_AD as AD_ACCT,

    PDL. DE_ACCT, to take into ACCOUNT

    lao PDR. ADEATH as AMT_DEPR,

    PDL. JOURNAL_ID as JRNL_ID,

    PDL. JOURNAL_DATE as JRNL_DT,

    lao PDR. FISCAL_YEAR as FY,

    lao PDR. ACCOUNTING_PERIOD AP,

    CASE

    WHEN RDP. FISCAL_YEAR = 2014 THEN

    WHEN RDP. PERIOD ACCOUNTANT = 11 THEN pdr. DEPR

    END AS CURR_MONTH,

    CASE

    WHEN RDP. FISCAL_YEAR <>2014

    WHEN RDP. ACCOUNTING PERIOD <>11 THEN pdr. DEPR

    END AS PRIOR_MONTH

    OF PS_DEPR_RPT pdr

    INNER JOIN PS_DIST_LN pdl

    THE pdl. BOOK = pdr. BOOK

    AND pdl. BUSINESS_UNIT = pdr. BUSINESS_UNIT

    AND pdl. FISCAL_YEAR = pdr. FISCAL_YEAR

    AND pdl. ACCOUNTING_PERIOD = pdr. ACCOUNTING_PERIOD

    AND pdl. ASSET_ID = pdr. ASSET_ID

    AND pdl. CF_SEQNO = pdr. CF_SEQNO

    INNER JOIN PS_ASSET PA

    WE pa. ASSET_ID = pdl. ASSET_ID

    AND pa. BUSINESS_UNIT = pdl. BUSINESS_UNIT

    WHERE

    lao PDR. BUSINESS_UNIT = "A0465.

    AND pdr. BOOK = 'RUN '.

    AND ((pdr. FISCAL_YEAR = 2014 AND pdr. ACCOUNTING_PERIOD = 11) OR (pdr. FISCAL_YEAR = 2014 AND pdr. ACCOUNTING_PERIOD = 10))

    Hello

    2713822 wrote:

    Thank you... I appreciate the information you provide when you answer these questions.  I always try to get the amount (from the same column) for 2 rows in different columns.  I tried the LAST_VALUE and LAG but it took a long time for the queries to run, I'm looking for another way to do the same.  I'm only using SQL to retrieve data.  I don't have the ability to create or insert.

    I looked the information above and the CASE statement to look like this:

    CASE

    WHEN RDP. FISCAL_YEAR = 2014

    AND pdr. ACCOUNTING_PERIOD = 11

    THEN the RDP. ADEATH AS CURR_MONTH

    ON THE OTHER

    lao PDR. ADEATH AS MONTHS PREVIOUS

    END

    But I'm now getting an "ORA-00905: lack of keyword" message.

    What I'm trying to do is to draw 2 lines 1 to 2014 / 11 and another for 2014 / 10.  The amount for the period 2014 / 11 should go in the current column and the amount for the period 2014 / 10 should go in the previous column.

    Before current assets management

    01 AB01 50.01 50.03

    ....

    If you want to give an alias for a column, then you can say "AS nome_alias" after that tell you what that is in this column.

    'AS nome_alias' applies to the entire column.  Cannot use 'alias_name' in the middle of an expression, for example, in the middle of a CASE expression, before the END keyword.

    If you want to have 2 separate output columns, curr_month and prior_month to your output, you must then 2 separate columns in your SELECT clause.  for example:

    SELECT pdr.branch

    pdr.asset

    CASE

    WHEN pdr.fiscal_year = 2014

    AND pdr.accounting_period = 11

    THEN pdr.depr

    END AS curr_month

    CASE

    WHEN...

    THEN...

    END AS prior_month

    PDR

    ;

    If post you some sample data (CREATE TABLE and INSERT statements), the results and explanations, I could show you how to complete the... sections.

    To find out what version of Oracle you have, use

    SELECT *.

    SINCE the release of v$.

    The output can be messy, like this:

    BANNER

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

    CON_ID

    ----------

    12 c Oracle database Release 12.1.0.1.0 - 64 bit Production

    0

    PL/SQL Release 12.1.0.1.0 - Production

    0

    CORE Production 12.1.0.1.0

    0

    AMT for 64-bit Windows: Version 12.1.0.1.0 - Production

    0

    NLSRTL Version 12.1.0.1.0 - Production

    0

    The important thing is the number 5 parts on the first line; 12.1.0.1.0 in the example above.

  • 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

  • Error "Command not properly ended SQL" CASES

    This error is driving me crazy... I have read several threads and google it so much, I am sure its obvious that miss me, but can someone help to point out? I get the not properly completed "SQL command" error and its location the | just before the case statement. Here's my request, I haven't posted a CREATE TABLE because I think it's just my syntax is incorrect?

    SELECT

    f.CT_ID,

    f.BUSINESS,

    f.CT_DS,

    d.ETL_DT,

    d.ACTIVITY_DT,

    d.MINUTE_KEY,

    d.FCST_CONTACTS_RECEIVED

    Of

    (LIGHTHOUSE. IEX_CT_DIM b

    JOIN INTERNAL LIGHT. D THE IEX_CTACTIVEFORECAST (b.CT_KEY = d.CT_KEY))

    JOIN INTERNAL LIGHT. TBL_GEN_CT_BUSINESS f

    WE (f.CT_ID = b.CT_ID)

         || CASE WHEN F.CT_DS = END "THI Spanish' THEN 'MODERATE_NR' AND

    (f.BUSINESS IN ('THI_PL', 'THI_ESC')) AND

    (d.ACTIVITY_DT BETWEEN TO_DATE)

    27 January 2014 00:00:00 ',

    "MM/DD/YYYY hh24:mi:ss")

    AND TO_DATE)

    27 April 2014 00:00:00 ',

    "MM/DD/YYYY hh24:mi:ss")) AND

    (f.EFF_DT = TO_DATE)

    29 January 2014 00:00:00 ',

    "MM/DD/YYYY hh24:mi:ss")) AND

    d.ETL_DT = (SELECT

    MAX (ETL_DT)

    Of

    LIGHTHOUSE. IEX_CTACTIVEFORECAST

    WHERE

    ACTIVITY_DT = d.ACTIVITY_DT AND

    CT_KEY = d.CT_KEY AND

    MINUTE_KEY = d.MINUTE_KEY)

    Means, you try to select ct_ds. If ct_ds = "Spanish THI", then you must replace that Word with "Moderate_nr". If it is put like this the case statement in the selection as list below

    SELECT

    f.CT_ID,

    f.BUSINESS,

    DECODE (F.CT_DS, 'Spanish THI', 'MODERATE_NR',F.CT_DS) ct_ds,.

    d.ETL_DT,

    d.ACTIVITY_DT,

    d.MINUTE_KEY,

    d.FCST_CONTACTS_RECEIVED

    Of

    (LIGHTHOUSE. IEX_CT_DIM b

    JOIN INTERNAL LIGHT. D THE IEX_CTACTIVEFORECAST (b.CT_KEY = d.CT_KEY))

    JOIN INTERNAL LIGHT. TBL_GEN_CT_BUSINESS f

    WE (f.CT_ID = b.CT_ID)

    (f.BUSINESS IN ('THI_PL', 'THI_ESC')) AND

    (d.ACTIVITY_DT BETWEEN TO_DATE)

    27 January 2014 00:00:00 ',

    "MM/DD/YYYY hh24:mi:ss")

    AND TO_DATE)

    27 April 2014 00:00:00 ',

    "MM/DD/YYYY hh24:mi:ss")) AND

    (f.EFF_DT = TO_DATE)

    29 January 2014 00:00:00 ',

    "MM/DD/YYYY hh24:mi:ss")) AND

    d.ETL_DT = (SELECT

    MAX (ETL_DT)

    Of

    LIGHTHOUSE. IEX_CTACTIVEFORECAST

    WHERE

    ACTIVITY_DT = d.ACTIVITY_DT AND

    CT_KEY = d.CT_KEY AND

    MINUTE_KEY = d.MINUTE_KEY)

    Post edited by: 000000

  • can we use alias name in the case statement?

    Select sal,

    Sal case

    When 500 then 'low '.

    When 5000 can 'high '.

    of another "medium".

    cases of termination

    EMP;

    OUTPUT

    case of SAL

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

    4587 way

    5000 high

    .. .so I have worn instead of cases at the exit?

    Yes. Contrary to the statements of CASE in PL/SQL, SQL CASE expressions like this ends with 'end', not 'end of case. Your use of the terminal 'deal' was just an alias the column as the 'CASES '.

    select
      sal,
      case sal
        when 500 then 'low'
        when 5000 then 'high'
        else 'medium'
      end range
    from
      emp;
    
  • Problem with Case statement

    I try to use a case statement in a report of the Apex, but I get an error message.

    It comes to my sql

    CASE WHEN EXISTS (select stg.extkey, distsubtrpgrpid

    of udm_da da

    udm_di di

    udm_distsubtrpgrp stg

    where di.disttransgrpid = stg.disttransgrpid

    and da.daid = di.daid

    and da.suid = su.suid)

    THEN

    Select stg.extkey

    of udm_da da.

    udm_di di,

    udm_distsubtrpgrp stg

    where di.disttransgrpid = stg.disttransgrpid

    and da.daid = di.daid

    and da.suid = ' | Qul SUID. '

    Stg.extkey group, distsubtrpgrpid

    Union

    Select stg.extkey

    of stg udm_distsubtrpgrp

    where distsubtrpgrpid! = - 1

    and distsubtrpgrpid = ' | NVL (su.distsubtrpgrpid-1). '

    order by 1

    WHEN su.distsubtrpgrpid IS NOT NULL

    THEN

    Select stg.extkey, distsubtrpgrpid

    of stg udm_distsubtrpgrp

    where distsubtrpgrpid! = - 1

    and distsubtrpgrpid = ' | NVL (su.distsubtrpgrpid-1). '

    order by 1

    ON THE OTHER

    NULL VALUE

    END DISTSUBTRPGRP_1

    Any help appreciated

    Gus

    GusC wrote:

    Yes you are right.

    My sql must be

    CASE WHEN su.distsubtrpgrpid IS NOT NULL

    THEN

    Select stg.extkey, distsubtrpgrpid

    of stg udm_distsubtrpgrp

    where distsubtrpgrpid! = - 1

    and distsubtrpgrpid = su.distsubtrpgrpid

    ON THE OTHER

    NULL VALUE

    END DISTSUBTRPGRP_1

    But the report won't save

    Gus

    No, your SQL is not that.

    The select statement that you put online here, aside from being not not in brackets, is the selection of two values, but you can provide two values for the result column.

    Without knowing who the SQL statement, we can highlight only the obvious questions.

Maybe you are looking for

  • How can I tell the tool "Download" ask me what to do with a download?

    I was trying to download an MP3 that a friend had sent to me, but when I went to press the button 'Save file' on the small window that says "Open in..." or "save to...". ' (Or something like that), I accidentally hit the button that says always "do t

  • Z1 HP - monitor screen discoloration

    I've owned than my z1 for nearly two years now and just noticed what looks like a water stain as a discoloration on the right side of the screen, which extends vertically under the glass of the lower right to halfway to the top of the screen, the rig

  • Upgrade the generatation report toolkit OR

    Hey there, I have a few old screws that used to be in the (1.0.x) report generation toolkit I need to modify and upgrade. Generate report Set updated the Data.vi Generate data Get report to Modify.vi Get Data.vi report do not seem to no longer exists

  • Unable to activate Windows 7 after reformat

    I have just be reformatted my hard disk down load vista home no problem. Updated anytime upgrade to windows 7 home no problem, I'm trying now high grade to windows 7 ultimate except the product key, and then begins to update then stops and says try a

  • Animate the button text on the timeline

    Hello worldThis is my first time to follow step by step from a youtube video:After effects CS5 - basic text Animation - YouTubeexperience animating text in aftereffects.My 1st question is:There is no button on my text on the timeline layer.I have to