472,330 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

help with PL/SQL (ORA-06502 & PLS-00204)

nabh4u
62
Hello,
I am having two tables, 1st has just one column with 80 bytes and the 2nd table has many columns. I use substr function to get the specific value from the first table and insert it into the second table using PL/SQL. My problem here is, in the first table I might have blanks for some values which I have to insert into the second table fields defined as Number data type. Oracle treats blanks as a string and when i try to insert i get the following error:

ORA-06502: PL/SQL: numeric or value error: character to number conversion error

I tried to use DECODE but I cannot in the PL/SQL assignment statement. gives me the following error:

PLS-00204: function or pseudo-column 'DECODE' may be used inside a SQL statement only

I cannot write select statements as I have many fields defined as number type. Is there any other alternative which i can use to check if the incoming value is blanks then replace it with 0?

Any advise is welcome.

Thanks,
Nabh4u.
Jun 25 '08 #1
12 9338
debasisdas
8,127 Expert 4TB
Try to use NVL function. else convert to number using TO_NUMBER.
Jun 25 '08 #2
nabh4u
62
Try to use NVL function. else convert to number using TO_NUMBER.
hi Debasisdas,

Thanks for a quick reply.

I cannot use NVL as the incoming value is not considered as null, instead it is considered as a string of blanks.

I also cannot use TO_NUMBER because what it does is converts a string into a number. If the string is blanks then what should be the conversion?

What I know about TO_NUMBER is it converts a string into a number.
Eg: TO_NUMBER('123.25') will give 123.25

But, if the string is ' ' then what should be the result of TO_NUMBER(' ') ?

May be oracle has something else to use.

Thanks,
Nabh4u.
Jun 25 '08 #3
debasisdas
8,127 Expert 4TB
if using PLSQL then why not check the value using IF or CASE. You can use CASE in SQL also..
Jun 26 '08 #4
r035198x
13,262 8TB
decode should work then. How did you use it when you got the error?
Jun 26 '08 #5
decode should work then. How did you use it when you got the error?
may be this is helpful .. how to use decode in plsql by using sql only

cursor c1 is
SELECT LORRY_NO, TCS_NO,tcs_date,branch_branch_code
FROM CT_TCS where ac_year_code=:ac_year_code
tcs_date between :vtcs1 and :vtcs2
and branch_branch_code=:vbran
and lorry_no=decode(:lry,'ALL',lorry_no,:lry)
ORDER BY LORRY_NO,TCS_NO
begin
open c1
fetch c1.......
Jun 26 '08 #6
nabh4u
62
if using PLSQL then why not check the value using IF or CASE. You can use CASE in SQL also..
The problem is I have many fields like that and if I write IF or CASE for all of them then it will be a big burden. I am looking for something which is simple and easy.
Jun 26 '08 #7
nabh4u
62
decode should work then. How did you use it when you got the error?
hi r035198x,

Decode will only work when you use it with a sql statement. Looks like if we use decode while assigning something then it wont work.

Eg:- abc := decode(xyz,null,0,xyz);

The problem is I have a lot of fields like that and if I use sql statements for all of them then it will be a big burden and a huge procedure.


Thanks,
Nabh4u.
Jun 26 '08 #8
r035198x
13,262 8TB
The problem is I have many fields like that and if I write IF or CASE for all of them then it will be a big burden. I am looking for something which is simple and easy.
... and about the decode?

EDIT:

How about the REPLACE function then?
Jun 26 '08 #9
amitpatel66
2,367 Expert 2GB
Yes REPLACE should work.
CHeck sample code below:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SQL> SET SERVEROUTPUT ON
  3. SQL> declare
  4.   2  a number;
  5.   3  begin
  6.   4  a:= REPLACE(SUBSTR('abcd                  ',6),CHR(32),0);
  7.   5  dbms_output.put_line(a);
  8.   6  end;
  9.   7  /
  10.  
  11.  
  12. PL/SQL procedure successfully completed.
  13.  
  14. SQL> ed
  15. Wrote file afiedt.buf
  16.  
  17.   1  declare
  18.   2  a number;
  19.   3  begin
  20.   4  a:= REPLACE(SUBSTR('abc  d',4,2),CHR(32),0);
  21.   5  dbms_output.put_line(a);
  22.   6* end;
  23. SQL> /
  24.  
  25.  
  26. PL/SQL procedure successfully completed.
  27.  
  28. SQL> 
  29.  
  30. SQL> 
  31.  
Jun 26 '08 #10
nabh4u
62
Yes REPLACE should work.
CHeck sample code below:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SQL> SET SERVEROUTPUT ON
  3. SQL> declare
  4.   2  a number;
  5.   3  begin
  6.   4  a:= REPLACE(SUBSTR('abcd                  ',6),CHR(32),0);
  7.   5  dbms_output.put_line(a);
  8.   6  end;
  9.   7  /
  10.  
  11.  
  12. PL/SQL procedure successfully completed.
  13.  
  14. SQL> ed
  15. Wrote file afiedt.buf
  16.  
  17.   1  declare
  18.   2  a number;
  19.   3  begin
  20.   4  a:= REPLACE(SUBSTR('abc  d',4,2),CHR(32),0);
  21.   5  dbms_output.put_line(a);
  22.   6* end;
  23. SQL> /
  24.  
  25.  
  26. PL/SQL procedure successfully completed.
  27.  
  28. SQL> 
  29.  
  30. SQL> 
  31.  
hi Amit,

Can you tell me what does CHR(32) mean in your code? Also, If suppose the incoming value i.e., if the substring has proper value then will it get the value?

For Example:

a:= REPLACE(SUBSTR('abc d',4,2),CHR(32),0); will return 0.

but if a:= REPLACE(SUBSTR('abcaad',4,2),CHR(32),0); then will it return 'aa'?

Thank you,
Nabh4u.
Jun 26 '08 #11
amitpatel66
2,367 Expert 2GB
hi Amit,

Can you tell me what does CHR(32) mean in your code? Also, If suppose the incoming value i.e., if the substring has proper value then will it get the value?

For Example:

a:= REPLACE(SUBSTR('abc d',4,2),CHR(32),0); will return 0.

but if a:= REPLACE(SUBSTR('abcaad',4,2),CHR(32),0); then will it return 'aa'?

Thank you,
Nabh4u.
CHR(32) is nothing but a ' ' (a single space). 32 is asciivalue for a space.

Yes definately. A simple SELECT statement would have got you answer:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SQL> select REPLACE(SUBSTR('abcaad',4,2),CHR(32),0) from dual
  3.   2  /
  4.  
  5. RE
  6. --
  7. aa
  8.  
  9. SQL> 
  10.  
  11.  
Jun 26 '08 #12
nabh4u
62
CHR(32) is nothing but a ' ' (a single space). 32 is asciivalue for a space.

Yes definately. A simple SELECT statement would have got you answer:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SQL> select REPLACE(SUBSTR('abcaad',4,2),CHR(32),0) from dual
  3.   2  /
  4.  
  5. RE
  6. --
  7. aa
  8.  
  9. SQL> 
  10.  
  11.  
Thank you all very much. I think REPLACE is the one I was looking for.


thanks,
Nabh4u.
Jun 26 '08 #13

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

Similar topics

5
by: Subrahmanyam Arya | last post by:
Dear oracle gurus, I am unable to get past the error ORA-12154: TNS: could not resolve service name on my host when using hsodbc to talk to a...
1
by: Park Yeon Jo | last post by:
About Error : ORA-12514: TNS:listener could not resolve SERVICE_NAME given in connect descriptor I installed Oracle 8.1.7 on Windows XP...
1
by: Adam Ruth | last post by:
I'm using OCI on Mac OS X and I've run into a strange problem with my TNSNAMES.ORA file. My TNSNAMES.ORA file has one entry INV4II and it works...
2
by: tracy | last post by:
when i run the statement: SQL> select rowid from student_semester; ERROR at line 1: ORA-01445: cannot select ROWID from a join view without a...
2
by: Gordon Keeler | last post by:
Hi all. I'm using the Oracle Version 8 client with the database stored on a network machine. Can anyone provide insight into how and where to...
2
by: mpatel6 | last post by:
I had this error in alert log and my instance was down, anybody can help me? Errors in file...
1
by: janakivenk | last post by:
Hello, I am running Oracle 10g R2 in our office. I created the following procedure. It is suppose to access an xml file ( family.xml). The...
0
by: basmgokul | last post by:
I am using oracle 10g in windows vista.. when starting DB it throws an error Errors in file c:\database\udump\practice_ora_440.trc: ORA-00704:...
0
by: kaapie | last post by:
Oracle does not know which table's rowid to return from this view and thus it gives an error. What this means is that one of the underlying...
3
by: faathir88 | last post by:
i'd like to insert lots of data n its hard to determine which field would be the primary key, coz all of them almost similar. So, i decided to use...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.