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.
12 9521
Try to use NVL function. else convert to number using TO_NUMBER.
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.
if using PLSQL then why not check the value using IF or CASE. You can use CASE in SQL also..
decode should work then. How did you use it when you got the error?
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.......
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.
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.
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?
Yes REPLACE should work.
CHeck sample code below: -
-
SQL> SET SERVEROUTPUT ON
-
SQL> declare
-
2 a number;
-
3 begin
-
4 a:= REPLACE(SUBSTR('abcd ',6),CHR(32),0);
-
5 dbms_output.put_line(a);
-
6 end;
-
7 /
-
-
-
PL/SQL procedure successfully completed.
-
-
SQL> ed
-
Wrote file afiedt.buf
-
-
1 declare
-
2 a number;
-
3 begin
-
4 a:= REPLACE(SUBSTR('abc d',4,2),CHR(32),0);
-
5 dbms_output.put_line(a);
-
6* end;
-
SQL> /
-
-
-
PL/SQL procedure successfully completed.
-
-
SQL>
-
-
SQL>
-
Yes REPLACE should work.
CHeck sample code below: -
-
SQL> SET SERVEROUTPUT ON
-
SQL> declare
-
2 a number;
-
3 begin
-
4 a:= REPLACE(SUBSTR('abcd ',6),CHR(32),0);
-
5 dbms_output.put_line(a);
-
6 end;
-
7 /
-
-
-
PL/SQL procedure successfully completed.
-
-
SQL> ed
-
Wrote file afiedt.buf
-
-
1 declare
-
2 a number;
-
3 begin
-
4 a:= REPLACE(SUBSTR('abc d',4,2),CHR(32),0);
-
5 dbms_output.put_line(a);
-
6* end;
-
SQL> /
-
-
-
PL/SQL procedure successfully completed.
-
-
SQL>
-
-
SQL>
-
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.
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: -
-
SQL> select REPLACE(SUBSTR('abcaad',4,2),CHR(32),0) from dual
-
2 /
-
-
RE
-
--
-
aa
-
-
SQL>
-
-
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: -
-
SQL> select REPLACE(SUBSTR('abcaad',4,2),CHR(32),0) from dual
-
2 /
-
-
RE
-
--
-
aa
-
-
SQL>
-
-
Thank you all very much. I think REPLACE is the one I was looking for.
thanks,
Nabh4u.
Sign in to post your reply or Sign up for a free account.
Similar topics
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 remote mysql
database. i got from the meta link all...
|
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 Professional.
and I wanto connect to that server...
|
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 fine. However,
it will only work if that is the...
|
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
key-preserved table
student_semester is a view...
|
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 start solving this
error???
Thanks so much for you...
|
by: mpatel6 |
last post by:
I had this error in alert log and my instance was down, anybody can help me?
Errors in file /u01/app/oracle/admin/sotstest/bdump/sotstest_p004_626740.trc:
ORA-07445: exception encountered: core...
|
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 procedure is compiled and when I try to run it, i get the...
|
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: bootstrap process failure
ORA-39700: database...
|
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 tables in the view has
to have either a primary key or...
|
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 sequence for its PK by using trigger
here's the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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...
|
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...
| |