473,396 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

CASE statement.........

Hi,
Can anyone please help me to rectify the problem.

Hi i wrote the following code regarding CASE statement:-

declare
num number :=45;
begin
case num
when num<20 then
dbms_output.put_line('Num is less then 20');
when num<40 then
dbms_output.put_line('Num is less then 40');
else
dbms_output.put_line('Num is less then 60');
end case;
end;
/

but i got the following error:-

case num
*
ERROR at line 4:
ORA-06550: line 4, column 6:
PLS-00615: type mismatch found at 'NUM' between CASE operand and WHEN operands
ORA-06550: line 4, column 1:
PL/SQL: Statement ignored

********** In this error i think datatype mismatch occured but i dont no why it occured **********

Please help with the correct code.

Regards,
Naveen
Jul 26 '07 #1
7 4989
debasisdas
8,127 Expert 4TB
Use the following code

Expand|Select|Wrap|Line Numbers
  1. declare
  2. num number :=45;
  3. begin
  4. case
  5. when num < 20 then
  6. dbms_output.put_line('Num is less then 20');
  7. when num < 40 then
  8. dbms_output.put_line('Num is less then 40');
  9. else
  10. dbms_output.put_line('Num is less then 60');
  11. end case;
  12. end;
Jul 26 '07 #2
What i think is that
the num which u used after case is of number data type and the num which u used in the when is returning you true or false, so there is a mismatch between the datatypes.
Jul 27 '07 #3
debasisdas
8,127 Expert 4TB
What i think is that
the num which u used after case is of number data type and the num which u used in the when is returning you true or false, so there is a mismatch between the datatypes.
There is nothing like mismatch.
Just compare the two sample code , you will get the difference.
Jul 28 '07 #4
Hi,
Can anyone please help me to rectify the problem.

Hi i wrote the following code regarding CASE statement:-

declare
num number :=45;
begin
case num
when num<20 then
dbms_output.put_line('Num is less then 20');
when num<40 then
dbms_output.put_line('Num is less then 40');
else
dbms_output.put_line('Num is less then 60');
end case;
end;
/

but i got the following error:-

case num
*
ERROR at line 4:
ORA-06550: line 4, column 6:
PLS-00615: type mismatch found at 'NUM' between CASE operand and WHEN operands
ORA-06550: line 4, column 1:
PL/SQL: Statement ignored

********** In this error i think datatype mismatch occured but i dont no why it occured **********

Please help with the correct code.

Regards,
Naveen
Hi naveen,
I looked your query.when you use reletional opertor please don't use num infront of case statement.

Your Query:

declare
num number :=45;
begin
case num
when num<20 then
dbms_output.put_line('Num is less then 20');
when num<40 then
dbms_output.put_line('Num is less then 40');
else
dbms_output.put_line('Num is less then 60');
end case;
end;
your mistake is highlighted in the form of bold

Correct Query:
declare
num number :=45;
begin
case
when num<20 then
dbms_output.put_line('Num is less then 20');
when num<40 then
dbms_output.put_line('Num is less then 40');
else
dbms_output.put_line('Num is less then 60');
end case;
end;

Please check and tell me..


Regards
Michael
Jul 30 '07 #5
Hi naveen,
I looked your query.when you use reletional opertor please don't use num infront of case statement.

Your Query:

declare
num number :=45;
begin
case num
when num<20 then
dbms_output.put_line('Num is less then 20');
when num<40 then
dbms_output.put_line('Num is less then 40');
else
dbms_output.put_line('Num is less then 60');
end case;
end;
your mistake is highlighted in the form of bold

Correct Query:
declare
num number :=45;
begin
case
when num<20 then
dbms_output.put_line('Num is less then 20');
when num<40 then
dbms_output.put_line('Num is less then 40');
else
dbms_output.put_line('Num is less then 60');
end case;
end;

Please check and tell me..


Regards
Michael
Hi Michael

Thanks a lot michael its working properly.

Regards
Naveen
Jul 30 '07 #6
Use the following code

Expand|Select|Wrap|Line Numbers
  1. declare
  2. num number :=45;
  3. begin
  4. case
  5. when num < 20 then
  6. dbms_output.put_line('Num is less then 20');
  7. when num < 40 then
  8. dbms_output.put_line('Num is less then 40');
  9. else
  10. dbms_output.put_line('Num is less then 60');
  11. end case;
  12. end;

Hi debasisdas
Thanks a lot its working fine. But i am confused why i got that error.
Regards,
Naveen
Jul 30 '07 #7
debasisdas
8,127 Expert 4TB
because you specified the case expression twice.
Jul 30 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

26
by: Joe Stevenson | last post by:
Hi all, I skimmed through the docs for Python, and I did not find anything like a case or switch statement. I assume there is one and that I just missed it. Can someone please point me to the...
6
by: deanfamily11 | last post by:
I've set up a case statement to have my program determine where on the Cartesian plane a point the user enters is located. I keep getting the C2051 error when I compile. Any help? #include...
7
by: Shapper | last post by:
Hello, I have a "Select Case MyVar" in which I define the values of an Array according to the value of MyVar. I need to use the Array Values in a Loop after End Select. It seems the Array is...
3
by: mark.irwin | last post by:
Hello all, Have an issue where a redirect pushes data to a page with a select case which then redirects to another page. Problem is the redirect isnt working in 1 case. Code below: strURL =...
12
by: rAinDeEr | last post by:
Hi, I have a table with 2 columns ** CREATE TABLE test (emp_num DECIMAL(7) NOT NULL,emp_name CHAR(10) NOT NULL) and i have inserted a number of records. ** Now, I want to insert a new...
5
by: Frederick Dean | last post by:
Hi,guys! I'm reading Stephen Dewhurst's book "C++ Gotchas"£¬in gothca #7, I meet a weird case: bool Postorder::next() { switch (pc) case START: while (true) if (!child()) { pc = LEAF; return...
1
by: microsoft.public.dotnet.languages.vb | last post by:
Hi All, I wanted to know whether this is possible to use multiple variables to use in the select case statement such as follows: select case dWarrExpDateMonth, dRetailDateMonth case...
22
by: John | last post by:
Hi Folks, I'm experimenting a little with creating a custom CEdit control so that I can decide on what the user is allowed to type into the control. I started off only allowing floating point...
9
by: Robbie Hatley | last post by:
Greetings, group. I just found a weird problem in a program where a variable declared in a {block} after a "case" keyword was being treated as having value 0 even though its actual value should...
13
by: Satya | last post by:
Hi everyone, This is the first time iam posting excuse me if iam making any mistake. My question is iam using a switch case statement in which i have around 100 case statements to compare. so...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.