Posts Tagged ‘sql’

28
Apr

how to get all rows in a single row?

   Posted by: İsmail ÇAKIR    in oracle

today one of my collague asked me to how to fetch all rows of a parameter table in a single row with .

so i wrote this.

select * from
(select * from (select rownum as rnum, c.* from ( select b.* from user.test b order by rowid) c) where rnum = 1),
(select * from (select rownum as rnum, c.* from ( select b.* from user.test b order by rowid) c) where rnum = 2),
(select * from (select rownum as rnum, c.* from ( select b.* from user.test b order by rowid) c) where rnum = 3),
(select * from (select rownum as rnum, c.* from ( select b.* from user.test b order by rowid) c) where rnum = 4),
(select * from (select rownum as rnum, c.* from ( select b.* from user.test b order by rowid) c) where rnum = 5),
(select * from (select rownum as rnum, c.* from ( select b.* from user.test b order by rowid) c) where rnum = 6),
(select * from (select rownum as rnum, c.* from ( select b.* from user.test b order by rowid) c) where rnum = 7),
(select * from (select rownum as rnum, c.* from ( select b.* from user.test b order by rowid) c) where rnum = 8),
(select * from (select rownum as rnum, c.* from ( select b.* from user.test b order by rowid) c) where rnum = 9),
(select * from (select rownum as rnum, c.* from ( select b.* from user.test b order by rowid) c) where rnum = 10)

example gets 1o rows in a single row, actually it was constant 78 rows.
so he could used it like
resultset.getString(“param1″+i) with a loop.

and then he also needed 5 by 5 collected results with 2x columns in each view.

and my solution is

select * from
(select rownum as rx, b.* from (
select rownum as rnum, rowid as rid, a.* from (select param_a, param_b, param_c, param_d, param_e from user.test order by param_a, param_b, param_c) a) b
where rnum >=5 and rnum < 10) x,
(select rownum as rx, b.* from (
select rownum as rnum, rowid as rid, a.* from (select param_a, param_b, param_c, param_d, param_e from user.test order by param_a, param_b, param_c) a) b
where rnum >=10 and rnum < 15) y where x.rnum + 5 = y.rnum ;

anyone knows easier and more optimised way to do these?

Bookmark and Share
Tags: , , , ,

Tags: , , , ,

7
Mar

sql between operatörü

   Posted by: Muhammed YÜRÜRDURMAZ    in Database, oracle

select * from tablo where sayi  1 and 5

kullanırken between operatörünbe dikkat edin. bazı veritabanlarında 1 dahil olmazken bazılarında 5 dahil olmuyor. bazırlarında 1 ve 5 dahil olurken bazılarında 1 ve 5 dahil olmuyor

örnek olarak üzerinde 1 ve 5 dahil oluyor

Bookmark and Share
Tags: , , ,

Tags: , , ,

Switch to our mobile site