groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bay Batu <batuhanbayra...@gmail.com>
Subject Re: Groovy Better Approach to create comma separated string from Database Select Query
Date Sat, 16 Jul 2016 10:00:09 GMT
Hi,

You can use PL/SQL’s built-in aggregation method with your joins.

psuedo code:
select listagg(i.value, ',') within GROUP(order by i.priority) 
from user u
left outer join infotable i on i.id = u.info_id
where …;

It would be wrong query, i did not test it but main part is “listagg within group”.


> On Jul 16, 2016, at 06:43, GroovyBeginner <groovybeginner@gmail.com> wrote:
> 
> I am trying to connect to oracle database table and pull the data and form
> the result in the form of comma separated values. I have written a sample
> code which works fine but wanted to have a better approach if the query is
> associated with more tables (joins), then the time is taken to get the
> output is more. Is there any better way of improving the performance.
> 
> import groovy.sql.Sql;
> import java.sql.ResultSet;
> 
> def temp="";
> def temp1="";
> sql = Sql.newInstance("jdbc:oracle:thin:@localhost:1521:XE","username",
> "password", "oracle.jdbc.driver.OracleDriver")
> sql.eachRow("select empid, empname FROM employee") {
>    temp1=it.toRowResult().values().join(", ")
>    if(temp=="") {
>        temp=temp1;
>    }else{
>        temp=temp+"\n"+temp1
>    }          
> }
> 
> 
> 
> --
> View this message in context: http://groovy.329449.n5.nabble.com/Groovy-Better-Approach-to-create-comma-separated-string-from-Database-Select-Query-tp5734115.html
> Sent from the Groovy Dev mailing list archive at Nabble.com.


Mime
View raw message