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!

How to split a string (in a column) into multiple columns

Neruda from ItalyOct 18 2017 — edited Oct 18 2017

Hello. Please help me for this case.

I have this table

CREATE TABLE prova_metartaf

(

valore VARCHAR2 (80)

);

INSERT INTO prova_metartaf values ('TAF LIBD 110500Z 1106/1206 VRB05KT 9999 SCT030 TEMPO 1112/1118 SHRA=');

INSERT INTO prova_metartaf values ('METAR LIBD 111020Z 36006KT 320V050 9999 FEW020 21/14 Q1023=');

INSERT INTO prova_metartaf values ('METAR LIPB 110950Z 00000KT CAVOK 16/08 Q1024 RMK MON LIB=');

INSERT INTO prova_metartaf values ('TAF LIPB 110500Z 1106/1206 VRB05KT CAVOK=');

SELECT * FROM metar_taf;

Immagine1.png

I need instead this kind of result:

Immagine2.png

Just to be clear, I need to split the strings inside of field "valore" in multiple fields (tipo, icao, timeinfo and infobol).

If the first character of the string is 'T' then:

tipo = from chr nr 1 to 3

icao = from chr nr 5 to 8

timeinfo = from chr nr 10 to 16

infobol = from chr 18 to the end

If the first character of the string is 'M' then:

tipo = from chr nr 1 to 5

icao = from chr nr 7 to 10

timeinfo = from chr nr 12 to 18

infobol = from chr 20 to the end

Thank you for the help

This post has been answered by ViSQL on Oct 18 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 15 2017
Added on Oct 18 2017
4 comments
3,385 views