Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert string into integer with nulls values inside

Carl CMay 24 2018 — edited May 24 2018

Hi guys,

I've this "conversion" issue, I hope you might help.

I've this table test

> create table text (tex varchar2(20))

> insert into text values ('010        AAA') ; " 8 empty spaces between 010 and AAA"

>insert into text values ('010001 ABCD');

>insert into text values ('010001 FGHJ')

tex
010        AAA
010001 ABCD
010001 FGHJ

I need to get this result to insert another table where col 3 muts be converted into integer

 

col1col2col3col4
010AAA
010001ABCD
010001FGHJ

So, when I run this quesry :

select

     substr(tex,1,2) as col1,

     substr(tex,3,1) as col2,

    cast(substr(tex,4,3) as col 3,

    substr(tex,7,6) as col 4

from text

I get this message : ORA 01722 invalid number

I understand why, because first line have empty spaces,

My Quastion, how shal I proceed ?

Thank you if you can help.

Carl

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 21 2018
Added on May 24 2018
7 comments
699 views