0

I have tried both[CAST & TO_NUMBER] method but non of worked to cast values that is returned from another procedure.

SELECT DBMS_LOB.SUBSTR(SUBSTR(DETAIL_LOB, 2300, 4), 2000) 
  INTO RES 
FROM lONG_TO_CLOB_TEMP_TABLE;`

RES VALUE IS 40 returned by above query.

RES datatype is varchar2.

Now I want to convert that RES value into number so that I can do some arithmetic operation with this.

like => 100/RES

Not working code =>

V_TEMP := CAST(RES AS NUMBER)
V_TEMP := TO_NUMBER(RES)

Error Message => "ORA-06502: PL/SQL: numeric or value error"

D.J.
  • 376
  • 4
  • 16

3 Answers3

0

Its most likely special character involve in (space or line break)

Try

V_TEM := To_number(regexp_replace(trim(RES), '(^[[:space:]]+)|([[:space:]]+$)',null))
Nipun Alahakoon
  • 2,772
  • 5
  • 27
  • 45
0

There was a line break causing the problem.

Solved with:-

REPLACE(REPLACE(REPLACE(column_name, CHR(10)), CHR(13)), CHR(9));

--Special thanks to @KaushikNayak

D.J.
  • 376
  • 4
  • 16
-1

In order to remove a newline character using PL/SQL, use the following:

declare charwithnewline VARCHAR2(10) := CONCAT('190', CHR(13));
begin
dbms_output.put_line('+++++++++++++++++++++++++');
dbms_output.put_line(charwithnewline);
dbms_output.put_line('+++++++++++++++++++++++++');
dbms_output.put_line(REPLACE(charwithnewline,CHR(13),''));
dbms_output.put_line('+++++++++++++++++++++++++');
end; 

Note: The newline character could be CHR(13) or CHR(10) or a combination of these two characters. The logic is the same.

YowE3K
  • 23,852
  • 7
  • 26
  • 40
abhi
  • 3,082
  • 6
  • 47
  • 73