Unpivot using order by clause
Hello everyone , can somebody please explain the difference in the VALUE column when DESCRIPTION = 'dept' when the query is run with and without the order by clause.
SELECT * FROM
SELECT * FROM emp
--ORDER BY job
)UNPIVOT (VALUE FOR DESCRIPTION IN (sal AS 'salary', deptno AS 'dept'));
Bug? 9900850.8
A workaround could be
with emp_1 as
select ename,sal,deptno,deptno dep_dummy,empno --"or whatever column wanted..
from emp
SELECT ename,DESCRIPTION,VALUE
from
select *
from emp_1
UNPIVOT
VALUE FOR DESCRIPTION IN
(sal AS 'salary', deptno AS 'dept')
order by dep_dummy,empno,description; --"and other columns..
ENAME DESCRI VALUE
CLARK dept 10
CLARK salary 2450
KING dept 10
KING salary 5000
MILLER dept 10
MILLER salary 1300
SMITH dept 20
SMITH salary 800
JONES dept 20
JONES salary 2975
SCOTT dept 20
SCOTT salary 3000
ADAMS dept 20
ADAMS salary 1100
FORD dept 20
FORD salary 3000
ALLEN dept 30
ALLEN salary 1600
WARD dept 30
WARD salary 1250
MARTIN dept 30
MARTIN salary 1250
BLAKE dept 30
BLAKE salary 2850
TURNER dept 30
TURNER salary 1500
JAMES dept 30
JAMES salary 950
28 rows selected.
Edited by: jeneesh on May 16, 2013 11:00 AM
Similar Messages
-
How to use "Order by" clause dynamically on LOV values in 10g r2 forms
Hi ,
I have following requirement,please guide me.
1 Create a List Of Values with 2 fields, Code and Description
2. Do not use order by clause in record Group Query
3. Attach this LOV to a field in Form
4. When user invokes the LOV user will see two fields in LOV with header as Code and Description
5. Now when user clicks on Column Header “Code” then LOV should be sorted on Code
6. And if User clicks on Column Header “Description” then LOV should be sorted on Description
Thanks in Advance.Kindly post this problem in this forum ->
[Forms Forum|http://forums.oracle.com/forums/forum.jspa?forumID=82]
And, close this thread by marked it as answered. ;)
Regards.
Satyaki De. -
With out using order by clause
display the details of the employees with sal in descending order, without using order by clause
Don't forget that it's just for fun :)Well it's not entirely for fun :-)
There are real life users who might have real production problems and the rely and input/feedback from this forum.
I do not :)You spread untested answers/knowledge that might be wrong.
I can't imagine where you can see cartesian. It's
equijoin by primary key.I suggest you test it.
JFUI hierarchy is built after joining. And this
hierarchy is bamboo-tree. So result must be sorted
acording hierarchy.I know what hierarchical ordering is :-)
And here's a little test i did on your behalf, on the EMP table :-)
select e1.*
from e e1,
( select e2.id, count(*) as rn from e e2, e e3
where e3.sal >= e2.sal
and e3.id >= e2.id
group by e2.id
) e4
where e1.id = e4.id
start with e4.rn = 1
connect by e4.rn = prior e4.rn + 1
SQL*Plus: Release 10.1.0.4.2 - Production on Wed Jul 25 16:02:19 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Enter user-name: scott/tiger
Connected to:
Oracle Database 10g Release 10.2.0.1.0 - Production
SCOTT@ORCL> set lines 1000
SCOTT@ORCL>
SCOTT@ORCL>
SCOTT@ORCL> select emp1.*
2 from emp emp1,
3 ( select emp2.empno, count(*) as rn from emp emp2, emp emp3
4 where emp3.sal >= emp2.sal
5 and emp3.empno >= emp2.empno
6 group by emp2.empno
7 ) emp4
8 where emp1.empno = emp4.empno
9 start with emp4.rn = 1
10 connect by emp4.rn = prior emp4.rn + 1;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7839 KING PRESIDENT 17-DEC-80 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7566 JONES MANAGER 7839 02-APR-81 2975 20
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7566 JONES MANAGER 7839 02-APR-81 2975 20
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7900 JAMES CLERK 7698 03-DEC-81 950 30
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7566 JONES MANAGER 7839 02-APR-81 2975 20
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7902 FORD ANALYST 7566 3000 20
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7566 JONES MANAGER 7839 02-APR-81 2975 20
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7566 JONES MANAGER 7839 02-APR-81 2975 20
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7900 JAMES CLERK 7698 03-DEC-81 950 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7934 MILLER CLERK 7782 1301 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7566 JONES MANAGER 7839 02-APR-81 2975 20
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7566 JONES MANAGER 7839 02-APR-81 2975 20
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7900 JAMES CLERK 7698 03-DEC-81 950 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
42 rows selected.
SCOTT@ORCL>Regards,
Tony -
How to use order by within Group by clause
Hi All,
I need a help as to how should i use the Order by clause so that the data should be in order with respect to one column, and at the same time whole data is grouped by some other column...like
Select RaceNo,Venue,FP,BP from Race group by RaceNo
Here I want to order by FP in ascending order for each group. When i am using it , whole order is changing.
Can anybody suggest me how to use order by clause that would apply to each group of data.
Thanks .order by clause should be used at the last in any query.......but in group by clause u can't use use that becoz u group according to column then no ordering is needed there......if u want to filter something then u can use having clause and later if u need to arrange then u can use order by clause.........
i hope this eg.l gives u some clarification....
e.g
select deptno,count(empno)
from dept
group by deptno
having count(empno) > 10
order by deptno -
Without using order by and connect by clause
hi all,
can i write a tree query without using start with clause and connect by clause
and
can i order the employee names in a select query without using order by clause
can those things are possible in select statement...dipuna wrote:
hi all,
can i write a tree query without using start with clause and connect by clause
and
can i order the employee names in a select query without using order by clause
can those things are possible in select statement...A very odd question.
Those clauses are the means to do what you are asking. Why would you be looking for some other method? -
Order By Clause on Non-Database Column using Forms
How to Sort by using Order by Clause on Non-Database Column using Forms6i
Eugene,
What is the error message/ number you are seeing? If you run "select name from tblperson order by name" do you still get an error? -
How can i use Order by inside a sub query in Oracle
Hi!,
Please help me, it's an urgent... how can i use Order by clause
SELECT SalesProductKeyID,ActualUnitPrice,BillDateKeyID,ProductKeyID
,Qty,Profit,DD.dDate
, (SELECT nvl(S.Qty,0) FROM Stock S , DateDimension DD1
WHERE S.DateKeyID = DD1.DateKeyID AND
S.ProductKeyID = SF.ProductKeyID AND
DD1.dDate <= DD.dDate and rownum=1
ORDER BY DD1.dDate DESC*) as StockQty
, (SELECT nvl(SUM(Qty),0) from salesfact SF2,DATEDIMENSION DD2
WHERE SF2.BillDateKeyID=DD2.DatekeyID AND SF2.ProductKeyID=SF.ProductKeyid
AND DD2.dDate > DD.dDate
AND DD2.dDATE=DD.dDate
) as TotalQtySold
FROM SalesFact SF INNER JOIN DATEDIMENSION DD
ON SF.billdatekeyid =DD.Datekeyid
WHERE
IsProfitCalculated = 1 AND
IsSalesFactSuppPopulated =0 AND
Qty > 0;
kindly help
Thank you.Actually I'm converting Procedures from SQL Server to Oracle.
Actual Stored Procedure in SQL Server is as follows.
SELECT --top 10000
SalesProductKeyID,ActualUnitPrice,BillDateKeyID,ProductKeyID
,Qty,Profit,DD.Date
, (SELECT TOP 1 ISNULL(S.Qty,0) FROM dbo.Stock S , dbo.DateDimension DD1
WHERE S.DateKeyID = DD1.DateKeyID AND
S.ProductKeyID = SF.ProductKeyID AND
DD1.Date <= DD.Date
ORDER BY DD1.Date DESC) as StockQty
, (SELECT ISNULL(SUM(Qty),0) from salesfact SF2,DATEDIMENSION DD2
WHERE SF2.BillDateKeyID=DD2.DatekeyID AND SF2.ProductKeyID=SF.ProductKeyid
AND DD2.Date > DD.Date
AND DD2.DATE=DD.Date
) as TotalQtySold
--INTO TEMP_Salesfact
FROM dbo.SalesFact SF INNER JOIN DATEDIMENSION DD
ON SF.billdatekeyid =DD.Datekeyid
WHERE
IsProfitCalculated = 1 AND
IsSalesFactSuppPopulated =0 AND
Qty > 0 -
Order by clause in cursor problem
Hello,
I'm unable to compile package body when i'm using order by clause in cursor subquery in stored procedure.
Sample code:
CREATE PACKAGE Announces AS
TYPE tRefCur IS REF CURSOR;
PROCEDURE TopAnnounces(
iiCount IN NUMBER,
osAnnounces OUT tRefCur,
oiRetVal OUT NUMBER
END Announces;
CREATE PACKAGE BODY Announces AS
PROCEDURE TopAnnounces(
iiCount IN NUMBER,
osAnnounces OUT NUMBER,
oiRetVal OUT NUMBER
AS
BEGIN
OPEN osAnnounces FOR
SELECT Id, Name, AnnCount FROM
SELECT Id, Name, COUNT(CategoryId) AS AnnCount FROM tblAnnounces
GROUP BY Id, Name
-- bellow is the line, where the code crash
ORDER BY AnnCount DESC
WHERE ROWNUM < iiCount + 1;
oiRetVal := 0;
EXCEPTION
WHEN OTHERS THEN
oiRetVal := -255;
END TopAnnounces;
END Announces;
If I compile the code above I will get this error:
PLS-00103: Encoutered the symbol "ORDER" when expecting on of the following:
After I remark the problematic line, the compilation is successful (but not the result :).
Is there something I'm doing wrong?
Thanks for advice
Vojtech Novacek
nullSorry you can not use order by clause into one temporal table created by subquery.
Put the order by clause offside of subquery.
Atte.
CC.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Vojtech Novacek:
Hello,
I'm unable to compile package body when i'm using order by clause in cursor subquery in stored procedure.
Sample code:
CREATE PACKAGE Announces AS
TYPE tRefCur IS REF CURSOR;
PROCEDURE TopAnnounces(
iiCount IN NUMBER,
osAnnounces OUT tRefCur,
oiRetVal OUT NUMBER
END Announces;
CREATE PACKAGE BODY Announces AS
PROCEDURE TopAnnounces(
iiCount IN NUMBER,
osAnnounces OUT NUMBER,
oiRetVal OUT NUMBER
AS
BEGIN
OPEN osAnnounces FOR
SELECT Id, Name, AnnCount FROM
SELECT Id, Name, COUNT(CategoryId) AS AnnCount FROM tblAnnounces
GROUP BY Id, Name
-- bellow is the line, where the code crash
ORDER BY AnnCount DESC
WHERE ROWNUM < iiCount + 1;
oiRetVal := 0;
EXCEPTION
WHEN OTHERS THEN
oiRetVal := -255;
END TopAnnounces;
END Announces;
If I compile the code above I will get this error:
PLS-00103: Encoutered the symbol "ORDER" when expecting on of the following:
After I remark the problematic line, the compilation is successful (but not the result :).
Is there something I'm doing wrong?
Thanks for advice
Vojtech Novacek<HR></BLOCKQUOTE>
null -
Hi,
Can we use order by clause in Sub query?
While using the order by clause, I am getting the "missing expression error" . If I remove order by clause query executing fine.
Here is my query:
select *
from emp_mstr
where emp_no in(select
emp_no
from emp_mstr
order by branch_no);
Thanks & Regards,
MahiMay be you miss some required spaces also, other than wrong use of ORDER BY
select *
from emp_mstr
where emp_no in
( select e2.emp_no
from emp_mstr e2
-- order by e2.branch_no
);Why do you want to ORDER BY in the subquery, which you use with IN clause? That will not make any difference in the result..Means the result you get with ORDER BY will be same as without that.. And in this case, ORDER by is a unncessary overhead.. And Ordering is very costly..
And why do you want to have the IN clause at all in your query? You are referring the same tables in the main query and sub query..
The below will give the same result
select *
from emp_mstr
where emp_no is not nullIf you want to use another table in the subquery, always use aliasess...
select *
from emp_mstr
where emp_no in
( select e2.emp_no
from emp_mstr2 e2
-- order by e2.branch_no
); -
Order by clause in discoverer custom folder
hi,
i m working on discoverer 3.1.38.I've been trying to sort the period according to calendar sequence and for this i tried 2-3 different queries which are working fine on sql plus but in discoverer custome folder,one error is coming saying ..can't use ORDER BY clause in custom folder.
I've tried formatting option also but it doesn't work here with me as i preferably want to sort in MON-RR format.
thanks in anticipation
nullthanks for replying back. but i didn't get what exactly u meant by creting query in user edition and about alternative sort,i should have list of value item and item_to_sort in same folder but i don't have that..i am creating one cross tab report and using to_char(gl_date,'MON-RR') format on my top axis its' appearing alphabetically over there,i wrote one qurey which worked prefecly fine on sql plus,but in discoverer its' giving me error.i can't create alternative sort on this,so please give me some different solution
thanks in advance -
What is the point in having multiple columns in ORDER BY clause?
DB version:10gR2
When using ORDER BY clause, the rows are always sorted according to the first column in the ORDER BY clause. So, what is point in having multiple columns in the ORDER BY clause(i always see this in production codes)?
For the below SQLs' from SCOTT schema, the result sets are always ordered according the first column ename. When i added job asc and job desc, the result set doesn't change.
SQL> select * from emp order by ename;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 20
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7839 KING PRESIDENT 17-NOV-81 5000 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7934 MILLER CLERK 7782 23-JAN-82 1300 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7369 SMITH CLERK 7902 17-DEC-80 800 20
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
14 rows selected.
SQL> select * from emp order by ename, job;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 20
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7839 KING PRESIDENT 17-NOV-81 5000 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7934 MILLER CLERK 7782 23-JAN-82 1300 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7369 SMITH CLERK 7902 17-DEC-80 800 20
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
14 rows selected.
SQL> select * from emp order by ename, job desc;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 20
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7839 KING PRESIDENT 17-NOV-81 5000 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7934 MILLER CLERK 7782 23-JAN-82 1300 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7369 SMITH CLERK 7902 17-DEC-80 800 20
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
14 rows selected.Because there is only one employee with the name SCOTT,FORD ...etc in the emp table and your first column in the order by list is ename
you spot the difference now
SQL> select * from emp order by job;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7788 SCOTT ANALYST 7566 19-APR-87 00:00:00 3000 20
7902 FORD ANALYST 7566 03-DEC-81 00:00:00 3000 20
7934 MILLER CLERK 7782 23-JAN-82 00:00:00 1300 10
7900 JAMES CLERK 7698 03-DEC-81 00:00:00 950 30
7369 SMITH CLERK 7902 17-DEC-80 00:00:00 800 20
7876 ADAMS CLERK 7788 23-MAY-87 00:00:00 1100 20
7698 BLAKE MANAGER 7839 01-MAY-81 00:00:00 2850 30
7566 JONES MANAGER 7839 02-APR-81 00:00:00 2975 20
7782 CLARK MANAGER 7839 09-JUN-81 00:00:00 2450 10
7839 KING PRESIDENT 17-NOV-81 00:00:00 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 00:00:00 1500 0 30
7654 MARTIN SALESMAN 7698 28-SEP-81 00:00:00 1250 1400 30
7521 WARD SALESMAN 7698 22-FEB-81 00:00:00 1250 500 30
7499 ALLEN SALESMAN 7698 20-FEB-81 00:00:00 1600 300 30
14 rows selected.
Elapsed: 00:00:00.00
SQL> select * from emp order by job, deptno asc;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7902 FORD ANALYST 7566 03-DEC-81 00:00:00 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 00:00:00 3000 20
7934 MILLER CLERK 7782 23-JAN-82 00:00:00 1300 10
7369 SMITH CLERK 7902 17-DEC-80 00:00:00 800 20
7876 ADAMS CLERK 7788 23-MAY-87 00:00:00 1100 20
7900 JAMES CLERK 7698 03-DEC-81 00:00:00 950 30
7782 CLARK MANAGER 7839 09-JUN-81 00:00:00 2450 10
7566 JONES MANAGER 7839 02-APR-81 00:00:00 2975 20
7698 BLAKE MANAGER 7839 01-MAY-81 00:00:00 2850 30
7839 KING PRESIDENT 17-NOV-81 00:00:00 5000 10
7654 MARTIN SALESMAN 7698 28-SEP-81 00:00:00 1250 1400 30
7844 TURNER SALESMAN 7698 08-SEP-81 00:00:00 1500 0 30
7521 WARD SALESMAN 7698 22-FEB-81 00:00:00 1250 500 30
7499 ALLEN SALESMAN 7698 20-FEB-81 00:00:00 1600 300 30
14 rows selected.
Elapsed: 00:00:00.01
SQL> select * from emp order by job,deptno desc;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7902 FORD ANALYST 7566 03-DEC-81 00:00:00 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 00:00:00 3000 20
7900 JAMES CLERK 7698 03-DEC-81 00:00:00 950 30
7369 SMITH CLERK 7902 17-DEC-80 00:00:00 800 20
7876 ADAMS CLERK 7788 23-MAY-87 00:00:00 1100 20
7934 MILLER CLERK 7782 23-JAN-82 00:00:00 1300 10
7698 BLAKE MANAGER 7839 01-MAY-81 00:00:00 2850 30
7566 JONES MANAGER 7839 02-APR-81 00:00:00 2975 20
7782 CLARK MANAGER 7839 09-JUN-81 00:00:00 2450 10
7839 KING PRESIDENT 17-NOV-81 00:00:00 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 00:00:00 1500 0 30
7654 MARTIN SALESMAN 7698 28-SEP-81 00:00:00 1250 1400 30
7521 WARD SALESMAN 7698 22-FEB-81 00:00:00 1250 500 30
7499 ALLEN SALESMAN 7698 20-FEB-81 00:00:00 1600 300 30
14 rows selected.
Elapsed: 00:00:00.01
SQL> -
Output not sorted when using group by clause
Recently we migrated our application from Forms5 to Forms10g and database from 7.3.2 to 10gR2.
More than 400 applications using sql stmt with "group by" clause and without "order by".
In Earlier version of oracle 7.3.2 "group by" clause in SQL stmt sorts the output by order of the column in the "group by"
stmt, where new version of oracle 10g (10.2.0.1.0 - 64bit Production) doesnt behave like older version.
eg select div_cd,dept_cd,count(*) from class group by div_cd,dept_cd
Output of the above query in Oracle7
DIV_CD DEPT_CD COUNT(*)
0 1 120
0 9 131
1 4 938
1 6 1
4 1 1490
5 2 59
6 6 848
6 9 295
8 1 45
9 5 19
Output of same query in Oracle10g
DIV_CD DEPT_CD COUNT(*)
0 6 120
0 9 131
4 1 1490
6 9 295
8 1 45
9 5 19
1 4 938
1 6 1
5 2 59
6 6 848
My question is
a) Does the oracle behave in that manner?.
b) if so, Any patch set available for this?
c) if no patch set how to resolve this issue.
if i use "order by" clause
along with group by then i can get the output how i want.
BUt problem is more than 400 applications (forms) using above method.
Identify Forms/Reports and rectifing is a tedious job.
Anyone can give me a good solution to solve the above issueGroup By does not, and never has guaranteed order. Just because it happened that way on the past does not mean it will continue to do so.
In the past, the algorithm used for Group By invoked a sort. It was convenient for the system to simply dump the output in that resulting order. These days, Group By could also be accomplished using a hash algorithm. Walking through the hash can easily result in a completely different ordering, as you have seen.
Your problem is that the assumptions made previously are now invalid. Oracle is still working correctly. No patch, but you might be able to work around it by crippling your database and using the COMPATIBLE parameter (although the official lower limit is 9.2.0) -
EJB finder query with ORDER BY clause
Hi,
How to query the data in ordered list using Order By clause in the entity Bean.
Here is the part of My code in which i am interrested.
/* @ejbgen:finder
* signature = "Collection findAllData()"
* ejb-ql = "SELECT OBJECT(z) FROM DataProfileBean AS z"
abstract public class DataProfileBean extends EntityAdapter {
* @ejbgen:cmp-field column = DATA_PREFIX
* @ejbgen:primkey-field
* @ejbgen:local-method transaction-attribute = Required
public abstract Integer getDataPrefix();
public abstract void setDataPrefix(Integer DataPrefix);
Now what modification needs to be done in the ejb-ql query to find the DataPrefix in the sorted list.
Regards,
DilipI don't think the current spec for EJBs support ORDER BY. But Weblogic has an extension that you can use (that is, if you're using it). Here's the info: http://e-docs.bea.com/wls/docs61/ejb/cmp.html#1076421
-
Long run time with ORDER by clause
Hi,
I am having a query which is executing fine(in 2 mins) but when i am using order by clause in it, its taking around 13 mins.
Can anyone suggest what could be th reason and how to execute the same query are get the ordered record?
thanks.Sorry for not providing complet details.
Database version id 10g.
Below is the execution plan when using with order by clause.
Execution Plan
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 1 | 118 | 1538 |
| 1 | FILTER | | | | |
| 2 | HASH JOIN | | 16657 | 1089K| 56 |
| 3 | TABLE ACCESS FULL | FILETYP | 6 | 60 | 3 |
| 4 | TABLE ACCESS FULL | FILETYPSOURCEID | 16657 | 927K| 52 |
| 5 | NESTED LOOPS | | 1 | 35 | 3 |
| 6 | TABLE ACCESS BY INDEX ROWID | FILEWAREHOUSE | 1 | 25 | 2 |
| 7 | INDEX RANGE SCAN | FILEWAREHOUSE_DX2 | 1 | | 2 |
| 8 | TABLE ACCESS BY INDEX ROWID | EXTFILE | 1 | 10 | 1 |
| 9 | INDEX UNIQUE SCAN | PK_EXTFILE | 1 | | 1 |
| 10 | SORT ORDER BY | | 1 | 118 | 1538 |
| 11 | NESTED LOOPS | | 1 | 118 | 1534 |
| 12 | NESTED LOOPS OUTER | | 1 | 100 | 1533 |
| 13 | NESTED LOOPS OUTER | | 1 | 96 | 1532 |
| 14 | NESTED LOOPS | | 1 | 88 | 1531 |
| 15 | HASH JOIN | | 5 | 360 | 1524 |
| 16 | TABLE ACCESS BY INDEX ROWID | RTXN | 1 | 22 | 1 |
| 17 | NESTED LOOPS | | 117 | 5148 | 1518 |
| 18 | VIEW | VW_SQ_1 | 20869 | 448K| 1441 |
| 19 | HASH GROUP BY | | 20869 | 427K| 1441 |
| 20 | FILTER | | | | |
| 21 | TABLE ACCESS BY INDEX ROWID| RTXNSTATHIST | 20869 | 427K| 1304 |
| 22 | INDEX RANGE SCAN | RTXNSTATHIST_DX2 | 20869 | | 29 |
| 23 | INDEX RANGE SCAN | PK_RTXN | 1 | | 1 |
| 24 | NESTED LOOPS | | 1 | 24 | 3 |
| 25 | TABLE ACCESS BY INDEX ROWID | FILEWAREHOUSE | 1 | 14 | 2 |
| 26 | INDEX RANGE SCAN | FILEWAREHOUSE_DX2 | 1 | | 2 |
| 27 | TABLE ACCESS BY INDEX ROWID | EXTFILE | 1 | 10 | 1 |
| 28 | INDEX UNIQUE SCAN | PK_EXTFILE | 1 | | 1 |
| 29 | TABLE ACCESS FULL | RTXNTYP | 1 | 28 | 5 |
| 30 | TABLE ACCESS BY INDEX ROWID | RTXNSTATHIST | 1 | 16 | 2 |
| 31 | INDEX RANGE SCAN | PK_RTXNSTATHIST | 1 | | 1 |
| 32 | TABLE ACCESS BY INDEX ROWID | NTWKNODE | 1 | 8 | 1 |
| 33 | INDEX UNIQUE SCAN | PK_NTWKNODE | 1 | | 1 |
| 34 | INDEX UNIQUE SCAN | PK_ORG | 1 | 4 | 1 |
| 35 | TABLE ACCESS BY INDEX ROWID | ACCT | 1 | 18 | 1 |
| 36 | INDEX UNIQUE SCAN | PK_ACCT | 1 | | 1 |
Below is the execution plan when running without ORDER BY clause...
Execution Plan
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 1 | 135 | 1537 |
| 1 | FILTER | | | | |
| 2 | HASH JOIN | | 16657 | 1089K| 56 |
| 3 | TABLE ACCESS FULL | FILETYP | 6 | 60 | 3 |
| 4 | TABLE ACCESS FULL | FILETYPSOURCEID | 16657 | 927K| 52 |
| 5 | NESTED LOOPS | | 1 | 35 | 3 |
| 6 | TABLE ACCESS BY INDEX ROWID | FILEWAREHOUSE | 1 | 25 | 2 |
| 7 | INDEX RANGE SCAN | FILEWAREHOUSE_DX2 | 1 | | 2 |
| 8 | TABLE ACCESS BY INDEX ROWID | EXTFILE | 1 | 10 | 1 |
| 9 | INDEX UNIQUE SCAN | PK_EXTFILE | 1 | | 1 |
| 10 | NESTED LOOPS | | 1 | 135 | 1534 |
| 11 | NESTED LOOPS OUTER | | 1 | 117 | 1533 |
| 12 | NESTED LOOPS OUTER | | 1 | 113 | 1532 |
| 13 | NESTED LOOPS | | 1 | 105 | 1531 |
| 14 | HASH JOIN | | 5 | 445 | 1524 |
| 15 | TABLE ACCESS FULL | RTXNTYP | 1 | 28 | 5 |
| 16 | TABLE ACCESS BY INDEX ROWID | RTXN | 1 | 22 | 1 |
| 17 | NESTED LOOPS | | 117 | 7137 | 1518 |
| 18 | VIEW | VW_SQ_1 | 20869 | 794K| 1441 |
| 19 | HASH GROUP BY | | 20869 | 427K| 1441 |
| 20 | FILTER | | | | |
| 21 | TABLE ACCESS BY INDEX ROWID| RTXNSTATHIST | 20869 | 427K| 1304 |
| 22 | INDEX RANGE SCAN | RTXNSTATHIST_DX2 | 20869 | | 29 |
| 23 | INDEX RANGE SCAN | PK_RTXN | 1 | | 1 |
| 24 | NESTED LOOPS | | 1 | 24 | 3 |
| 25 | TABLE ACCESS BY INDEX ROWID | FILEWAREHOUSE | 1 | 14 | 2 |
| 26 | INDEX RANGE SCAN | FILEWAREHOUSE_DX2 | 1 | | 2 |
| 27 | TABLE ACCESS BY INDEX ROWID | EXTFILE | 1 | 10 | 1 |
| 28 | INDEX UNIQUE SCAN | PK_EXTFILE | 1 | | 1 |
| 29 | TABLE ACCESS BY INDEX ROWID | RTXNSTATHIST | 1 | 16 | 2 |
| 30 | INDEX RANGE SCAN | PK_RTXNSTATHIST | 1 | | 1 |
| 31 | TABLE ACCESS BY INDEX ROWID | NTWKNODE | 1 | 8 | 1 |
| 32 | INDEX UNIQUE SCAN | PK_NTWKNODE | 1 | | 1 |
| 33 | INDEX UNIQUE SCAN | PK_ORG | 1 | 4 | 1 |
| 34 | TABLE ACCESS BY INDEX ROWID | ACCT | 1 | 18 | 1 |
| 35 | INDEX UNIQUE SCAN | PK_ACCT | 1 | | 1 |
-------------------------------------------------------------------------------------------Edited by: user10754555 on Feb 5, 2010 6:02 PM -
RESTICTIONS ON ORDER BY CLAUSE
Can someone clear my doubts.I find it in DOCS but didn't succeded.Where it is written ?Please Explain me.
Can We use ORDER BY CLAUSE in SubQuery ?
Thanks.
KarTiK.No,
Even though It wont work..
Findout yourself..
SQL> select ename,sal
2 from (select a.*,rownum s
3 from emp a
4 order by sal desc)
5 where s = &rnk
6 /
Enter value for rnk: 4
old 5: where s = &rnk
new 5: where s = 4
ENAME SAL
JONES 2975
SQL> /
Enter value for rnk: 3
old 5: where s = &rnk
new 5: where s = 3
ENAME SAL
WARD 1250
SQL> /
Enter value for rnk: 1
old 5: where s = &rnk
new 5: where s = 1
ENAME SAL
SMITH 800
Maybe you are looking for
-
Warning Messages when starting Application
Hello, I get those messages when starting my application: WARN - [ConverterRule]{faces-config/converter} Merge(null,java.math.BigDecimal) WARN - [ConverterRule]{faces-config/converter} Merge(null,java.math.BigInteger) WARN - [ManagedBeanRule]{faces-c
-
J2ME: add a week to the current date
I want to add a week to the current date but the output has to be a valid date. I can't figure it out how to solve the problem :(. Can anybody help me with my problem? TIA
-
ByAccount Aggregation not working correctly in 2 of 3 cubes
I have 3 financial cubes in the same project. Essentially the cubes are the same with only the account rollup being different. For the accounts I have 3 separate parent child account dimensions defined. The account type for each account is defined
-
IBook Clamshell apple logo glow
Does anybody know how to make a iBook g3 clamshell apple logo glow like this video? http://www.youtube.com/watch?v=aV6k9el17Jg
-
Installation of windows server 2008r2 on dell power edge 2850
I just received an dell power edge 2850, can I install windows server 2008r2 on this unit