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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

SQL / PLSQL to split string into chunks

Ramky99Aug 18 2009 — edited Aug 18 2009
Hi all,

I have an issue converting some name data from one table structure to another.

e.g.

SQL> desc names
Name Null? Type
----------------------------------------- -------- ----------------------------
TITLE VARCHAR2(5)
FNAME VARCHAR2(20)
LNAME VARCHAR2(20)

SQL> desc data
Name Null? Type
----------------------------------------- -------- ----------------------------
FULLNAME VARCHAR2(50)


insert into data values ('MR I HAVE AN ESPECIALLY LONG NAME INDEED');
insert into data values ('MINE IS EVEN LONGER, QUITE RIDICULOUSLY SO IN FACT');

Essentially I need to split these long names, stored in 1 field, into the 3 fields above. The tricky part however is that I want to do it in such a way so that if the 1st part of the name fits the 1st 5 char field I'd like it to do that, if not I'd want it to split it between the next 2 fields - again without splitting a string. Reason behind this is that the application automatically puts a space between each field when they display and I'd like to avoid gaps in names if at all possible.

This has me a little stumped so any help would be seriously great ... it might not even be a go-er as it might be too wasteful with available space but I'd like to give it a shot.

Thanks!
Adam
This post has been answered by Frank Kulash on Aug 18 2009
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 15 2009
Added on Aug 18 2009
4 comments
3,061 views