Unix Technical Forum

Re: Queen/Pink Floyd

This is a discussion on Re: Queen/Pink Floyd within the Oracle Database forums, part of the Database Server Software category; --> DA Morgan <damorgan@exesolutions.com> wrote in message Dan, just enough for me to almost hang myself. I'm posting my solution ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-22-2008, 05:09 PM
Monty
 
Posts: n/a
Default Re: Queen/Pink Floyd

DA Morgan <damorgan@exesolutions.com> wrote in message

Dan, just enough for me to almost hang myself. I'm posting my solution
here not for criticism but to save someone else the large amount of
time it took me to write. And I know it shouldn't have taken me long.
Sad.

Monty


SQL> CREATE TABLE tbltest(a VARCHAR2(200));

Table created.

SQL> INSERT INTO tbltest(a)
2 VALUES ('brian may john deacon roger taylor freddy mercury');

1 row created.

SQL> INSERT INTO tbltest(a)
2 VALUES ('nick mason david gilmour roger waters richard wright');

1 row created.

SQL>
SQL> CREATE TABLE tokenised(b VARCHAR2(25));

Table created.

SQL>
SQL> DECLARE
2 CURSOR ctest IS SELECT * FROM tbltest;
3 ctestrow tbltest%ROWTYPE;
4
5 spacepositionoffset NUMBER;
6 spaceposition NUMBER;
7
8 BEGIN
9 OPEN ctest;
10 LOOP
11 FETCH ctest INTO ctestrow;
12 EXIT WHEN ctest%NOTFOUND;
13
14 spacepositionoffset:=1;
15 LOOP
16 spaceposition:=INSTR(ctestrow.a,' ',spacepositionoffset);
17 IF spaceposition=0 THEN
18 INSERT INTO tokenised(b) VALUES
(SUBSTR(ctestrow.a,spacepositionoffset,LENGTH(ctes trow.a)-spacepositionoffset+1));
19 ELSE
20 INSERT INTO tokenised(b) VALUES
(SUBSTR(ctestrow.a,spacepositionoffset,spacepositi on-spacepositionoffset));
21 END IF;
22
23 spacepositionoffset:=spaceposition+1;
24 EXIT WHEN spaceposition=0;
25 END LOOP;
26
27 END LOOP;
28 CLOSE ctest;
29 END;
30 /

PL/SQL procedure successfully completed.

SQL>
SQL>
SQL> SELECT b FROM tokenised;

B
-------------------------
brian
may
john
deacon
roger
taylor
freddy
mercury
nick
mason
david

B
-------------------------
gilmour
roger
waters
richard
wright

16 rows selected.

SQL>




> news:<3DFA6F21.A7AE713C@exesolutions.com>...
> Monty wrote:
>
> > Hi, don't ask why but ....
> >
> > CREATE TABLE tbltest(a VARCHAR2(200));
> > INSERT INTO tbltest(a) VALUES ('brian may john deacon roger taylor
> > freddy mercury');
> > INSERT INTO tbltest(a) VALUES ('nick mason david gilmour roger waters
> > richard wright');
> >
> > Is it a simple exercise to create another table from this table, so
> > that:
> >
> > SQL >
> > SQL > SELECT * FROM rock;
> > brian
> > may
> > john
> > deacon
> > roger
> > taylor
> > freddy
> > mercury
> > nick
> > mason
> > david
> > gilmour
> > roger
> > waters
> > richard
> > wright
> >
> > SQL>
> > SQL>

>
> Very simple.
>
> You will need:
> 1. An anonymous block
> 2. A cursor
> 3. A loop
> 4. INSTR
> 5. SUBSTR
> 6. An insert statement
> 7. A commit
>
> Dan Morgan

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-22-2008, 05:09 PM
DA Morgan
 
Posts: n/a
Default Re: Queen/Pink Floyd

Monty wrote:

> DA Morgan <damorgan@exesolutions.com> wrote in message
>
> Dan, just enough for me to almost hang myself. I'm posting my solution
> here not for criticism but to save someone else the large amount of
> time it took me to write. And I know it shouldn't have taken me long.
> Sad.
>
> Monty
>
> SQL> CREATE TABLE tbltest(a VARCHAR2(200));
>
> Table created.
>
> SQL> INSERT INTO tbltest(a)
> 2 VALUES ('brian may john deacon roger taylor freddy mercury');
>
> 1 row created.
>
> SQL> INSERT INTO tbltest(a)
> 2 VALUES ('nick mason david gilmour roger waters richard wright');
>
> 1 row created.
>
> SQL>
> SQL> CREATE TABLE tokenised(b VARCHAR2(25));
>
> Table created.
>
> SQL>
> SQL> DECLARE
> 2 CURSOR ctest IS SELECT * FROM tbltest;
> 3 ctestrow tbltest%ROWTYPE;
> 4
> 5 spacepositionoffset NUMBER;
> 6 spaceposition NUMBER;
> 7
> 8 BEGIN
> 9 OPEN ctest;
> 10 LOOP
> 11 FETCH ctest INTO ctestrow;
> 12 EXIT WHEN ctest%NOTFOUND;
> 13
> 14 spacepositionoffset:=1;
> 15 LOOP
> 16 spaceposition:=INSTR(ctestrow.a,' ',spacepositionoffset);
> 17 IF spaceposition=0 THEN
> 18 INSERT INTO tokenised(b) VALUES
> (SUBSTR(ctestrow.a,spacepositionoffset,LENGTH(ctes trow.a)-spacepositionoffset+1));
> 19 ELSE
> 20 INSERT INTO tokenised(b) VALUES
> (SUBSTR(ctestrow.a,spacepositionoffset,spacepositi on-spacepositionoffset));
> 21 END IF;
> 22
> 23 spacepositionoffset:=spaceposition+1;
> 24 EXIT WHEN spaceposition=0;
> 25 END LOOP;
> 26
> 27 END LOOP;
> 28 CLOSE ctest;
> 29 END;
> 30 /
>
> PL/SQL procedure successfully completed.
>
> SQL>
> SQL>
> SQL> SELECT b FROM tokenised;
>
> B
> -------------------------
> brian
> may
> john
> deacon
> roger
> taylor
> freddy
> mercury
> nick
> mason
> david
>
> B
> -------------------------
> gilmour
> roger
> waters
> richard
> wright
>
> 16 rows selected.
>
> SQL>
>
> > news:<3DFA6F21.A7AE713C@exesolutions.com>...
> > Monty wrote:
> >
> > > Hi, don't ask why but ....
> > >
> > > CREATE TABLE tbltest(a VARCHAR2(200));
> > > INSERT INTO tbltest(a) VALUES ('brian may john deacon roger taylor
> > > freddy mercury');
> > > INSERT INTO tbltest(a) VALUES ('nick mason david gilmour roger waters
> > > richard wright');
> > >
> > > Is it a simple exercise to create another table from this table, so
> > > that:
> > >
> > > SQL >
> > > SQL > SELECT * FROM rock;
> > > brian
> > > may
> > > john
> > > deacon
> > > roger
> > > taylor
> > > freddy
> > > mercury
> > > nick
> > > mason
> > > david
> > > gilmour
> > > roger
> > > waters
> > > richard
> > > wright
> > >
> > > SQL>
> > > SQL>

> >
> > Very simple.
> >
> > You will need:
> > 1. An anonymous block
> > 2. A cursor
> > 3. A loop
> > 4. INSTR
> > 5. SUBSTR
> > 6. An insert statement
> > 7. A commit
> >
> > Dan Morgan


You seem to have slipped the noose.

To be honest I took you for a student ... my response was intended to point you in
the right direction without handing you the answer.

Daniel Morgan

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:45 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com