CASE Statement - and checking number ranges
I am attempting to write a bit of SQL that can be used to do a count of Requisition Values, in different value bands, e.g.:
0 - 250
251 - 500
501 - 1000
etc...
I have got this far:
SELECT sum_value
, COUNT(req_id) req_ct
FROM (SELECT prha.requisition_header_id req_id
, CASE SUM(prla.unit_price * prla.quantity)
WHEN 250
THEN '250'
WHEN 500
THEN '500'
WHEN 500
THEN '1000'
ELSE 'OTHER'
END sum_value
FROM po.po_requisition_headers_all prha
, po.po_requisition_lines_all prla
WHERE prha.requisition_header_id = prla.requisition_header_id
AND prha.creation_date >= SYSDATE - 3
GROUP BY prha.requisition_header_id
, prla.requisition_header_id) rt
GROUP BY sum_value;
SUM_V REQ_CT
250 3
500 6
OTHER 726But - it is not that great, in that it counts REQs with an exact value of 250,400,500 etc.
I am trying to work out the syntax to allow the CASE statement to work with ranges, but I can't work it out.
I have naively attempted this, for example:
WHEN > 250 AND 500
But that errors out, because I can see that the '>' needs to know what it is checking
Any help much appreciated.
Thank you
Thanks for the reply Sarma,
I've attempted that:
SELECT sum_value
, COUNT(req_id) req_ct
FROM (SELECT prha.requisition_header_id req_id
, CASE SUM(prla.unit_price * prla.quantity)
WHEN BETWEEN 250 AND 500
THEN '250 - 500'
WHEN BETWEEN 501 AND 1000
THEN '501 - 1000'
WHEN BETWEEN 1001 AND 2500
THEN '1001 - 2500'
ELSE 'OTHER'
END sum_value
FROM po.po_requisition_headers_all prha
, po.po_requisition_lines_all prla
WHERE prha.requisition_header_id = prla.requisition_header_id
AND prha.creation_date >= SYSDATE - 3
GROUP BY prha.requisition_header_id
, prla.requisition_header_id) rt
GROUP BY sum_value;But I can see that it doesn't work because I need to state what 'blah' is!
For example, if I tried to state 'blah' as follows:
SELECT sum_value
, COUNT(req_id) req_ct
FROM (SELECT prha.requisition_header_id req_id
, CASE SUM(prla.unit_price * prla.quantity)
WHEN SUM(prla.unit_price * prla.quantity) BETWEEN 250 AND 500
THEN '250 - 500'
WHEN SUM(prla.unit_price * prla.quantity) BETWEEN 501 AND 1000
THEN '501 - 1000'
WHEN SUM(prla.unit_price * prla.quantity) BETWEEN 1001 AND 2500
THEN '1001 - 2500'
ELSE 'OTHER'
END sum_value
FROM po.po_requisition_headers_all prha
, po.po_requisition_lines_all prla
WHERE prha.requisition_header_id = prla.requisition_header_id
AND prha.creation_date >= SYSDATE - 3
GROUP BY prha.requisition_header_id
, prla.requisition_header_id) rt
GROUP BY sum_value;It still errors. I guess I am doing something fundamentally wrong, but I can't see how I can refer to the 'sum' value, to then use it in the Between section of the Case statement.
Thanks
Similar Messages
-
CASE STATEMENTS AND CASE EXPRESSIONS IN ORACLE9I PL/SQL
제품 : PL/SQL
작성날짜 : 2001-11-13
CASE STATEMENTS AND CASE EXPRESSIONS IN ORACLE9I PL/SQL
=======================================================
PURPOSE
아래의 자료는 Case 문에서 oracle 8.1.7과 Oracle 9i의 New Feature로 8.1.7에서는
sqlplus 에서만 가능했고, 9i 부터는 pl/sql 까지 가능하다.
Explanation
1. Oracle 8.1.7 Feature
Oracle 8.1.7 에서 Case 문은 Decode 문과 유사하지만, 기존의 decode 문을 쓰는 것보다
더 많은 확장성과 Logical Power와 좋은 성능을 제공한다. 주로 나이와 같이 category 별로
나눌때 주로 사용하고 Syntex는 아래와 같다.
CASE WHEN <cond1> THEN <v1> WHEN <cond2> THEN <v2> ... [ELSE <vn+1> ] END
각각의 WHEN...THEN 절의 argument 는 255 까지 가능하고 이 Limit를 해결하려면
Oracle 8i Reference를 참조하면 된다.
The maximum number of arguments in a CASE expression is 255, and each
WHEN ... THEN pair counts as two arguments. To avoid exceeding the limit of 128 choices,
you can nest CASE expressions. That is expr1 can itself be a CASE expression.
Case Example : 한 회사의 모든 종업원의 평균 봉급을 계산하는데 봉급이 $2000보다 작은경우
2000으로 계산을 하는 방법이 pl/sql을 대신하여 case function을 사용할 수 있다.
SELECT AVG(CASE when e.sal > 2000 THEN e.sal ELSE 2000 end) FROM emp e;
Case Example : 나이를 column으로 가지고 있는 customer table을 예로 들어보자.
SQL> SELECT
2 SUM(CASE WHEN age BETWEEN 70 AND 79 THEN 1 ELSE 0 END) as "70-79",
3 SUM(CASE WHEN age BETWEEN 80 AND 89 THEN 1 ELSE 0 END) as "80-89",
4 SUM(CASE WHEN age BETWEEN 90 AND 99 THEN 1 ELSE 0 END) as "90-99",
5 SUM(CASE WHEN age > 99 THEN 1 ELSE 0 END) as "100+"
6 FROM customer;
70-79 80-89 90-99 100+
4 2 3 1
1 SELECT
2 (CASE WHEN age BETWEEN 70 AND 79 THEN '70-79'
3 WHEN age BETWEEN 80 and 89 THEN '80-89'
4 WHEN age BETWEEN 90 and 99 THEN '90-99'
5 WHEN age > 99 THEN '100+' END) as age_group,
6 COUNT(*) as age_count
7 FROM customer
8 GROUP BY
9 (CASE WHEN age BETWEEN 70 AND 79 THEN '70-79'
10 WHEN age BETWEEN 80 and 89 THEN '80-89'
11 WHEN age BETWEEN 90 and 99 THEN '90-99'
12* WHEN age > 99 THEN '100+' END)
SQL> /
AGE_G AGE_COUNT
100+ 1
70-79 4
80-89 2
90-99 3
Example
2. Oracle 9i Feature
Oracle 9i부터는 pl/sql에서도 case문을 사용할 수 있으면 이것은
복잡한 if-else 구문을 없애고, C언어의 switch문과 같은 기능을 한다.
아래의 9i pl/sql Sample 및 제약 사항을 보면 아래와 같다.
Sample 1:
A simple example demonstrating the proper syntax for a case
statement
using a character variable as the selector. See the section entitled
'Restrictions' at the end of this article for details on which PLSQL
datatypes may appear as a selector in a case statement or
expression.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
declare
achar char(1) := '&achar';
begin
case achar
when 'A' then dbms_output.put_line('The description was Excellent');
when 'B' then dbms_output.put_line('The description was Very Good');
when 'C' then dbms_output.put_line('The description was Good');
when 'D' then dbms_output.put_line('The description was Fair');
when 'F' then dbms_output.put_line('The description was Poor');
else dbms_output.put_line('The description was No such Grade');
end case;
end;
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
Sample 2:
A simple example demonstrating the proper syntax for a case
expression
using a character variable as the selector. See the section entitled
'Restrictions' at the end of this article for details on which PLSQL
datatypes may appear as a selector in a case statement or
expression.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
declare
achar char(1) := '&achar';
description varchar2(20);
begin
description :=
case achar
when 'A' then 'Excellent'
when 'B' then 'Very Good'
when 'C' then 'Good'
when 'D' then 'Fair'
when 'F' then 'Poor'
else 'No such grade'
end;
dbms_output.put_line('The description was ' || description);
end;
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
NOTE: The above simple samples demonstrate two subtle differences in the
syntax
required for case statements and expressions.
1) A case STATEMENT is terminated using the 'end case' keywords; a
case
EXPRESSION is terminated using only the 'end' keyword.
2) Each item in a case STATEMENT consists of one or more
statements, each
terminated by a semicolon. Each item in a case expression
consists of
exactly one expression, not terminated by a semicolon.
Sample 3:
Sample 1 demonstrates a simple case statement in which the selector
is
compared for equality with each item in the case statement body.
PL/SQL
also provides a 'searched' case statement as an alternative; rather
than
providing a selector and a list of values, each item in the body of
the
case statement provides its own predicate. This predicate can be any
valid boolean expression, but only one case will be selected.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
declare
achar char(1) := '&achar';
begin
case
when achar = 'A' then dbms_output.put_line('The description was
Excellent');
when achar = 'B' then dbms_output.put_line('The description was Very
Good');
when achar = 'C' then dbms_output.put_line('The description was
Good');
when achar = 'D' then dbms_output.put_line('The description was
Fair');
when achar = 'F' then dbms_output.put_line('The description was
Poor');
else dbms_output.put_line('The description was No such Grade');
end case;
end;
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
Sample 4:
This sample demonstrates the proper syntax for a case expression of
the
type discussed in Sample 3 above.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
declare
achar char(1) := '&achar';
description varchar2(20);
begin
description :=
case
when achar = 'A' then 'Excellent'
when achar = 'B' then 'Very Good'
when achar = 'C' then 'Good'
when achar = 'D' then 'Fair'
when achar = 'F' then 'Poor'
else 'No such grade'
end;
dbms_output.put_line('The description was ' || description);
end;
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
Sample 5:
This sample demonstrates the use of nested case statements. It is
also
permissable to nest case expressions within a case statement (though
it
is not demonstrated here), but nesting of case statements within a
case
expression is not possible since statements do not return any value.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
declare
anum1 number := &anum1;
anum2 number := &anum2;
answer number;
begin
case anum1
when 1 then case anum2
when 1 then answer := 10;
when 2 then answer := 20;
when 3 then answer := 30;
else answer := 999;
end case;
when 2 then case anum2
when 1 then answer := 15;
when 2 then answer := 25;
when 3 then answer := 35;
else answer := 777;
end case;
else answer := 555;
end case;
dbms_output.put_line('The answer is ' || answer);
end;
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
Sample 6:
This sample demonstrates nesting of case expressions within another
case
expression. Note again the absence of semicolons to terminate both
the
nested case expression and the individual cases of those
expressions.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
declare
anum1 number := &anum1;
anum2 number := &anum2;
answer number;
begin
answer :=
case anum1
when 1 then case anum2
when 1 then 10
when 2 then 20
when 3 then 30
else 999
end
when 2 then case anum2
when 1 then 15
when 2 then 25
when 3 then 35
else 777
end
else 555
end;
dbms_output.put_line('The answer is ' || answer);
end;
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
Although PL/SQL anonymous blocks have been used in all of the examples
so far,
case statements and expressions can also be used in procedures,
functions, and
packages with no changes to the syntax.
The following samples are included for completeness and demonstrate the
use of
case statements and/or expressions in each of these scenarios.
Sample 7:
This sample demonstrates use of a case statement in a stored
procedure.
Note that this sample also demonstrates that it is possible for each
of
the items in the case body to consist of more than one statement.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
create or replace procedure testcasestmt ( anum IN number ) is
begin
case
when anum = 1 then dbms_output.put_line('The number was One');
dbms_output.put_line('In case 1');
when anum = 2 then dbms_output.put_line('The number was Two');
dbms_output.put_line('In case 2');
when anum = 3 then dbms_output.put_line('The number was Three');
dbms_output.put_line('In case 3');
when anum = 4 then dbms_output.put_line('The number was Four');
dbms_output.put_line('In case 4');
when anum = 5 then dbms_output.put_line('The number was Five');
dbms_output.put_line('In case 5');
else dbms_output.put_line('The description was Invalid input');
dbms_output.put_line('In the else case');
end case;
end;
exec testcasestmt(&anum);
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
Sample 8:
This sample demonstrates the use of a case statement in a stored
package.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
create or replace package testpkg2 is
procedure testcasestmt ( anum IN number );
function testcasestmt_f ( anum IN number ) return number;
end testpkg2;
create or replace package body testpkg2 is
procedure testcasestmt ( anum IN number ) is
begin
case
when anum = 1 then dbms_output.put_line('The number was One');
dbms_output.put_line('In case 1');
when anum = 2 then dbms_output.put_line('The number was Two');
dbms_output.put_line('In case 2');
when anum = 3 then dbms_output.put_line('The number was Three');
dbms_output.put_line('In case 3');
when anum = 4 then dbms_output.put_line('The number was Four');
dbms_output.put_line('In case 4');
when anum = 5 then dbms_output.put_line('The number was Five');
dbms_output.put_line('In case 5');
else dbms_output.put_line('The description was Invalid input');
dbms_output.put_line('In the else case');
end case;
end;
function testcasestmt_f ( anum IN number ) return number is
begin
case
when anum = 1 then dbms_output.put_line('The number was One');
dbms_output.put_line('In case 1');
when anum = 2 then dbms_output.put_line('The number was Two');
dbms_output.put_line('In case 2');
when anum = 3 then dbms_output.put_line('The number was Three');
dbms_output.put_line('In case 3');
when anum = 4 then dbms_output.put_line('The number was Four');
dbms_output.put_line('In case 4');
when anum = 5 then dbms_output.put_line('The number was Five');
dbms_output.put_line('In case 5');
else dbms_output.put_line('The description was Invalid input');
dbms_output.put_line('In the else case');
end case;
return anum;
end;
end testpkg2;
exec testpkg2.testcasestmt(&anum);
variable numout number
exec :numout := testpkg2.testcasestmt_f(&anum);
print numout
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
Sample 9:
This sample demonstrates the use of a case expression in a stored
package.
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - -
set serveroutput on
create or replace package testpkg is
procedure testcase ( anum IN number );
function testcase_f ( anum IN number ) return number;
end testpkg;
create or replace package body testpkg is
procedure testcase ( anum IN number ) is
anumber number := anum;
anothernum number;
begin
anothernum :=
case
when anumber = 1 then anumber + 1
when anumber = 2 then anumber + 2
when anumber = 3 then anumber + 3
when anumber = 4 then anumber + 4
when anumber = 5 then anumber + 5
else 999
end;
dbms_output.put_line('The number was ' || anothernum);
end;
function testcase_f ( anum IN number ) return number is
anumber number := anum;
anothernum number;
begin
anothernum :=
case
when anumber = 1 then anumber + 1
when anumber = 2 then anumber + 2
when anumber = 3 then anumber + 3
when anumber = 4 then anumber + 4
when anumber = 5 then anumber + 5
else 999
end;
dbms_output.put_line('The number was ' || anothernum);
return anothernum;
end;
end testpkg;
variable numout number
exec testpkg.testcase(&anum);
exec :numout := testpkg.testcase_f(&anum);
print numout
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - -
제약 사항
다음의 databasetype은 case 문에서 지원되지 않는다.
BLOB
BFILE
VARRAY
Nested Table
PL/SQL Record
PL/SQL Version 2 tables (index by tables)
Object type (user-defined type)
All of these types except for object types face a similar restriction
even for if statements (i.e. they cannot be compared for equality directly) so this is unlikely to change for these types. Lack of support for object types is simply an implementation restriction which may be relaxed in future releases.
Reference Ducumment
Oracle 8.1.7 Manual
NOTE:131557.1I have done the following code but doesn't
like the statement of - "case(butNext)". What do you mean "doesn't like" -- did you get an error message?
I'm guessing it won't compile because you're trying to switch on a Button.
I tried something
like "g.fillOval(100,50,70,90, BorderLayout.NORTH)"...no that doesn't make sense. You only use BorderLayout.NORTH when you're adding components to a BorderLayout layout manager. An oval is not a component and fillOval isn't adding a component and Graphics is not a Panel or layout manager.
Would appreciate it if someone could tell me how to position
shapes using the graohic method. I think the problem is that you're confusing shapes with components. -
Case statement and Decode function both are not working in Select cursor.
I have tried both the Case statement and Decode function in Select cursor, but both the things are not working. On the other hand both the things work in just select statement.
See the first column in select (PAR_FLAG), I need to have this evaluated along with other fields. Can you please suggest some thing to make this work. And also I would like to
know the reason why decode is not working, I heard some where Case statement do not work with 8i.
Author : Amit Juneja
Date : 06/20/2011
Description:
Updates the Diamond MEMBER_MASTER table with the values from
INC.MEM_NJ_HN_MEMBER_XREF table.
declare
rec_cnt number(12) := 0;
commit_cnt number(4) := 0;
cursor select_cur is
Select DECODE(1,
(Select 1
from hsd_prov_contract R
where R.seq_prov_id = PM.seq_prov_id
and R.line_of_business = H.line_of_business
and R.PCP_FLAG = 'Y'
and R.participation_flag = 'P'
and SYSDATE between R.EFFECTIVE_DATE AND
NVL(R.TERM_DATE,
TO_DATE('31-DEC-9999', 'DD-MON-YYYY'))),
'Y',
'N') PAR_FLAG,
H.SEQ_ELIG_HIST,
H.SEQ_MEMB_ID,
H.SEQ_SUBS_ID,
H.SUBSCRIBER_ID,
H.PERSON_NUMBER,
H.EFFECTIVE_DATE,
H.TERM_DATE,
H.TERM_REASON,
H.RELATIONSHIP_CODE,
H.SEQ_GROUP_ID,
H.PLAN_CODE,
H.LINE_OF_BUSINESS,
H.RIDER_CODE_1,
H.RIDER_CODE_2,
H.RIDER_CODE_3,
H.RIDER_CODE_4,
H.RIDER_CODE_5,
H.RIDER_CODE_6,
H.RIDER_CODE_7,
H.RIDER_CODE_8,
H.MEDICARE_STATUS_FLG,
H.OTHER_STATUS_FLAG,
H.HIRE_DATE,
H.ELIG_STATUS,
H.PREM_OVERRIDE_STEP,
H.PREM_OVERRIDE_AMT,
H.PREM_OVERRIDE_CODE,
H.SEQ_PROV_ID,
H.IPA_ID,
H.PANEL_ID,
H.SEQ_PROV_2_ID,
H.SECURITY_CODE,
H.INSERT_DATETIME,
H.INSERT_USER,
H.INSERT_PROCESS,
H.UPDATE_DATETIME,
H.UPDATE_USER,
H.UPDATE_PROCESS,
H.USER_DEFINED_1,
H.SALARY,
H.PEC_END_DATE,
H.REASON_CODE,
H.PEC_WAIVED,
H.BILL_EFFECTIVE_FROM_DATE,
H.BILLED_THRU_DATE,
H.PAID_THRU_DATE,
H.SUBSC_DEPT,
H.SUBSC_LOCATION,
H.USE_EFT_FLG,
H.BENEFIT_START_DATE,
H.SEQ_ENROLLMENT_RULE,
H.MCARE_RISK_ACCRETION_DATE,
H.MCARE_RISK_DELETION_DATE,
H.MCARE_RISK_REFUSED_DATE,
H.COMMENTS,
H.USER_DEFINED_2,
H.USER_DEFINED_3,
H.RATE_TYPE,
H.PCPAA_OCCURRED,
H.PRIVACY_ON,
H.PCP_CHANGE_REASON,
H.SITE_CODE,
H.SEQ_SITE_ADDRESS_ID,
PM.seq_prov_id rendered_prov
from hsd_member_elig_history H,
INC.PCP_REASSIGN_RPRT_DATA P,
hsd_prov_master PM
where P.subscriber_id = H.subscriber_id
and P.rendered_pcp = PM.provider_ID
and H.elig_status = 'Y'
and (H.term_date is NULL or H.term_date >= last_day(sysdate))
order by H.Seq_memb_id;
begin
for C in select_cur loop
rec_cnt := rec_cnt + 1;
update hsd_member_elig_history
set term_date = TRUNC(SYSDATE - 1),
term_reason = 'PCPTR',
update_datetime = SYSDATE,
update_user = USER,
update_process = 'TD33615'
where seq_elig_hist = C.seq_elig_hist
and seq_memb_id = C.seq_memb_id;
INSERT INTO HSD_MEMBER_ELIG_HISTORY
(SEQ_ELIG_HIST,
SEQ_MEMB_ID,
SEQ_SUBS_ID,
SUBSCRIBER_ID,
PERSON_NUMBER,
EFFECTIVE_DATE,
TERM_DATE,
TERM_REASON,
RELATIONSHIP_CODE,
SEQ_GROUP_ID,
PLAN_CODE,
LINE_OF_BUSINESS,
RIDER_CODE_1,
RIDER_CODE_2,
RIDER_CODE_3,
RIDER_CODE_4,
RIDER_CODE_5,
RIDER_CODE_6,
RIDER_CODE_7,
RIDER_CODE_8,
MEDICARE_STATUS_FLG,
OTHER_STATUS_FLAG,
HIRE_DATE,
ELIG_STATUS,
PREM_OVERRIDE_STEP,
PREM_OVERRIDE_AMT,
PREM_OVERRIDE_CODE,
SEQ_PROV_ID,
IPA_ID,
PANEL_ID,
SEQ_PROV_2_ID,
SECURITY_CODE,
INSERT_DATETIME,
INSERT_USER,
INSERT_PROCESS,
UPDATE_DATETIME,
UPDATE_USER,
UPDATE_PROCESS,
USER_DEFINED_1,
SALARY,
PEC_END_DATE,
REASON_CODE,
PEC_WAIVED,
BILL_EFFECTIVE_FROM_DATE,
BILLED_THRU_DATE,
PAID_THRU_DATE,
SUBSC_DEPT,
SUBSC_LOCATION,
USE_EFT_FLG,
BENEFIT_START_DATE,
SEQ_ENROLLMENT_RULE,
MCARE_RISK_ACCRETION_DATE,
MCARE_RISK_DELETION_DATE,
MCARE_RISK_REFUSED_DATE,
COMMENTS,
USER_DEFINED_2,
USER_DEFINED_3,
RATE_TYPE,
PCPAA_OCCURRED,
PRIVACY_ON,
PCP_CHANGE_REASON,
SITE_CODE,
SEQ_SITE_ADDRESS_ID)
values
(hsd_seq_elig_hist.nextval,
C.SEQ_MEMB_ID,
C.SEQ_SUBS_ID,
C.SUBSCRIBER_ID,
C.PERSON_NUMBER,
trunc(SYSDATE),
C.TERM_DATE,
C.TERM_REASON,
C.RELATIONSHIP_CODE,
C.SEQ_GROUP_ID,
C.PLAN_CODE,
C.LINE_OF_BUSINESS,
C.RIDER_CODE_1,
C.RIDER_CODE_2,
C.RIDER_CODE_3,
C.RIDER_CODE_4,
C.RIDER_CODE_5,
C.RIDER_CODE_6,
C.RIDER_CODE_7,
C.RIDER_CODE_8,
C.MEDICARE_STATUS_FLG,
C.OTHER_STATUS_FLAG,
C.HIRE_DATE,
C.ELIG_STATUS,
C.PREM_OVERRIDE_STEP,
C.PREM_OVERRIDE_AMT,
C.PREM_OVERRIDE_CODE,
C.SEQ_PROV_ID,
C.IPA_ID,
C.PANEL_ID,
C.SEQ_PROV_2_ID,
C.SECURITY_CODE,
SYSDATE,
USER,
'TD33615',
SYSDATE,
USER,
'TD33615',
C.USER_DEFINED_1,
C.SALARY,
C.PEC_END_DATE,
C.REASON_CODE,
C.PEC_WAIVED,
C.BILL_EFFECTIVE_FROM_DATE,
C.BILLED_THRU_DATE,
C.PAID_THRU_DATE,
C.SUBSC_DEPT,
C.SUBSC_LOCATION,
C.USE_EFT_FLG,
C.BENEFIT_START_DATE,
C.SEQ_ENROLLMENT_RULE,
C.MCARE_RISK_ACCRETION_DATE,
C.MCARE_RISK_DELETION_DATE,
C.MCARE_RISK_REFUSED_DATE,
C.COMMENTS,
C.USER_DEFINED_2,
C.USER_DEFINED_3,
C.RATE_TYPE,
C.PCPAA_OCCURRED,
C.PRIVACY_ON,
C.PCP_CHANGE_REASON,
C.SITE_CODE,
C.SEQ_SITE_ADDRESS_ID);
commit_cnt := commit_cnt + 1;
if (commit_cnt = 1000) then
dbms_output.put_line('Committed updates for 1000 records.');
commit;
commit_cnt := 0;
end if;
end loop;
commit;
dbms_output.put_line('Total number of MEMBER_ELIG_HISTROY records inserted : ' ||
rec_cnt);
exception
when others then
raise_application_error(-20001,
'An error was encountered - ' || sqlcode ||
' -error- ' || sqlerrm);
end;user10305724 wrote:
I have tried both the Case statement and Decode function in Select cursor, but both the things are not working. Please define what you mean by not working even if your computer screen is near the internet we can't see it.
You should also look at the FAQ about how to ask a question
SQL and PL/SQL FAQ
Particularly *9) Formatting with {noformat}{noformat} Tags* and posting your version.
know the reason why decode is not working, I heard some where Case statement do not work with 8i.
Does this mean you are using 8i? Then scalar sub queries - selects within the select list, are not supported, along with CASE in PL/SQL.
Select DECODE(1,
* (Select 1
from hsd_prov_contract R
where R.seq_prov_id = PM.seq_prov_id
and R.line_of_business = H.line_of_business
and R.PCP_FLAG = 'Y'
and R.participation_flag = 'P'
and SYSDATE between R.EFFECTIVE_DATE AND
NVL(R.TERM_DATE,
TO_DATE('31-DEC-9999', 'DD-MON-YYYY')))*,
'Y',
'N') PAR_FLAG,
>
exception
when others then
raise_application_error(-20001,
'An error was encountered - ' || sqlcode ||
' -error- ' || sqlerrm);
http://tkyte.blogspot.com/2008/01/why-do-people-do-this.html -
Problem w/ Case Statement and Video Capture
Hey!
I've got a question about a topic which seems pretty trivial, but has been giving me quite the trouble for some time now. I was hoping that someone on this forum would be able to help me catch and fix my mistake.
Basically what I'm trying to do is capture video from a camera, run some video analysis for a certain duration, and store the raw footage for that same duration in an avi file. I'm using IMAQdx and a Logitech C920 camera to gather video. When I run the program, I want there to be an output of the raw video on the front panel. When I then hit a button, I would like the camera to save a .avi file of the video for a set number of frames and concurrently run some analysis and display the results on another display on the front panel. The purpose of the raw footage in the .avi file is to be able to run the analysis again at a later date.
I've attached both a screenshot and the .vi file to this post. When I run the current script, I'm confronted with one of two possible errors (not sure why they're different from time to time). The Video Acquisition Block either "Time Out"s or the Write to AVI block issues an incompatible image type error. The reason why I'm baffled by this is because when I take it out of the case statement and have it run with the rest of the program, the .avi file is generated accurately and stored.
Any help would be greatly appreciated. Thanks!
Attachments:
Script Image.png 39 KB
11_30_12 TrackVIEW.vi 271 KBGreetings,
Would the time out error happen every time you run the VI? In addition, do these errors have a code?
I was able to replicate the issue and initially believe that it might be that we are simultaneously opening two sessions to the same camera. Could you simply take a finite number of images from the first acquisition and chain the second one via sequence structure? It would limit the viewer to only view the video on the other Image Display during saving the AVI, but it might be worthwhile looking into.
It might also be worthwhile to consider enquewing a certain number of images whenever the button is pressed, but that would require some more programming logic.
Cordially;
Simon P.
National Instruments
Applications Engineer -
Hello!
I have a question from the user I am struggling to give a clever answer to.
What does it mean when you get a message on billing saving: "Billing document XXXXX saved (check number range)"?
Thanks!
Cheers
BeaHi Beata,
When the number range is near exaust level , System gives a message that the number range is nearing completion.
This % can be 5 % or 10% and can be set during customising.
Now you need to make provision for new range once this is exausted.
Regards
Vivek -
Regarding case statement and decode function
Hi Experts,
I have question.....regarding case statement and decode statement....
Can you please explain me that which one will be efficient,to place in insert statement...
insert statement(
(case when ........then
case when ....then
else
end)
else
end)
or
insert statement(
case when.....then
decode(....)
else
end)
Can you people explain me which one is more efficient method?
Thanks in advance.......The are major differences to talk about in case of CASE vs DECODE, but performance wise both are pretty much the same.
Have a look at Tom's thread
Ask Tom &quot;better performance - case or decode&quot;
I would suggest to use CASE whenever possible. Don't worry about the performance part. -
Difference beween Case Statement and Pivot Operator in a OWB mapping
Hi ,
Kindly clarify what is the difference between using a PIVOT operator and the CASE statement in a Expression Operator in a particular mapping.
rgds
ArinjitHi
With PIVOT operator you can transform columns to rows. For example if oyu have 12 column (one for every months) than you can create 12 rows with one column of month data.
If you want to do this without PIVOT you can do it with union (12 times) or with
something like this.
In this case you can't use CASE statement I think.
If you want to do the reverse of this, create 12 column from 12 rows, you can use UNPIVOT operator. In this case you can use CASE statement and aggregating.
Ott Karesz
http://www.trendo-kft.hu -
New Document Types and new Number Ranges
Hi,
Plz tell me How to configure New Document Types and new Number Ranges for Services and Asset Purchases.
How can i maintain Services with or without Master data.
Plz tell how much services are there and how to configure step by stepHi
New document type can be configured in SPRO - SAP IMG- Material management - Purchasing - Purchase order - Define number rabges / define document types.
With out service master straightaway you can create the Service PO with account assigment.
AC03 - Create service master record.
ML10 - Model service specifications
Then Service conditions ML33 or ML39 or ML45
Create the PO and then do the service entry in ML81N
Regards,
Raman -
Hi,
How can in the system FI and SD number range for billing documents be made same.
thanks
RekhaHi,
FI and SD number ranges can be made same for billing documents. SD number range should be made internal and FI number range should be made external.
Thanks
G.Bharathi -
Internal and external number range for a deivce
Hi Experts..
We have a client requirement where in we need to have both external and internal number ranges defined for the device.
But while creating a device it always takes external number range and never takes internal number range.
What is the possible reason for it and how can i rectify it.Hi Arvind
do u mean even when an externam name is provided in the device creation and still the screen does not accept it?
let me know
kr
raj -
Define groupings and assign number ranges
Hi,
I want to ask about customizing
In Recacust --> business partner --> Relevant setting for BP in RE context --> number range --> Define groupings and assign number ranges
There are Internal Standard Grouping column and External Standard Grouping column.
What is that for ? if i set both of them to active, what's the effect ?
Thank youHi,
If I tick the "ext.std grping" in one of BP grouping (for example in grouping 0002). Grouping 0002 will be used as standard grouping. The BDT selects this standard grouping if a business partner number was assigned to a business partner when the latter was created, but not a grouping.
Then,,, when i try to delete external grouping that used as the standard grouping, there was a message "External standard grouping 0002 must not be deleted"
How to un-tick this "ext.std grping" ?
I think this affected the BP creation. Now, I can't create BP, there always an error message "GET_BUSINESS_SYSTEM_ERRORAn error occurred when determining the business system"
Thank You -
Hi,
How can in the system FI and SD number range for billing documents be made same.
thanks
SekharHi,
FI and SD number ranges can be made same for billing documents. SD number range should be made internal and FI number range should be made external.
Thanks
G.Bharathi -
Sending PI message in case of Payment Cancellation and Check Number Voided
Hi ..
I've a requirement to send a message to PI wth the required invoice header fields whenver any payment document number is cancelled or check number is voided. I know we can cancel the payment or check payment through tcode FCH8 and the module program for this is SAPMFCHK.
I have no idea where would i put my custom code in the check payment cancellation wherein i can put my invoice fields and the proxy code so that I can send a message whenever any check payment or payment is cancelled.
Please help me if you have come with the similar requirement. I think i need to create an enhancement and put my codes inside that but not sure how do to this.
Thanks,
ShamimHi
I guess You need to create substitution for this purpose. In your case reversal document get created for your original FI document.
Go through http://wiki.sdn.sap.com/wiki/display/ERPFI/Creatinguserexitsforsubstitutions
First check GCX2 transaction if there is already any Z Program attached for your application area. If yes check if it is active in SPRO
Special Purpose LedgerTools-Maintain Validation/Substitution/Rules---Maintain Substitution
You can create substitution ZTEST under
Financial Accounting----Document header for field "reversal Indicator" and if you do F4 in field "Exit" you will see the exit created by you as per wiki.
I think you can create substitution on field "reversal Indicator" but its your choice. Check if your exit gets trigger.
Try creating a event to trigger proxy or submit program etc...
Hope this helps.
Regards
Vinit
Edited by: Vinit Joshi on Mar 9, 2012 8:20 PM -
Lexicographic flag setup and material number range change
Hi gurus,
got the following situation:
AS IS:
Tcode MMNR: Number range for material master part number: AAAAAAAAAAAAAAAAAA to ZZZZZZZZZZZZZZZZZZ (lenght 18, external assignment)
Tcode OMSL: Lexicographic flag IS NOT setup
Tcode OMS2: For all material types flag "External no. assignment w/o check" IS SETUP
Basically we can't create numeric only part numbers.
The new requirement is to be able to create numeric part numbers like:
1234
12345
0123
01234 (where the leading zero is a significant character for the part number)
By doing the following changes:
MMNR: change number range 000000000000000000 to ZZZZZZZZZZZZZZZZZZ
OMSL: setup lexicographic AND leading zeros flag
OMS2: clear flag for External no. assignment w/o check
I see I do achieve the result: numeric part numbers can be created, leading zeros are managed in the correct way and all numeric part numbers are LEFT-aligned, so looking to MARA you would see part numbers like this:
00012345
012345
012345V
09CATALIST1
0AFVAU0001
12345
23225V
23243V
2SIMBACK3210
I did already tried all the above changes in the quality system, then created a numeric part number and an alfanumeric part number, for both of them did create a PO, Inbound delivery, posted MIGO, created a sales order, outbound delivery, PGIed without any issue, stock was displayed and managed correctly by the system, same for material docs.
We already thought about BW, so in case we do the changes BW would be ok.
Apparently everything is fine so I should go for the production system BUT........ in my mind I'm thinking that OMSL Tcode is usually setup day 1 of an Sap project and then usually you forget it... I have the fear that even if everything looks fine (and Sap allows me to change the customizing), I'm going to muck up the system...
Have you ever had the same to do ? I already saw posts similar to this one but already existing conditions were different so to me this case looks like unique so far..
Any help, suggestion, whatever will be highly appreciated, especially cause I have to take a decision by tomorrow morning
Many thanks in advance !!
Enrico
Edited by: Matt on Aug 13, 2011 7:39 AM - profanity removedAs you never had numeric numbers, it should not create a big problem.
I am working in a system with lexicographical setting in use.
But you have to keep in mind that your sort sequence is quite different to numeric numbers, like this:
1
10
11
12
2
3
31
311123
32
32012
4
And you may get the one or other issue if you download material numbers to Excel, with wrong settings you will loose your leading zeros.
A similar effect happens most of the time if user not very familiar with Excel give you a file for an upload, as this often is prepared without leading zeros, which could cause a load to the wrong material if the remaining number would be a duplicate:
0123 and 123
Of course is a selection by number range not that easy as it is with numeric numbers. Usingthe first example a range from 1 to 3 includes materials 10, 11 and 12 as well -
Hello,
If storage location is HU and WM managed ( SU management active), is it required that for the number range of HU simialr overlapping number range has to be maintained for SU (assigned to the warehouse)?Hi,
you activate handling unit management independent from storage unit
management.
Only in case if storage location is full-WM- AND HU-managed the storage
unit management is always active and HU numbers are taken over as SU
numbers. In all other cases HUM and SUM are independent from each other
and number ranges must be set a way that they are not overlapping.
Regards,
Ely
Maybe you are looking for
-
Calling a Method of Interface by using Object
Hi All, I want to use a method of a class which will be IF_ABC_XYZ~ <amethod> ( ). how can i use this method in my program , I have the instance of the class which have the above mentioned method? Thanks & Regards Pavan
-
How to download purchased music to my new imac
how to download purchased music to my new imac
-
Condition exclusion between 2 condition types- Pleaase urgent
Hi gurus Ihave some problem. please help me to configure the system. I am giving 2 discounts and one has to excluse from other if it finds better discount. Ex : Z001 =$5 and Z002= $6 two condition types with 2 different access sequence .(not same a
-
Report 10g : Graph fillTransparent
How can I make the graph transparent and show other object of Report Builder ? (transparent : without image) and/ or How can I create a reference line which appears under the bars or points ?
-
Record limit in REUSE_ALV_GRID_DISPLAY
I have a ALV report program that displays an internal table with about 5000 records. When the user either selects 1-n lines on the ALV screen (or none at all) and then clicks a Details button I fill another internal table with the details that I want