Thread: Sql query creating a view


Permlink Replies: 3 - Pages: 1 - Last Post: May 14, 2007 8:15 AM Last Post By: marias
kirk

Posts: 79
Registered: 01/12/07
Sql query creating a view
Posted: May 14, 2007 8:00 AM
Click to report abuse...   Click to reply to this thread Reply
Hi I need to create a simple view like this

No Count
10 15

to get the No i am using a function which would normally return 1 value like 10 above but could sometimes return 2 numbers in the following format 10:5
When I get a number like this i need to split it into 2 rows in the view with the same count.

No Count
10 15
5 15

at the moment i get this

No Count
10:5 15
5 15

I can use plsql or sql thanks in advance

kirk

kirk

Posts: 79
Registered: 01/12/07
Re: Sql query creating a view
Posted: May 14, 2007 8:06 AM   in response to: kirk in response to: kirk
Click to report abuse...   Click to reply to this thread Reply
Not sure i was clear enough so heres my view as it stands

CREATE OR REPLACE FORCE VIEW "Q_ABSENCE" ("OWNERID", "OWNERTYPE", "TYPE", "ITEMCOUNT") AS
select distinct 'No',
count(*) as itemcount
from sick_absence
where ab_proccessed =2
and AB_COORDPROCESSED = 'No'
group by ab_owner

Which would return the following data

NO Count
10 2
5 4
4:3 2
2 1
234:23 4

I need it to return

No Count
10 2
5 4
4 2
3 2
2 1
234 4
23 4

thanks for your time

Kirk

The Flying Spon...

Posts: 750
Registered: 10/06/06
Re: Sql query creating a view
Posted: May 14, 2007 8:08 AM   in response to: kirk in response to: kirk
Click to report abuse...   Click to reply to this thread Reply
Captains log, stardate 1407900. Supplementary log in Captain's Absence.

Kirk, has been taken prisoner on the planet Ramble and all communications have become illogical.

We are looking to reroute the comms equipment through the photon generator to amplify the meaning, in the mean time I am holding out for hope that his communication will be reiterated in a fashion more likely to be understandable.
marias

Posts: 1,428
Registered: 06/23/06
Re: Sql query creating a view
Posted: May 14, 2007 8:15 AM   in response to: kirk in response to: kirk
Click to report abuse...   Click to reply to this thread Reply
try like this...for splitting values

with t as
(select '10:5' no,15 cnt from dual union all
select '11',20 from dual)
select distinct substr (s, instr(s,':',1,l) + 1 , instr(s,':',1,l+1) - instr(s,':',1,l) - 1 ) no,cnt
from (select cnt,':' || no || ':' s, level l from t connect by level <= length(no) - length(replace(no,':')) + 1)
order by cnt;

NO CNT

----------
10 15
5 15
11 20
Legend
Guru Guru : 2500 - 1000000 pts
Expert Expert : 1000 - 2499 pts
Pro Pro : 500 - 999 pts
Journeyman Journeyman : 200 - 499 pts
Newbie Newbie : 0 - 199 pts
Oracle ACE Director
Oracle ACE Member
Oracle Employee ACE
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums