Inserting row in the result set
Hi
need to insert a row in resultset when previous row typ=c and next row typ=p then need to insert one row in between typ c and p with typ =s see the #temp_result table for result expected
--drop table temp1
--drop table temp1_result
--presently data:-
create table temp1
(id int,
ord int,
typ varchar(2),
dt date)
insert into temp1 values (101, 1, 'c', '2001-10-01')
insert into temp1 values (101, 2, 'p', '2001-11-11')
insert into temp1 values (102, 1, 'c', '2002-10-01')
insert into temp1 values (102, 2, 'p', '2002-11-01')
insert into temp1 values (102, 3, 'p', '2002-12-01')
insert into temp1 values (103, 1, 'c', '2003-10-01')
insert into temp1 values (103, 2, 'p', '2003-11-01')
insert into temp1 values (104, 1, 'c', '2004-10-01')
insert into temp1 values (104, 2, 'c', '2004-11-01')
insert into temp1 values (104, 3, 'p', '2004-12-01')
insert into temp1 values (105, 1, 'c', '2005-10-01')
insert into temp1 values (105, 2, 'p', '2005-11-01')
insert into temp1 values (105, 3, 'c', '2005-12-01')
insert into temp1 values (106, 1, 'c', '2006-08-01')
insert into temp1 values (106, 2, 'p', '2006-09-01')
insert into temp1 values (106, 3, 'c', '2006-10-01')
insert into temp1 values (106, 4, 'p', '2006-11-01')
insert into temp1 values (106, 5, 'p', '2006-12-01')
select * from temp1
order by id, ord
--result expected:-
create table temp1_result
(id int,
ord int,
typ varchar(2),
dt date)
insert into temp1_result values (101, 1, 'c', '2001-10-01')
insert into temp1_result values (101, 2, 's', '')
insert into temp1_result values (101, 3, 'p', '2001-11-11')
insert into temp1_result values (102, 1, 'c', '2002-10-01')
insert into temp1_result values (102, 2, 's', '')
insert into temp1_result values (102, 3, 'p', '2002-11-01')
insert into temp1_result values (102, 4, 'p', '2002-12-01')
insert into temp1_result values (103, 1, 'c', '2003-10-01')
insert into temp1_result values (103, 2, 's', '')
insert into temp1_result values (103, 3, 'p', '2003-11-01')
insert into temp1_result values (104, 1, 'c', '2004-10-01')
insert into temp1_result values (104, 2, 'c', '2004-11-01')
insert into temp1_result values (104, 3, 's', '')
insert into temp1_result values (104, 4, 'p', '2004-12-01')
insert into temp1_result values (105, 1, 'c', '2005-10-01')
insert into temp1_result values (105, 2, 's', '')
insert into temp1_result values (105, 3, 'p', '2005-11-01')
insert into temp1_result values (105, 4, 'c', '2005-12-01')
insert into temp1_result values (106, 1, 'c', '2006-08-01')
insert into temp1_result values (106, 2, 's', '')
insert into temp1_result values (106, 3, 'p', '2006-09-01')
insert into temp1_result values (106, 4, 'c', '2006-10-01')
insert into temp1_result values (106, 5, 's', '')
insert into temp1_result values (106, 6, 'p', '2006-11-01')
insert into temp1_result values (106, 7, 'p', '2006-12-01')
select * from temp1_resultregards
Edited by: @2**** on 31-Jan-2012 06:48
Well, in an Oracle database, something like this...
SQL> ed
Wrote file afiedt.buf
1 with temp as (select 101 as id, 1 as ord, 'c' as typ, date '2001-10-01' as dt from dual union all
2 select 101, 2, 'p', date '2001-11-11' from dual union all
3 select 102, 1, 'c', date '2002-10-01' from dual union all
4 select 102, 2, 'p', date '2002-11-01' from dual union all
5 select 102, 3, 'p', date '2002-12-01' from dual union all
6 select 103, 1, 'c', date '2003-10-01' from dual union all
7 select 103, 2, 'p', date '2003-11-01' from dual union all
8 select 104, 1, 'c', date '2004-10-01' from dual union all
9 select 104, 2, 'c', date '2004-11-01' from dual union all
10 select 104, 3, 'p', date '2004-12-01' from dual union all
11 select 105, 1, 'c', date '2005-10-01' from dual union all
12 select 105, 2, 'p', date '2005-11-01' from dual union all
13 select 105, 3, 'c', date '2005-12-01' from dual union all
14 select 106, 1, 'c', date '2006-08-01' from dual union all
15 select 106, 2, 'p', date '2006-09-01' from dual union all
16 select 106, 3, 'c', date '2006-10-01' from dual union all
17 select 106, 4, 'p', date '2006-11-01' from dual union all
18 select 106, 5, 'p', date '2006-12-01' from dual)
19 --
20 -- end of test data
21 --
22 select id
23 ,row_number() over (partition by id order by ord, typ) as ord
24 ,typ
25 ,dt
26 from (
27 select id
28 ,ord
29 ,case when rn = 2 and add_typ = 's' then add_typ else typ end as typ
30 ,case when rn = 1 then dt else null end as dt
31 from (
32 select t.id, t.ord, t.typ, t.dt
33 ,case when typ = 'c' and lead(typ) over (partition by id order by ord) = 'p' then 's'
34 else null end as add_typ
35 from temp t
36 ) x
37 cross join (select rownum rn from dual connect by rownum <= 2)
38 where not (rn = 2 and add_typ is null)
39 )
40* order by id, ord
SQL> /
ID ORD T DT
101 1 c 01-OCT-2001 00:00:00
101 2 s
101 3 p 11-NOV-2001 00:00:00
102 1 c 01-OCT-2002 00:00:00
102 2 s
102 3 p 01-NOV-2002 00:00:00
102 4 p 01-DEC-2002 00:00:00
103 1 c 01-OCT-2003 00:00:00
103 2 s
103 3 p 01-NOV-2003 00:00:00
104 1 c 01-OCT-2004 00:00:00
104 2 c 01-NOV-2004 00:00:00
104 3 s
104 4 p 01-DEC-2004 00:00:00
105 1 c 01-OCT-2005 00:00:00
105 2 s
105 3 p 01-NOV-2005 00:00:00
105 4 c 01-DEC-2005 00:00:00
106 1 c 01-AUG-2006 00:00:00
106 2 s
106 3 p 01-SEP-2006 00:00:00
106 4 c 01-OCT-2006 00:00:00
106 5 s
106 6 p 01-NOV-2006 00:00:00
106 7 p 01-DEC-2006 00:00:00
25 rows selected.
Similar Messages
-
How to add a dummy row in the result set of a SELECT statement.
Hello Everyone -
I have requirment to add a dummy row in the result set of a SELECT statement.
For e.g. lets say there is a table Payment having following colums:
Payment_id number
status varchar2(10)
amount number
payment_date date
so here is the data :-
Payment_id Status Amount payment_date
1 Applied 100 12/07/2008
2 Reversed 200 01/ 06/2009
3 Applied 300 01/ 07/2009
Here is my SQL
Select * form payment where payment_date >= 01/01/2009
Output will be
2 Reversed 200 01/ 06/2009
3 Applied 300 01/ 07/2009
My desired output is below
2 Reversed 200 01/ 06/2009
3 Applied 300 01/ 07/2009
2 Reversed -200 01/ 06/2009 ------(Dummy Row)
Thrid row here is the dummy row which I want to add when status is "Reversed"
I would be very thankful for any kind of help in this regard ...
Thanks,
GauravCartesion joining against a dummy table is a useful method of creating a dummy row:
with my_tab as (select 1 cust_id, 1 Payment_id, 'Applied' Status, 100 Amount, to_date('12/07/2008', 'mm/dd/yyyy') payment_date from dual union all
select 1 cust_id, 2 Payment_id, 'Reversed' Status, 200 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
select 1 cust_id, 3 Payment_id, 'Applied' Status, 300 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
select 2 cust_id, 1 Payment_id, 'Applied' Status, 100 Amount, to_date('12/07/2008', 'mm/dd/yyyy') payment_date from dual union all
select 2 cust_id, 2 Payment_id, 'Reversed' Status, 200 Amount, to_date('01/05/2009', 'mm/dd/yyyy') payment_date from dual union all
select 2 cust_id, 3 Payment_id, 'Applied' Status, 300 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
select 2 cust_id, 4 Payment_id, 'Reversed' Status, -400 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
select 2 cust_id, 5 Payment_id, 'Applied' Status, 500 Amount, to_date('01/07/2009', 'mm/dd/yyyy') payment_date from dual),
--- end of mimicking your table
dummy as (select 'Reversed' col1, 1 rn from dual union all
select 'Reversed' col1, 2 rn from dual)
select mt.cust_id,
mt.payment_id,
mt.status,
decode(dummy.rn, 2, -1*mt.amount, mt.amount) amount,
mt.payment_date
from my_tab mt,
dummy
where mt.status = dummy.col1 (+)
order by mt.cust_id, mt.payment_id, dummy.rn nulls first;
CUST_ID PAYMENT_ID STATUS AMOUNT PAYMENT_DATE
1 1 Applied 100 07/12/2008
1 2 Reversed 200 06/01/2009
1 2 Reversed -200 06/01/2009
1 3 Applied 300 06/01/2009
2 1 Applied 100 07/12/2008
2 2 Reversed 200 05/01/2009
2 2 Reversed -200 05/01/2009
2 3 Applied 300 06/01/2009
2 4 Reversed -400 06/01/2009
2 4 Reversed 400 06/01/2009
2 5 Applied 500 07/01/2009Edited by: Boneist on 07-Jan-2009 23:10
NB. You may have to mess around with the ordering if that's not come back in the order you wanted. You didn't mention what the rules were for any expected ordering though, so I've made up my own *{;-)
Also, I added an identifier (cust_id) to differentiate between different sets of payments, since that's usually the case. Remove that if it's not applicable for your case. -
How to exclude the XML declaration from each row of the result set?
Hi,
I have a table with an XMLTYPE column and would like to SELECT a set of rows. How can I exclude the XML declaration from each row in the result set? My query currently looks like this, I'm executing it through Spring JDBC:
SELECT XMLSerialize(CONTENT t1.xmltext) FROM myschema.event t1 WHERE XMLEXISTS('$e/Event' PASSING XMLTEXT AS "e") ORDER BY t1.time DESC
After selecting, in my application I convert each row into a String and concatenate all rows into one big string in order to parse it into a DOM model. I get a parser exception (org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed) because there are multiple XML declarations in my big string. Of course, I could manually check the String of each row whether it starts with the XML declaration, but it would be nicer if I could instruct the DB not to add it in the first place. Is there a way?
Thanks!
-- DanielaHi,
A couple of options I can think of :
SELECT XMLSerialize(CONTENT
XMLtransform(t1.xmltext,
xmltype('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="/"><xsl:copy-of select="*"/></xsl:template>
</xsl:stylesheet>')
FROM myschema.event t1
WHERE XMLEXISTS('$e/Event' PASSING XMLTEXT AS "e")
ORDER BY t1.time DESC
;or simply,
SELECT XMLSerialize(CONTENT
extract(t1.xmltext,'/')
FROM myschema.event t1
WHERE XMLEXISTS('$e/Event' PASSING XMLTEXT AS "e")
ORDER BY t1.time DESC
; -
Getting specific row of the result set.
table: employee
empno number(20)
ssan varchar2(9)
date_time_stamp date
My Sql gets all the empno where ssan and date_time_stamp are equal.
However I need previous row from max(empno) where ssan & date_time_stamp are equal.
For eg:
empno ssan date_time_stamp
100 123456789 01-FEB-2004
101 000000000 02-FEB-2004
102 123456789 01-FEB-2004
103 123456789 01-FEB-2004
105 123456789 01-FEB-2004
I need row with empno = 103.
My current sql fetches all rows for particular ssan where ssan and date time stamp are equal that fetches all empno for particular ssan and date time stamp. I want the max(empno) -1 (previous row of the result set).
Here is my sql:
select empno,ssan,date_time_stamp
from employee e
where date_time_stamp in (select date_time_stamp from employee where e.ssan = ssan)
order by empno,ssan;
The above sql will fetch
empno ssan date_time_stamp
100 123456789 01-FEB-2004
102 123456789 01-FEB-2004
103 123456789 01-FEB-2004 ---> I need this row, previous row from max(empno) where ssan and date time
stamp are matching.
105 123456789 01-FEB-2004
101 000000000 02-FEB-2004If I understand correctly, you want the second highest empno for each unique combination of ssan and date_time_stamp. If so, given
SQL> SELECT * FROM employee;
EMPNO SSAN DATE_TIME_S
102 123456789 01-feb-2004
103 123456789 01-feb-2004
105 123456789 01-feb-2004
100 123456678 01-feb-2004
102 123456678 01-feb-2004
103 123456678 01-feb-2004
101 000000000 02-feb-2004
105 123456678 01-feb-2004
100 123456678 02-feb-2004
102 123456678 02-feb-2004
103 123456678 02-feb-2004
105 123456678 02-feb-2004
100 123456789 01-feb-2004Then something like this should do it.
SQL> SELECT empno,ssan,date_time_stamp
2 FROM (SELECT empno,ssan,date_time_stamp,
3 RANK() OVER (PARTITION BY ssan,date_time_stamp
4 ORDER BY empno DESC) rk
5 FROM employee)
6* WHERE rk = 2;
EMPNO SSAN DATE_TIME_S
103 123456678 01-feb-2004
103 123456678 02-feb-2004
103 123456789 01-feb-2004HTH
John -
INSERTing a blank row in the result set
Hi friends,
SELECT * FROM EMPLOYEES ORDER BY DEPARTMENT_ID;
In the result of the above, I need to INSERT a blank row in the result for each DEPARTMENT_ID. i.e., the result should look like the following:
EMP_ID - NAME - SALARY - DEPARTMENT_ID
101 - Albert - 10,000 - 10
102 - Benjamin - 8,000 - 10
103 - Chitra - 10,500 - 20
104 - David - 4,500 - 20
105 - Elango - 6,000 - 20
106 - Fathima - 6,000 - 30
107 - Ganga - 9,000 - 30
etc.
I don't want to insert into the table. Just in display I need a blank row.
Thanks in advance.
Edited by: Iniyavan on Mar 8, 2010 11:37 AMAre you looking for this?
satyaki>select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
PL/SQL Release 11.1.0.6.0 - Production
CORE 11.1.0.6.0 Production
TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
NLSRTL Version 11.1.0.6.0 - Production
Elapsed: 00:00:00.00
satyaki>
satyaki>select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
Elapsed: 00:00:00.00
satyaki>
satyaki>break on deptno
satyaki>
satyaki>
satyaki>select empno,
2 ename,
3 sal,
4 deptno
5 from emp
6 order by deptno;
EMPNO ENAME SAL DEPTNO
7782 CLARK 2450 10
7839 KING 5000
7934 MILLER 1300
7566 JONES 2975 20
7902 FORD 3000
7876 ADAMS 1100
7369 SMITH 800
7788 SCOTT 3000
7521 WARD 1250 30
7844 TURNER 1500
7499 ALLEN 1600
EMPNO ENAME SAL DEPTNO
7900 JAMES 950 30
7698 BLAKE 2850
7654 MARTIN 1250
14 rows selected.
Elapsed: 00:00:00.04
satyaki>
satyaki>Regards.
Satyaki De. -
How to pass one row of a result set to a cffunction?
I can pass the entire result set of a query to a cffunction,
but the function only needs one row.
The code below is a syntax error, where "3" is array index
notation for the third row of the result set.
What is the correct way to pass one row of a result set to a
cffunction?
Thank you.iirc, cf does not allow one to reference and access a row of
a resultset
like that.
you will have to create a structure/array that holds the data
from
specific query row and pass that to your function. looping
over
queryname.columnlist list will make it easier and not
specific to any
particular query. make it into another function that accepts
a query and
row number as arguments and returns a struct/array of that
row data (or
automatically passes it to another function).
sample code for creating a structure of specific query row
data:
<cfset rowstruct = {}>
<cfloop list="#queryname.columnlist#" index="col">
<cfset rowstruct[col] = queryname[col][somerownumber]>
</cfloop>
<cfdump var="#rowstruct#">
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/ -
OBIEE Answers does not display the result set of a report query
Hi,
We have a pivot table type of report in Oracle Business Intelligence Enterprise Edition v.10.1.3.3.2 Answers that has the following characteristics:
3 Pages
3 Sections , 4 Columns
18363 Rows in the result set
As per the NQQuery.log, the query for this report executes successfully resulting in 18363 rows. However, nothing comes up in the display on Answers. Moreover, no error is reported. The instanceconfig.xml file has the following setting:
<PivotView>
<CubeMaxRecords>30000</CubeMaxRecords>
<CubeMaxPopulatedCells>300000</CubeMaxPopulatedCells>
</PivotView>
Even with these settings, Answers just returns a blank page - nothing is displayed in the name of the result set of the report query. Has anyone encountered this problem scenario before?
Any help is much appreciated.
Thanks,
PiyushHi Fiston / Pradeep,
Thanks for your inputs. A few points to note:
-> I am actually not getting any error message in answers or the NQQuery log. Moreover I am not getting any errors related to "query governor limit exceeding in cube generation" also.
-> I have other pivot table type of reports in the same repository that work fine. In fact the report which has this issue even works sometimes - what actually is happening is that if I alter the number of sections from 3 to 4, then the result set changes from 14755 Rows to 18363 Rows and as per the NQQuery.log in both cases the query completes successfully. However, when the result set has 14755 rows, I get to see the output in Answers; however when the result set is 18636 rows, the Answers screen just goes blank and does not show any output or error. This makes me believe that there is some parameter in instanceconfig or the NQSconfig file - I have tried a lot of changes but nothing works !
Any help is much appreciated.
Best Regards,
Piyush -
The result set that contain 10 rows always
Hi all,
I'm wondering if there is some way to produce the result set of a query in 10 rows always, in other word i run a query and i want that the result set in 10 row even if the query dosn't return any row.
I need that row as a placeholder.
thanks
FrancescoHappened to be GUI developer and try to take advantage of SQL,
select * from (select rownum rn, e.* from emp e where rownum<11 and 1=2) e
right join (select rownum rn from dual connect by rownum<11) t
on t.rn=e.rn
RN
EMPNO ENAME
JOB
MGR HIREDATE
SAL
COMM
DEPTNO
RN
5
8
3
1
2
10
6
7
4
9
10 rows selected.
select * from (select rownum rn, e.* from emp e where rownum<11) e
right join (select rownum rn from dual connect by rownum<11) t
on t.rn=e.rn
RN
EMPNO ENAME
JOB
MGR HIREDATE
SAL
COMM
DEPTNO
RN
1
7369 SMITH
CLERK
7902 17-DEC-80
800
20
1
2
7499 ALLEN
SALESMAN
7698 20-FEB-81
1600
300
30
2
3
7521 WARD
SALESMAN
7698 22-FEB-81
1250
500
30
3
4
7566 JONES
MANAGER
7839 02-APR-81
2975
20
4
5
7654 MARTIN
SALESMAN
7698 28-SEP-81
1250
1400
30
5
6
7698 BLAKE
MANAGER
7839 01-MAY-81
2850
30
6
7
7782 CLARK
MANAGER
7839 09-JUN-81
2450
0
10
7
8
7788 SCOTT
ANALYST
7566 19-APR-87
3000
20
8
9
7839 KING
PRESIDENT
17-NOV-81
5000
0
10
9
10
7844 TURNER
SALESMAN
7698 08-SEP-81
1500
0
30
10
10 rows selected. -
Getting the first row of a result set
I need to get the first row returned from a select query that looks like this:
SELECT DISTINCT parm1 FROM table1 WHERE parm1 > 10 ORDER BY parm1
Can someone please show me how to do this?
AlexBecause you're only getting one row you don't need to bother with a DISTINCT clause. You'll need to order your data first and then nab the first row from that result set.
SELECT parm1
FROM (SELECT parm1
FROM table1
WHERE parm1 > 10
ORDER BY parm1)
WHERE ROWNUM <= 1; -
How to get the result set in batches
I have a query which results into large data. This data i want to display in a group of 20. After every 20 records i want to add header and footer to it.
Is it possible to get the result set data into batch of 20 ? means can i specify start and end index of query ?
regards
ManishaWhat I am saying is that a big query with lots of
joins will probably be slow, and as such would be a
ripe candidate for batching the responses, if it were
not possible to speed/optimize it. Batching is nice
to look at for the user, but is not a solution for
performance problems. In essence it is irrelevant
that it adds a little performance deficit, as it
appears to be running a lot quicker, and gives more
feedback to the user.Then let me say it again....
- "Join" is a term that applies to a method of doing queries in the database....
- Query 1 which uses a join and returns 15 rows
- Query 2 which does not use a join and returns 1500 rows.
Given the above then Query 1 will provide better overall performance for the system than Query 2 in a properly configured database.
If it doesn't then the database is not set up correctly.
And again this will be irrespective of whether the query is scrollable or not. -
By which method,i can get the no of rows in the record set?
Does anyone help me that by which method,i can get the no of rows in the record set?
now i use next() to check whether the next record is available or not?shashi_rajak wrote:
under Practice Exercise #1 heading :
there is a statement.
"Now, the COUNT function does not need to retrieve all of the fields from the table (ie: employee_number, employee_name, and salary), but rather whenever the condition is met, it will retrieve the numeric value of 1. Thus, increasing the performance of the SQL statement."And have you ever tried it? Or do you simply blindly believe everything you read? And what sort of "authority" is "tech on the net"?
P.S. A quick test on Oracle (and you must do each query at least twice throwing away the first result, as Oracle always caches things which will have an effect, and averaging the remaining attempts).
count(*) -- 1 min 17 secs for 35,311,978 rows
count(1) -- 1 min 19 secs for 35,311,978 rows
Edit: And the table has 46 columns. -
How to hide the all rows except the result row in a report?
Hi Experts,
We have a report in which the user is interested to see only the result rows and I need to HIDE the characteristics in the rows. I was successfull in doing the same for Key figures in columns using "Calculate single value as suppress result". But I am not finding a way out to hide the characteristics in the rows.
If I move the characteristics in rows to Free characteristics, the result row is not getting dispalyed. Also, the characteristics are used dynamically by the formulae in columns and hence i cant remove these characteristics from the query. . The user wants the query to contain only one characteristic in the row and the result row for the key figures in columns. The report currently displays Invoice level data for each customer and this needs to be eliminated and it should display the summarised data for every customer. Please suggest how this can be accomplished
Regards,
KavithaMoving the char to free char will show the equivalent of result.
Your issue likely is that this breaks the calculations since you do want the calculations done at detail level.
To achieve this, move your char to free char (say it is 0CUSTOMER).
For the CKF/Formula, go to aggregation tab, set the exception aggregation as Total (or whatever it was in standard behavior) and specify reference characteristic (in this case 0CUSTOMER), also check the 'Before aggregation' if you have that checkbox there.
This will ensure the calculation is done at detail level even though the char is not included in the rows.
If you have multiple chars to be moved to free char but included in detailed calculation, you will need to build cascading CKFs (CKF1 with ref char1, CKF2 eq to CKF1 with exception aggr on ref char2...and so on).
Added:
I understand you do want 0CUSTOMER in there, but something else (let us say 0DOCNO) removed. Use 0DOCNO in place of 0CUSTOMER in the case described above.
Edited by: Ajay Das on Aug 5, 2009 8:57 AM -
How to return the result set of multiple select statements as one result set?
Hi All,
I have multiple select statements in my stored procedure that I want to return as one result set
for instance
select id from tableA
union
select name from table b
but union will not work because the result sets datatypes are not identical so how to go about this ?
ThanksYou have to CAST or CONVERT (or implicitly convert) the columns to the same datatype. You must find a datatype that both columns can be converted to without error. In your example I'm guessing id is an int and name is a varchar or nvarchar.
Since you didn't convert the datatypes, SQL will use its data precedence rules and attempt to convert name to an int. If any row contains a row that has a value in name that cannot be converted to an int, you will get an error. The solution is
to force SQL to convert the int to varchar. So you want something like
select cast(id as varchar(12)) from tableA
union
select name from tableb
If the datatypes are something other that int or varchar, you must find a compatable datatype and then convert one (or both) of the columns to that datatype.
Tom -
JSP Servlet and convert the result set of an SQL Query To XML file
Hi all
I have a problem to export my SQL query is resulty into an XML file I had fixed my servlet and JSP so that i can display all the records into my database and that the goal .Now I want to get the result set into JSP so that i can create an XML file from that result set from the jsp code.
thisis my servlet which will call the jsp page and the jsp just behind it.
//this is the servlet
import java.io.*;
import java.lang.reflect.Array;
import java.sql.*;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.*;
import javax.sql.*;
public *class *Campaign *extends *HttpServlet
*private* *final* *static* Logger +log+ = Logger.+getLogger+(Campaign.*class*.getName());
*private* *final* *static* String +DATASOURCE_NAME+ = "jdbc/SampleDB";
*private* DataSource _dataSource;
*public* *void* setDataSource(DataSource dataSource)
_dataSource = dataSource;
*public* DataSource getDataSource()
*return* _dataSource;
*public* *void* init()
*throws* ServletException
*if* (_dataSource == *null*) {
*try* {
Context env = (Context) *new* InitialContext().lookup("java:comp/env");
_dataSource = (DataSource) env.lookup(+DATASOURCE_NAME+);
*if* (_dataSource == *null*)
*throw* *new* ServletException("`" + +DATASOURCE_NAME+ + "' is an unknown DataSource");
} *catch* (NamingException e) {
*throw* *new* ServletException(e);
protected *void *doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
Connection conn = *null*;
*try* {
conn = getDataSource().getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select post_id,comments,postname from app.posts");
// out.println("Le résultat :<br>");
ArrayList <String> Lescomments= *new* ArrayList<String>();
ArrayList <String> Lesidentifiant = *new* ArrayList<String>();
ArrayList <String> Lesnoms = *new* ArrayList <String>();
*while* (rs.next()) {
Lescomments.add(rs.getString("comments"));
request.setAttribute("comments",Lescomments);
Lesidentifiant.add(rs.getString("post_id"));
request.setAttribute("id",Lesidentifiant);
Lesnoms.add(rs.getString("postname"));
request.setAttribute("nom",Lesnoms);
rs.close();
stmt.close();
*catch* (SQLException e) {
*finally* {
*try* {
*if* (conn != *null*)
conn.close();
*catch* (SQLException e) {
// les paramètres sont corrects - on envoie la page réponse
getServletContext().getRequestDispatcher("/Campaign.jsp").forward(request,response);
}///end of servlet
}///this is the jsp page called
<%@ page import="java.util.ArrayList" %>
<%
// on récupère les données
ArrayList nom=(ArrayList)request.getAttribute("nom");
ArrayList id=(ArrayList)request.getAttribute("id");
ArrayList comments=(ArrayList) request.getAttribute("comments");
%>
<html>
<head>
<title></title>
</head>
<body>
Liste des campagnes here i will create the xml file the problem is to display all rows
<hr>
<table>
<tr>
</tr>
<tr>
<td>Comment</td>
<td>
<%
for( int i=0;i<comments.size();i++){
out.print("<li>" + (String) comments.get(i) + "</li>\n");
}//for
%>
</tr>
<tr>
<td>nom</td>
<td>
<%
for( int i=0;i<nom.size();i++){
out.print("<li>" + (String) nom.get(i) + "</li>\n");
}//for
%>
</tr>
<tr>
<td>id</td>
<td>
<%
for( int i=0;i<id.size();i++){
out.print("<li>" + (String) id.get(i) + "</li>\n");
}//for
%>
</tr>
</table>
</body>
</html>
This is how i used to create an XML file in a JSP page only without JSP/SERVLET concept:
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%
// Identify a carriage return character for each output line
int iLf = 10;
char cLf = (*char*)iLf;
// Create a new empty binary file, which will content XML output
File outputFile = *new* File("C:\\Users\\user\\workspace1\\demo\\WebContent\\YourFileName.xml");
//outputFile.createNewFile();
FileWriter outfile = *new* FileWriter(outputFile);
// the header for XML file
outfile.write("<?xml version='1.0' encoding='ISO-8859-1'?>"+cLf);
try {
// Define connection string and make a connection to database
Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/SAMPLE","app","app");
Statement stat = conn.createStatement();
// Create a recordset
ResultSet rset = stat.executeQuery("Select * From posts");
// Expecting at least one record
*if*( !rset.next() ) {
*throw* *new* IllegalArgumentException("No data found for the posts table");
outfile.write("<Table>"+cLf);
// Parse our recordset
// Parse our recordset
*while*(rset.next()) {
outfile.write("<posts>"+cLf);
outfile.write("<postname>" + rset.getString("postname") +"</postname>"+cLf);
outfile.write("<comments>" + rset.getString("comments") +"</comments>"+cLf);
outfile.write("</posts>"+cLf);
outfile.write("</Table>"+cLf);
// Everything must be closed
rset.close();
stat.close();
conn.close();
outfile.close();
catch( Exception er ) {
%>Please state your problem that you are having more clearly so we can help.
I looked at your code I here are a few things you might consider:
It looks like you are putting freely typed-in comments from end-users into an xml document.
The problem with this is that the user may enter characters in his text that have special meaning
to xml and will have to be escaped correctly. Some of these characters are less than character, greater than character and ampersand character.
You may also have a similiar problem displaying them on your JSP page since there may be special characters that JSP has.
You will have to read up on how to deal with these special characters (I dont remember what the rules are). I seem to recall
if you use CDATA in your xml, you dont have to deal with those characters (I may be wrong).
When you finish writing your code, test it by entering all keyboard characters to make sure they are processed, stored in the database,
and re-displayed correctly.
Also, it looks like you are putting business logic in your JSP page (creating an xml file).
The JSP page is for displaying data ONLY and submitting back to a servlet. Put all your business logic in the servlet. Putting business logic in JSP is considered bad coding and will cause you many hours of headache trying to debug it. Also note: java scriptlets in a JSP page are only run when the JSP page is compiled into a servlet by java. It does not run after its compiled and therefore you cant call java functions after the JSP page is displayed to the client. -
We have a GUI swing screen in which we have navigation buttons.
when the user clicks the previous ,next, last,first buttons we have to show the records accordingly.
The min. size of the database is around 1 million.and each row has 60 columns.
Our approach is screen--->servlet-->ejb beans --->database.
since the database is huge how to hold the values, and where, without affecting the performance.
If we get the resultset it holds all the data.since the data size is huge,we are looking for a solution.The user may browse through the data ,edit the data and delete the data.
we have to perform accordingly. Also, if, for example, user1 is seeing record no.1 & user 2 has modified record no.3 in the meanwhile, when user1 goes to record no.3, he should see the
modified record. In short, the user should always see the latest values.
please give us the best approach to solve this problem.
Also this is in a multi user environment.It seems like you need to look at threads to update current values in the display and narrow the result set that you retrieve to match the criteria needed for display. You might consider making the method to change values a syncronized one.
Maybe you are looking for
-
Database does not exist, but visible in EAS console
Dear Sir/Madam, We had a problem with a corrupted security file. We have replaced the corrupted essbase.sec with an older version. Now it all works again, but when I open the tree in EAS console, I can see two databases which didn't exist before the
-
System-Wide Formatting not applied to Dashboard Column Prompt in 11g
In OBIEE 11g, I have a dashboard column prompt with a date column. I use this column in the analysis and have made the column properties (formatting) a system-wide default for that column. When I use the column in a dashboard column prompt, it does n
-
How Do I Paste Metadata in Bridge?
In CS5 you can paste metadata in the Bridge>Get Info panel. I can't do it in CS6. How do I copy all my keywords and descriptions? Mac 10.6.8
-
Trying to move a users from one database to another gives error
When I try moving a user from one database to another I get an error, but one some PC's installed with EMC, gives no problems. So what could the the issue here, I tried googling, but came out without any solution. Exchange 2010 sp3, EMC on Windows 7
-
This has been going on for a long time. Note: I've been hoping that each updates and itunes would fix this, but they didn't.