ORDER BY clause with expression
Considering that all the column names and table name is valid, what happens internally when the following query is run?
SQL> SELECT STU_ID, STU_NAME FROM STUDENT ORDER BY 2+3, STU_ID;
What i found out was the rows get ordered in ascending order of STU_ID. It's quite clear that it is ignoring the expressing 2+3, so my doubts are:
(a) Is it appending any pseudo-column to the table with 2+3 getting evaluated to 5?
(b) If there exist a 5th column in the table student and we specify it in the select statement's select list (5 column names) then why its not considering it as 5 and sorting the data according that?
(c) Is it true that, any expression we write is getting evaluated to NULL? Then is it that ORDER BY NULL evaluates to no ordering and the parser searches for next column-name or position (if specified) ?
(d) if neither then, what's the reason of the ignorance?
Hi,
Welcome to the forum!
987236 wrote:
Considering that all the column names and table name is valid, what happens internally when the following query is run?
SQL> SELECT STU_ID, STU_NAME FROM STUDENT ORDER BY 2+3, STU_ID;
What i found out was the rows get ordered in ascending order of STU_ID. It's quite clear that it is ignoring the expressing 2+3, so my doubts are:
(a) Is it appending any pseudo-column to the table with 2+3 getting evaluated to 5There's no pseduo-column involved. (Pseudo-columns are something that Oracle provides for you, without you having to spell out what you want. ROWID and LEVEL are examples of pseudo-columns. In this example, 2+3 is an Expression . Like pseudo-columns, expressions can usually appear in the ORDER BY clause, even though they are not actually stored in the table.)
It's sorting first by the NUMBER 5 (= 2 + 3), not the 5th column. Since the NUMBER 5 has the same value on every row, every row ties for first place. The result of sorting by any constant is the same; the results are the same as not including that exrpression in the ORDER BY clause. That is the ORDER BY clause you posted is equivalent to
ORDER BY 2 + 3
, 'foo'
, SYSDATE
, NULL
, stu_idand it's also equivalent to
ORDER BY stu_idNone of the expressions except stu_id vary from row to row, so none of them affect the sorting.
(b) If there exist a 5th column in the table student and we specify it in the select statement's select list (5 column names) then why its not considering it as 5 and sorting the data according that?As Solomon said, only number literals are taken to mean a column. 5 is a number literal, so
ORDER BY 5means "sort by the 5th column", but 2 + 3 is not a literal (it's an expression that happens to include a couple of literals), so
ORDER BY 2 + 3does not refer to the 5th colunmn.
(c) Is it true that, any expression we write is getting evaluated to NULL? Then is it that ORDER BY NULL evaluates to no ordering and the parser searches for next column-name or position (if specified) ?No, when you way "ORDER BY x", the rows with lower values of x come first, followed by rows with higher values of x. Rows with the same value of x will be together, in no particular order with respect to each other (unless there is a tie-breaker expression later in the ORDER BY clause.
That's exactly what happens when you say "ORDER BY NULL". NULL has the same value (actually, the same lack of any value) on all rows, so all the rows have the same value of x, and they will appear in no particular order.
(d) if neither then, what's the reason of the ignorance?
Similar Messages
-
Decode in order by clause with desc
I want to user order by clause with decode + desc order.
somthing like
ORDER BY DECODE ('SALE', e.sale, 'SALE DESC' ????)
????-> How to use desc order with decode
Thanks in advanceI thought smart people in this OTN community will understand that I am trying to order by the thisdate column that is timestamp datatype:). My apologize for not being that specific.
The query I gave is a simple version of the stored procedure I am using. The point is I need to order by - depending on one of the parameters that is passed to the procedure. In simplest decode statements, its something like
order by decode(p_in_var,'ABC','thisdate asc','DEF','thisdate desc',thisdate asc)
Here p_in_var is varchar input parameter to the stored procedure.
Please let me know if there is any more information needed.
Thx! -
ViewObjects Order by clause with DECODE
Hello!
I am using Jdeveloper 11g, version 11.1.1.2.0.
The problem I'm having is this.
If I use a DECODE statement in view objects ORDER BY clause, I get an error: "java.util.regex.PatternSyntaxException: Unmatched closing ')' near index 2".
Let me give an example. I'll be using EmployeesView view object, which is using Employees entity from HR schema.
This is a part of view objects XML.
<ViewObject
xmlns="http://xmlns.oracle.com/bc4j"
Name="EmployeesView"
Version="11.1.1.55.36"
SelectList="Employees.EMPLOYEE_ID,
Employees.FIRST_NAME,
Employees.LAST_NAME,
Employees.EMAIL,
Employees.PHONE_NUMBER,
Employees.HIRE_DATE,
Employees.JOB_ID,
Employees.SALARY,
Employees.COMMISSION_PCT,
Employees.MANAGER_ID,
Employees.DEPARTMENT_ID"
FromList="EMPLOYEES Employees"
BindingStyle="OracleName"
CustomQuery="false"
PageIterMode="Full"
UseGlueCode="false"
OrderBy="Employees.MANAGER_ID">
As you can see in this case, the Order by clause is very simple. This works like a charm.
But, if put something like this "DECODE(Employees.MANAGER_ID, NULL, 1, 2)" in the Order by, I get an internal parsing error.
I replicated this error on my home machine as well as on my work machine. I'm using the same version of Jdeveloper on both.
Has anyone else stumbled upon this problem and solved it?
Any thoughts would be greatly appreciated :)
KristjanThe second example works, but the first one doesn't, unfortunately :/
Also, the example I gave is unfortunately just that, a proof-of-concept example that there is a problem with DECODE if it is written inside the Order by clause.
My real DECODE use case is a bit different. Like this: "DECODE(attribute, 'N', 1, 2) ASC".
Since posting my original question, I did some research-by-example work and I discovered that this is not just a problem of DECODE, but more like a problem of brackets and commas.
No database function that uses more than one parameter can be used in Order by clause.
The reason is, if a function with more than one parameter is used, commas inside brackets have to be used. Something along the lines of: "database_function(param1, param2, ...)".
The parser seems to have a problem with this kind of expressions.
Is there a work around?
Kristjan
p.s.: Thank you for your quick response. -
Hi,
I wanted to know if this is possible with order by clause and union. some how union messes up the ordering of the left part of the union statement.
assume the data is as below in table tab1
c1 c2
4 1
4 2
5 1
5 2
7 1
7 2
8 3
9 4
the expected output must be for all c1 < 7 ordering must be on c1 and for all c1 > 7 ordering must be on c2.
so the query i tried was
select c1,c2 from tab1 where c1 <7 order by c1
union
select c1,c2 from tab1 where c1 >=7 order by c2
it is giving the message 'Sql command not properly ended'.
Suggestions are welcomeSQL>
SQL> With t As
2 (
3 Select 4 c1, 1 c2 From dual Union All
4 Select 4 ,2 From dual Union All
5 Select 5 ,1 From dual Union All
6 Select 5 ,2 From dual Union All
7 Select 7 ,1 From dual Union All
8 Select 7 ,2 From dual Union All
9 Select 8 ,3 From dual Union All
10 Select 9 ,4 From dual
11 ), t1 As (Select c1,c2 From t Where c1 <7 Order By c1)
12 ,t2 As (select c1,c2 from t where c1 >=7 Order By c2)
13 Select * From t1 Union All
14 Select * From t2;
C1 C2
4 1
4 2
5 1
5 2
7 1
7 2
8 3
9 4
8 rows selected
SQL> /*-- Union All
2 select c1,c2 from t where c1 >=7
3 Order By c1,c2;
4 */
5
with union clause order by must be placed in the end,,
select c1 from dual union all
select c2 from dual
order by c1 -
Order By Clause with Empty Field values !
Hello,
In Oracle , the order by clause does not return the expected query result, if any of the field value in the order by clause has an empty string.
Oracle treats the empty string as null value and ORDER BY gives a result with the empty string field values listed at last.
For example :
test is a sample table containing "name" field.
Query: "select name from test order by name"
In SQL Server/Access
Result (1)
NAME
(blank)
(blank)
User1
User2
User3
In Oracle
Result (2)
NAME
User1
User2
User3
(blank)
(blank)
I know some of the Work arounds for this as listed below :
1) To use NVL in Order By Clause.
i.e., the modified query
"select name from test order by nvl(name,0)"
gives the result same as Result (1).
2) To have single blank space in the field value if it is empty.
I dont want to use either of these two options b'se it would lead to a mass change in my existing code.
Is there any way i can do a
collation order settings in the Oracle databases to get the results as in MS SQL/Access.
Can Any help me out in Solving this?
Thanks
Devi Shankar
nullBharath,
I am moving this question to the SQL forum.
Regards,
Geoff -
Conditional order by clause with multiple columns
I would like to know whether it is possible to include multiple columns in a conditional order by clause.
Ex: I have written the following PL / SQL :
CREATE PROCEDURE GetProducts
@OrderBy VARCHAR(50),
@Input2 VARCHAR(30)
AS
BEGIN
SET NOCOUNT ON
SELECT Id, ProductName, Description, Price, Quantity
FROM Products
WHERE ProductName LIKE @Input2
ORDER BY
CASE
WHEN @OrderBy = 'ProductNameAsc' THEN ProductName
END ASC,
CASE
WHEN @OrderBy = 'ProductNameDesc' THEN ProductName
END DESC
END
Now I want to include when the Orderby - "Productnameasc" then order by productname, price, stdate
else
orderby productname, crdate, category
Could this be done? I tried it, but couldn't get this to work.
Any help is greatly appreciated.Since matching ORDER BY columns have different data types (first column for CLERK is sal - number, first column for MANAGER deptno is number but first column for "else" is a string) we need to convert number to string but preserve number sort order. Since DEPTNO is NUMBER(2) we will use TO_CHAR with format 'S00'. Since SAL is NUMBER(7,2) we will use TO_CHAR with format model 'S00000D00'. For EMPNO we will use TO_CHAR with format model 'S0000'.
select deptno,
empno,
ename,
job,
sal
from emp
order by case job
when 'CLERK' then to_char(sal,'S00000D00')
when 'MANAGER' then to_char(deptno,'S00')
else ename
end,
case job
when 'CLERK' then to_char(deptno,'S00')
else job
end,
case job
when 'CLERK' then job
when 'MANAGER' then to_char(empno,'S0000')
end
DEPTNO EMPNO ENAME JOB SAL
20 7369 SMITH CLERK 800
30 7900 JAMES CLERK 950
20 7876 ADAMS CLERK 1100
10 7934 MILLER CLERK 1300
10 7782 CLARK MANAGER 2450
20 7566 JONES MANAGER 2975
30 7698 BLAKE MANAGER 2850
30 7499 ALLEN SALESMAN 1600
20 7902 FORD ANALYST 3000
10 7839 KING PRESIDENT 5000
30 7654 MARTIN SALESMAN 1250
DEPTNO EMPNO ENAME JOB SAL
20 7788 SCOTT ANALYST 3000
30 7844 TURNER SALESMAN 1500
30 7521 WARD SALESMAN 1250
14 rows selected.
SQL> SY. -
Writing order by clause with user parameter
I have a user parameter where the user is supposed to choose what column they want to sort by.
And they can choose between k.personnr and k.personnavn. I am trying to do this with a decode function.
Now this would work fine if there was no union between these select statements.
But with the union I get a ORA-01785, where they tell me to put in a number.
Here is the sql:
SELECT
k.personnr as PERSON ,
k.personnavn as NAVN,
r.belop as SUM,
concat(to_char(r.bilagdato,'MM'), to_char(r.bilagdato,'YYYY')) AS MND,
PERIODE(concat(to_char(r.bilagdato,'MM'), to_char(r.bilagdato,'YYYY'))) AS PERIODE
FROM
reskontro r,
klient k,
kontoplan p,
konto c
WHERE
r.distriktnr='21'
and r.distriktnr=c.kontoid
and r.distriktnr=k.distriktnr
and r.personnr=k.personnr
and r.kontonr=p.kontonr
and (((r.bilagdato between :p_fra_dato and :p_til_dato) and (:p_fra_dato <= c.overfort) and (:p_til_dato <= c.overfort))
or ((r.bilagdato between :p_fra_dato and c.overfort) and (:p_fra_dato <= c.overfort) and (:p_til_dato >= c.overfort)))
UNION ALL
SELECT
k.personnr as PERSON ,
k.personnavn as NAVN,
(t.belop/100) as SUM,
concat(to_char(t.bilagdato,'MM'), to_char(t.bilagdato,'YYYY')) AS MND,
PERIODE(concat(to_char(t.bilagdato,'MM'), to_char(t.bilagdato,'YYYY')),:P_HORISONTAL) AS PERIODE
FROM
transaksjon t,
klient k,
kontoplan p
WHERE
t.distriktnr='21'
and t.distriktnr=k.distriktnr
and t.personnr=k.personnr
and t.kontonr=p.kontonr
and t.bilagdato between :p_fra_dato and :p_til_dato
This is the order by clause I would like to use:
order by decode(:p_order_by,'Personnavn',k.personnavn,k.personnr)
I also get an error when I use:
order by decode(:p_order_by,'Personnavn',2,1)
Can anybody tell me how to work around this problem?Hi,
One way you can do to get around this problem could be :
select * from (
SELECT
k.personnr as PERSON ,
k.personnavn as NAVN,
r.belop as SUM,
concat(to_char(r.bilagdato,'MM'), to_char(r.bilagdato,'YYYY')) AS MND,
PERIODE(concat(to_char(r.bilagdato,'MM'), to_char(r.bilagdato,'YYYY'))) AS PERIODE
FROM
reskontro r,
klient k,
kontoplan p,
konto c
WHERE
r.distriktnr='21'
and r.distriktnr=c.kontoid
and r.distriktnr=k.distriktnr
and r.personnr=k.personnr
and r.kontonr=p.kontonr
and (((r.bilagdato between :p_fra_dato and :p_til_dato) and (:p_fra_dato <= c.overfort) and (:p_til_dato <= c.overfort))
or ((r.bilagdato between :p_fra_dato and c.overfort) and (:p_fra_dato <= c.overfort) and (:p_til_dato >= c.overfort)))
UNION ALL
SELECT
k.personnr as PERSON ,
k.personnavn as NAVN,
(t.belop/100) as SUM,
concat(to_char(t.bilagdato,'MM'), to_char(t.bilagdato,'YYYY')) AS MND,
PERIODE(concat(to_char(t.bilagdato,'MM'), to_char(t.bilagdato,'YYYY')),:P_HORISONTAL) AS PERIODE
FROM
transaksjon t,
klient k,
kontoplan p
WHERE
t.distriktnr='21'
and t.distriktnr=k.distriktnr
and t.personnr=k.personnr
and t.kontonr=p.kontonr
and t.bilagdato between :p_fra_dato and :p_til_dato)
order by decode(:p_order_by,'Personnavn', NAVN, PERSON)
/Uffe -
Order by clause with Named Query
hi
i have to give order by clause in Named Query
how we have to specify is can any body help
thanks
HarishAssuming an Entity called Handset:
select h from Handset h order by h.description -
HAVING clause, or ORDER BY clause ....ERROR
hi i have following query which throws error plz find the solution for the query to go safe..
Select C.src_cd,
D.src_nm,
count(*) supp_clm_count,
(CASE WHEN A.clm_ttladjamt > 0 then A.clm_ttladjamt else A.clm_ttlreqamt END) as amount
From IWOWNER.WC_clm A,
IWOWNER.WC_clm_srvc B,
SHOWNER.WC_SRC C,
SHOWNER.WC_SRC_lang D
where A.clm_id = B.clm_id
and A.rcv_loc_id = C.src_id
and C.src_id = D.src_id
and TRANSLATE(A.clm_rqst_type_cd) = 'SUPPLIERCLAIM'
and TRANSLATE(A.clm_typ_cd) in ('WARRANTY','PRE-DELIVERY')
and DATE(A.clm_create_dt) between '01/01/2000' and '01/01/2010'
Group by C.src_cd, D.src_nm
ERROR:
SQLSTATE: 42803, SQLERRMC: CLM_TTLADJAMT
Message: An expression starting with "CLM_TTLADJAMT" specified in a SELECT clause, HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column function and no GROUP BY clause is specifiedHi,
With analytic function
/* Formatted on 2009/07/22 10:47 (Formatter Plus v4.8.8) */
SELECT DISTINCT c.src_cd, d.src_nm,
COUNT (1) OVER (PARTITION BY c.src_cd, d.src_nm)
supp_clm_count,
SUM (CASE
WHEN a.clm_ttladjamt > 0
THEN a.clm_ttladjamt
ELSE a.clm_ttlreqamt
END
) OVER (PARTITION BY c.src_cd, d.src_nm) AS amount
FROM iwowner.wc_clm a,
iwowner.wc_clm_srvc b,
showner.wc_src c,
showner.wc_src_lang d
WHERE a.clm_id = b.clm_id
AND a.rcv_loc_id = c.src_id
AND c.src_id = d.src_id
AND a.clm_rqst_type_cd = 'SUPPLIERCLAIM'
AND a.clm_typ_cd IN ('WARRANTY', 'PRE-DELIVERY')
AND a.clm_create_dt BETWEEN TO_DATE ('01/01/2000', 'dd/mm/yyyy')
AND TO_DATE ('01/01/2010', 'dd/mm/yyyy') -
TestStand Open SQL Statement does not support SQL's ORDER BY clause???
TestStand 1.0.3
Windows 2000 SP1
SQL Server 2000 Personal
You've got to be kidding me...
It appears that the built-in TestStand Open SQL Step does NOT support the
"ORDER BY" clause in the SELECT statement, even though the documentation
says it does. Is this true?
I have an Open SQL Statement query:
"SELECT * FROM [MyTable] WHERE ([Batch ID]=1234)"
it works fine, returning a correct record count 120 records. If I change
the Open SQL Statement query simply by adding an ORDER BY clause, such as:
"SELECT * FROM [MyTable] WHERE ([Batch ID]=1234) ORDER BY [MyField] ASC"
it returns a record count of zero. I know that "MyField" exists in the
MyTable table and contains valid data. The
second query works fine in SQL
Server Enterprise Manager.
Am I missing something? Is it true that the TestStand Open SQL Step does
NOT support the "ORDER BY" clause? If not, what &#$!ing good is it and why
does the manual state it is supported? Is there any other way using just
the TestStand steps to order a database recordset on one or more fields?
Any help would be appreciated.
Grrrrr....
Bob Rafuse
Etec Inc.> Bob -
> The database step types do not do anything special to the SQL command
> that you give it. The step just passes the command to the ADO
> provider. I tried a simple query using the step types with the
> following command,
>
> "SELECT UUT_RESULT.* FROM UUT_RESULT WHERE ([UUT_SERIAL_NUMBER] =
> 12345) ORDER BY [EXECUTION_TIME] ASC"
>
> and this return the expected results and the record count parameter
> was as expected. I tried this on TS 1.0.2 and TS 2.0 with MS Access
> 2000 and MS SQL Server 7.0. I do not have MS SQL Server 2000 at this
> time.
>
> It would be surprised if the step types are messing something up.
I've been doing some experimenting over the past couple of days. Simple,
one-table queries seem to handle the ORDER BY clause fine. Th
ings seem to
get messed up when I try multi-table queries with ORDER BY clause with the
TestStand database steps. I get no errors but the returned record counts
are always 0 with the ORDER BY and positive without the ORDER BY. The exact
same queries work fine in Visual Basic/ADO and the SQL Server Query
Analyzer.
> Questions:
> 1. Have you verified whether the data is actually returned even though
> the record count is zero?
Hmmm... yes data IS getting returned (at least on the two instances I just
checked), but the record count is always zero. I was not proceeding with
processing if the record count was 0.
Still... I don't know how to loop through the recordset without knowing how
many records there are an not eventually generate an error by passing EOF.
Is there another way using the TestStand database steps to determine a) the
number of records in the recordset or b) when I'm at EOF?
> 2. Are you using any advanced options on the Opend SQL Statement step
> type, specifically
the cursor type set to forward only? Forward only
> cursors do not allow for record counts.
Everything on the Advanced tab of the Open SQL Statement step is set to "Use
Default".
Bob. -
Database Settings for order By Clause
Hi,
In oracle if we do a "order by" in SQL statement for field values whose values are empty, then they would be listed at the last if we dont specify any NVL() for it.
Is there any other option by which the funcionality of Order by clause with Empty field values can be changed.
Is there any settings that can be made in the existing database , so that the Order by clause does not list the empty field values at the bottom.
Thanx in advance.
Bharathyou can do wonders with decode and nvl
for instance:
order by decode(nullable_field, null, 1, 2)would make all your null fields come first, whereas
order by nvl(nullable_field, 'M')would make them appear in the middle of an alphabetical list.
Basically NULLs are not something. You have to give the ORDER BY something to replace the null.
null -
Can I use an expression in order by clause
SELECT
PERIOD_NUM, period_num *12,
period_name,
--TO_DATE(SUBSTR(PERIOD_NAME,1,3)| |SUBSTR(PERIOD_NAME,INSTR(PERIOD_NAME,'-'),3),'MON-RR'),
TO_NUMBER(TO_CHAR(TO_DATE((SUBSTR(PERIOD_NAME,1,3)| |SUBSTR(PERIOD_NAME,INSTR(PERIOD_NAME,'-')+1,2)),'MONRR'),'RRRRMM'))
FROM GL.GL_PERIODS
order by 2--TO_NUMBER(TO_CHAR(TO_DATE(SUBSTR(PERIOD_NAME,1,3)| |SUBSTR(PERIOD_NAME,INSTR(PERIOD_NAME,'-')+1,2),'MONRR'),'RRRRMM'))
desc
gl_periods is a table, period_name consists of values like oct-01_fy-01 etc and oct01_01_fy-01
I want to sort on this column based on period_name, so I am trying to convert into number like for oct-01_fy-01, the query gives
200110 and so on. the recent period comes first, But my question is I can't use the same to_number(.....) in the order by clause. oracle gives an error
ORA-01843: not a valid month.
Let me know whether anyone come across with this kind of situationIf you are sure the expression is correct, since you are using it in the select clause, give an alias and use the alias in the order by clause.
null -
IN clause with ORDER BY clause in sub-queries
Hello,
We generate dynamic queries with the following statement pattern (could be many union/intersect sub-queries):
select my_col
from my_table
where my_col IN
select table_2.my_col , x_col from table_2 where x_col > 10
UNION
select table_3.my_col , y_col from table_3 where y_col > 20
INTERSECT
select table_4.my_col , z_col from table_4 where z_col is between 30 and 50
I know that I can do just the sub-queries w/ an ORDER BY clause as follows (as long as the 2nd parameter in the select stmts are of the same type):
select table_2.my_col , x_col from table_2 where x_col > 10
UNION
select table_3.my_col , y_col from table_3 where y_col > 20
INTERSECT
select table_4.my_col , z_col from table_4 where z_col is between 30 and 50
order by 2 desc
But my questions are:
1. What is (if there is) the syntax that will ensure that the result set order will be that of the ordering of the sub-queries?
Or does my SQL stmt have to have syntactically (but not semantically) change to achieve this?
Thanks,
JimRandolf Geist wrote:
just a minor doubt - I think it is not officially supported to have separate ORDER BYs in a compound query with set operators (e.g. UNION / UNION ALL subsets). Of course one could use inline views with NO_MERGE + NO_ELIMINATE_OBY hints, but I think the only officially supported approach is to use a single, final ORDER BY (that needs to use positional notation as far as I remember).
Randolf,
You're right, of course, about the separate "order by" clauses.
Interestingly the following type of thing does work though (in 10.2.0.3, at least):
with v1 as (
select * from t1 where col1 = 'ABC' order by col2
v2 as (
select * from t1 where col1 = 'DEF' order by col2
select * from v1
union all
select * from v2
;A quick check the execution plan suggsts that Oracle appears to be convering this to the following - even though its technically not acceptable in normal circumstances:
select * from t1 where col1 = 'ABC' order by col2
union all
select * from t1 where col1 = 'DEF' order by col2
;Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk
To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format.
"Science is more than a body of knowledge; it is a way of thinking"
Carl Sagan -
Hi,
I have a requirement where I need to display a list of employees, performance rating and manager id. I want to display the emplyees first whos manager is as manager_id as input parameter. So lets say a manager logs in, he should see his reportees first and then therest. How can I implemet this in SQL? I am trying first clause with order by but not sure how to do that here. A help on this would be appreciated.
procedure
display_list(manager_id in varchar2)
Output is:
emp_id
manager_id
performance_rating
Edited by: Nandini on Apr 28, 2013 10:48 PMYou can use a CASE statment, which will check the MANGER_ID column against the passed manager id value, as shown below..
order by
case when manager_id = :input_manager_id then 0
else 1
end,manager_id,performace_rating desc -
Select statement takes very long to run with order by clause.
Hi all,
I have a select statement which when I run without the order by clause takes arround 2 minutes to run. But with the order by clause it goes on for ever. I am trying to access the database server through a network which is not too fast.
The select statement is based on 9 views which are again based on some views. It also has inline views and outer joins. These views and inline views can not be done away with.
When selected without the order by clause it gives 3215 records.
Anything like 2 to 3 minutes will be Ok.
Thanks.
--MalayThe select statement is as follows :-
SELECT f.system_name,
a.signal_type,
f.sys_signal_name,
a.bus_desc,
b.vl_ident,
b.vl_name,
b.src_mac,
b.src_mac_addr,
b.dest_mac,
b.dest_mac_addr,
b.network,
bb.bufr_size_in_bytes,
bb.bag_in_ms,
bb.is_rma_used,
bb.is_ic_used,
bb.sub_vl_cnt,
bb.skew_max_in_ns,
cc.msg_name,
c.src_ip,
c.src_ip_addr,
c.src_port,
c.dest_ip,
c.dest_ip_addr,
c.dest_port,
cc.rate_in_ms,
cc.tx_mode,
cc.protocol,
cc.port_type,
cc.msg_length_in_bytes,
d.mnemonic,
d.start_addr32,
d.lsb,
d.end_addr32,
d.msb,
d.format,
d.init_value,
d.fs_mnemonic,
d.fs_afdx_data_id,
d.digital_data_id,
DECODE(
d.digital_datatype,
NULL, '',
'UNUSED', '',
api$util.concat_column_data(
'api_'
|| d.digital_datatype,
'digital_data_id',
d.digital_data_id,
bool.FALSE
) AS data_details,
f.connection_id
|| '_'
|| a.digital_bus_id
|| '_'
|| b.afdx_vl_id
|| '_'
|| bb.afdx_output_id
|| '_'
|| c.afdx_frame_id
|| '_'
|| cc.afdx_msg_id
|| '_'
|| d.afdx_data_id AS KEY
FROM api_afdx a,
api_afdx_vl b,
api_afdx_output bb,
api_afdx_frame c,
api_afdx_msg cc,
api_afdx_data d,
vf_signal e,
(SELECT DISTINCT aa.signal_id,
cc.system_name,
bb.connection_id,
bb.sys_signal_name
FROM vf_nodes aa,
vf_connections bb,
vf_system cc
WHERE aa.connection_id = bb.connection_id
AND bb.system_id = cc.system_id) f
WHERE e.signal_id = f.signal_id(+)
AND e.digital_bus_id = a.digital_bus_id
AND a.digital_bus_id = bb.digital_bus_id(+)
AND bb.afdx_output_id = b.afdx_output_id(+)
AND b.afdx_vl_id = c.afdx_vl_id(+)
AND bb.afdx_output_id = cc.afdx_output_id(+)
AND cc.afdx_msg_id = d.afdx_msg_id(+)
ORDER BY f.system_name,
a.signal_type,
f.sys_signal_name,
b.vl_name,
cc.msg_name,
d.start_addr32,
d.lsb;
Where api_afdx ,
api_afdx_vl ,
api_afdx_output ,
api_afdx_frame ,
api_afdx_msg ,
api_afdx_data ,
vf_signal ,
vf_nodes ,
vf_connections ,
vf_system
are all views.
Maybe you are looking for
-
B1 Item to B1 Item scenario on B1if 8.8
Hi there. I'm trying to develop a very simple task with b1if. My target is to get a B1 to B1 consolidation of Items. Any time a item is created or changed, it will be reflected in others sbo companies. So far, I've got a simple scenario with just one
-
Logic Pro 7 - Audio Track record with Firewire In
System: Mac Book Pro. Logic 7.2.3 M-Audio Firewire 410. Aggregate device created = Firewire Multichannel (as input) & Built-In Output. (Built-in microphone turned off) Using condensor mike connected to F/W interface SYMPTOM: No Audio being recorded t
-
Is there a way to asign a transaction to a report painter?
-
Account Number for customer - Urgent
Hi Experts, What is the table and field name for Account number for Customer. Its possible to one account number have more than one customers. Thanks in advance. Points will be rewarded.
-
Serial number entry after posting delivery doc......
hi experts.... we have a requirement in which in the standard sales cycle of Sales order->delivery document posting ( PGI)-> invoice billing the client wants that serial number entry (which is done at the time of PGI) should be done after invoicing(