IS IT POSSIBLE TO WRITE ORDER BY CLAUSE WITHIN INNER QUERY
IS IT POSSIBLE TO WRITE ORDER BY CLAUSE WITHIN INNER QUERY
So you still can't :) I still don't see it that strict:
You know of course that this is possible:
select ename, (select ename
from (select empno, ename
from emp
where deptno = 10
order by 1) e2
where e.empno = e2.empno) a
from emp eso we have an »ORDER BY CLAUSE WITHIN INNER QUERY« which is even correlated (though through the outer query).
Whether this makes sense or not is not question imho :-) ... but you can
Similar Messages
-
Suppress "Order By" clause in Answers Query
Hello,
Is it possible to Suppress "Order By" clause in Answers Query.
I'm using a database view as data source. In the view definition, "order by" clause is already specified. Is it possible to get the same order in the OBIEE report??
I do not want to use Sort Order column in the repository.
Thanks,
GirishYou add a rownumber to your DB view and use that to 'sort' your report.
regards
John
http://obiee101.blogspot.com/ -
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 -
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
); -
Is there any point in having an ORDER BY clause within a FOR LOOPs counter?
DB Version:10.2.0.1.0
I need to loop through empno's using a FOR loop. But is there any point in having an Order by clause within SQL as shown below. This only degrades the performance because of the unnecessary sorting by the ORDER BY clause. Right?
begin
FOR i IN (select empno from emp ORDER BY sal ASC) LOOP
curr_stat_id := i.empno +p_gennum;
.First question you should ask to your self is
"Do i need a FOR LOOP. Cant i do it in a straight SQL"
If the answer is NO (Which is not in several cases) then the next question is.
"What is my requirement"
Having an order by in the Select is totally pertained to your requirement. If your requirement
says you should loop through the employee based on there salary for lowest to highest then yes you
need an order by.
So more than performance point of view its requirement point of you. But if you are more concern about
performance you will first ask to your self
"Do i need a FOR LOOP. Cant i do it in a straight SQL"
Thanks,
Karthick. -
Where to place ORDER BY clause when a query includes UNION
I have a query that has UNION in it. could you please tell me where to place the ORDER BY clause. Because it's throwing an error if i place the ORDER BY clause at the end
Because you are using the UNION set operator, you need to either specifically list your columns or use positional notation.
Without a set operator we can order by the column name without specifically listing it:
SQL> select * from dual
2 order by dummy;
D
X
1 row selected.This doesn't work once you introduce a set operator:
SQL> ed
Wrote file afiedt.buf
1 select * from dual union all
2 select * from dual union all
3 select * from dual
4* order by dummy
SQL> /
order by dummy
ERROR at line 4:
ORA-00904: "DUMMY": invalid identifierSo you need to either use positional notation:
SQL> ed
Wrote file afiedt.buf
1 select * from dual union all
2 select * from dual union all
3 select * from dual
4* order by 1
SQL> /
D
X
X
X
3 rows selected.Or, specifically list or alias the columns you are projecting:
SQL> ed
Wrote file afiedt.buf
1 select dummy from dual union all
2 select dummy from dual union all
3 select dummy from dual
4* order by dummy
SQL> /
D
X
X
X
3 rows selected.
SQL> ed
Wrote file afiedt.buf
1 select dummy as d from dual union all
2 select dummy as d from dual union all
3 select dummy as d from dual
4* order by d
SQL> /
D
X
X
X
3 rows selected.cheers,
Anthony -
[10g] Need help with order by clause in hierarchical query
I have the following sample data:
CREATE TABLE bill_test1
( parent_part CHAR(25)
, child_part CHAR(25)
, line_nbr NUMBER(5)
, qty_per NUMBER(9,5)
INSERT INTO bill_test1 VALUES ('ABC-1','ABC-10',100,1);
INSERT INTO bill_test1 VALUES ('ABC-1','ABC-20',200,2);
INSERT INTO bill_test1 VALUES ('ABC-1','ABC-30',300,3);
INSERT INTO bill_test1 VALUES ('ABC-1','HARDWARE-1',401,10);
INSERT INTO bill_test1 VALUES ('ABC-1','HARDWARE-2',402,5);
INSERT INTO bill_test1 VALUES ('ABC-10','ABC-155',100,2);
INSERT INTO bill_test1 VALUES ('ABC-10','HARDWARE-1',200,1);
INSERT INTO bill_test1 VALUES ('ABC-155','RAW-2',100,4.8);
INSERT INTO bill_test1 VALUES ('ABC-155','HARDWARE-3',200,3);
INSERT INTO bill_test1 VALUES ('ABC-20','RAW-1',100,10.2);
INSERT INTO bill_test1 VALUES ('ABC-30','RAW-3',100,3);And the query below gives me exactly what I want, in the order I want it. However, I am wondering if there is a way to get this order without creating the SEQ column, since I don't need it in my results
SELECT part_nbr
, parent_part
, child_part
FROM (
SELECT CONNECT_BY_ROOT b.parent_part AS part_nbr
, b.parent_part
, b.child_part
, SYS_CONNECT_BY_PATH(b.line_nbr,' ') AS seq
FROM bill_test1 b
, dual
CONNECT BY parent_part = PRIOR child_part
WHERE part_nbr = 'ABC-1'
ORDER BY seq
Results of above query, except with SEQ included in SELECT (just to show what I'm sorting off of):
PART_NBR PARENT_PART CHILD_PART SEQ
ABC-1 ABC-1 ABC-10 100
ABC-1 ABC-10 ABC-155 100 100
ABC-1 ABC-155 RAW-2 100 100 100
ABC-1 ABC-155 HARDWARE-3 100 100 200
ABC-1 ABC-10 HARDWARE-1 100 200
ABC-1 ABC-1 ABC-20 200
ABC-1 ABC-20 RAW-1 200 100
ABC-1 ABC-1 ABC-30 300
ABC-1 ABC-30 RAW-3 300 100
ABC-1 ABC-1 HARDWARE-1 401
ABC-1 ABC-1 HARDWARE-2 402Hi,
As long as there's only one root, you can say ORDER SIBLINGS BY, but you can't do that in a sub-query (well, you can, but usually there's no point in doing it in a sub-query). If the CONNECT BY is being done in a sub-query, there is no guarantee that the main query will preserve the hierarchical order that the sub-query provides.
The query you posted doesn't require a suib-query, so you can say:
SELECT CONNECT_BY_ROOT b.parent_part AS part_nbr
, b.parent_part
, b.child_part
--, SYS_CONNECT_BY_PATH(b.line_nbr,' ') AS seq
FROM bill_test1 b
WHERE CONNECT_BY_ROOT b.parent_part = 'ABC-1'
CONNECT BY parent_part = PRIOR child_part
ORDER SIBLINGS BY b.line_nbr
;I said the query you posted doesn't require a sub-query. It also doesn't require dual, so I suspect what you posted is a simplification of what you're really doing, and that may need a sub-query. In particular, if you intend to GROUP BY part_nbr, then you need the sub-query. We can repeat the CONNECT_BY_ROOT expression in the WHERE clause (or, now that I think about it, use a START WITH clause instead of WHERE), but, for some reason, we can't use CONNECT_BY_ROOT in a GROUP BY clause; we need to compute CONNECT_BY_ROOT in a sub-query, give it a name (like part_nbr), and GROUP BY that column in a super-query.
This assumes that there is only one root node. ORDER SIBLINGS BY means just that: children of a common parent will appear in order, but the root nodes, who have no parents, will not necessarily be in order.
Here's what I meant by using START WITH instead of WHERE:
SELECT CONNECT_BY_ROOT b.parent_part AS part_nbr
, b.parent_part
, b.child_part
--, SYS_CONNECT_BY_PATH(b.line_nbr,' ') AS seq
FROM bill_test1 b
START WITH b.parent_part = 'ABC-1'
CONNECT BY parent_part = PRIOR child_part
ORDER SIBLINGS BY b.line_nbr
;This should be much more efficient, because it narrows down the results before you waste time getting their descendants.
Using a START WITH clause here is analagous to me sending you an e-mail, saying "Come to a meeting a my office at 3:00."
Using a WHERE clause here is analagous to me sending an e-mail to everyone in the company, saying "Come to a meeting a my office at 3:00", and then, as people get here, telling everyone except you that they can go back.
ORDER SIBLINGS BY was introduced in Oracle 9.
Edited by: Frank Kulash on Dec 9, 2010 2:39 PM
Added version with START WITH clause -
Order By Clause - Slows performance
On 10.2 when adding an order by clause to a query affects performance that returns 6 rows of data.
Before:
select distinct col1
from table1
Cost: 3,000
Execution Time: less than a second
Chooses: Bitmap Index Fast Full Scan Index (BitMap)
After:
select distinct col1
from table1
order by col1
Cost: 14,000
Execution time: 90 seconds
Chooses: Full TableScan
Any ideas as to why the order by causes the slow down ?
Thanks,Venzi wrote:
Now you add the order by clause to it and Oracle has now to do a sort on it. It can't sort on the BITMAP index in that case so it has to go to the table. It is possible for Oracle to do the order by through the bitmap index - the reason it doesn't is probably down to arithmetic. (The situation is made a little messier by the fact that the table and index have been parallel enabled). Here's a plan from 10.2.0.3 showing the "order by" query running through the bitmap index:
| Id | Operation | Name | Rows | Bytes | Cost | TQ |IN-OUT| PQ Distrib |
| 0 | SELECT STATEMENT | | 6 | 18 | 356 | | | |
| 1 | PX COORDINATOR | | | | | | | |
| 2 | PX SEND QC (ORDER) | :TQ10001 | 6 | 18 | 356 | Q1,01 | P->S | QC (ORDER) |
| 3 | SORT GROUP BY | | 6 | 18 | 356 | Q1,01 | PCWP | |
| 4 | PX RECEIVE | | 2000K| 5859K| 63 | Q1,01 | PCWP | |
| 5 | PX SEND RANGE | :TQ10000 | 2000K| 5859K| 63 | Q1,00 | P->P | RANGE |
| 6 | PX BLOCK ITERATOR | | 2000K| 5859K| 63 | Q1,00 | PCWC | |
| 7 | BITMAP CONVERSION TO ROWIDS | | 2000K| 5859K| 63 | Q1,00 | PCWP | |
| 8 | BITMAP INDEX FAST FULL SCAN| T1_B1 | | | | Q1,00 | PCWP | |
------------------------------------------------------------------------------------------------------------Note how the optimizer can recognise that the "group by" operation will allow it to avoid an explicit "order by" operation, and uses the "(ORDER)" distribution to pass the data to the Query Coordinator to enforce correct ordering.
Running up a test case with a couple of million rows, it looks like the underlying problem the OP has is that the CBO bypasses a few of the execution options in this particular case when parallel execution is possible. (I had to hint this plan - the default plan was a serial full scan of the index that allowed the optimizer to bypass the "sort order" because of a "sort unique", but the cost was much higher than this parallel plan - see below).
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 6 | 18 | 2269 |
| 1 | SORT UNIQUE NOSORT | | 6 | 18 | 2269 |
| 2 | BITMAP INDEX FULL SCAN| T1_B1 | 2000K| 5859K| 278 |
-----------------------------------------------------------------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.
There is a +"Preview"+ tab at the top of the text entry panel. Use this to check what your message will look like before you post the message. If it looks a complete mess you're unlikely to get a response. (Click on the +"Plain text"+ tab if you want to edit the text to tidy it up.)
+"I believe in evidence. I believe in observation, measurement, and reasoning, confirmed by independent observers. I'll believe anything, no matter how wild and ridiculous, if there is evidence for it. The wilder and more ridiculous something is, however, the firmer and more solid the evidence will have to be."+
Isaac Asimov -
Order by clause in PL/SQL cursors
I am trying to execute a procedure with some input parameters. I open a cursor
with a select statement. However, the order by clause in the query does not
recognize parameter sent through the procedure input parameters.
For example:
open <<cursor name>> for
select id from member order by <<dynamic parameter>>" does not work (Compiles fine but does not return the right result).
But if I try and give a static order by <<column name>> it works. Is the
order by clause in the PL/SQL a compile time phenomenon?
I have also tried it through dynamic sql. All the other parameters work except the order by <<parameter>> asc|desc
Also "asc" and "desc" does not work if given dynamically.
What alternatives do I have?
nullI don't think order by can be dynamic in a cursor, but it sure can be using dynamic sql. The only issue is that you must do a replace in the sql string with the dynamic variable. For example:
create or replace procedure test_dyn(p_col in varchar2, p_order in varchar2) as
q varchar2(500);
u_exec_cur number;
u_columnnumber NUMBER;
u_columndate DATE;
u_columnvarchar varchar2(50);
u_cur_count number;
u_ename varchar2(20);
u_sal number;
begin
q := 'select ename, sal from scott.emp order by p_col p_order';
-- got to do these two replaces
q:= replace(q,'p_col',p_col);
q:= replace(q,'p_order',p_order);
u_exec_cur := dbms_sql.open_cursor;
dbms_sql.parse(u_exec_cur,q,dbms_sql.v7);
dbms_sql.define_column(u_exec_cur, 1, u_columnvarchar, 20);
dbms_sql.define_column(u_exec_cur, 2, u_columnnumber);
u_cur_count := dbms_sql.execute(u_exec_cur);
loop
exit when (dbms_sql.fetch_rows(u_exec_cur) <= 0);
dbms_sql.column_value(u_exec_cur, 1, u_ename);
dbms_sql.column_value(u_exec_cur, 2, u_sal);
dbms_output.put_line(u_ename);
dbms_output.put_line(u_sail);
--htp.p(u_ename);
--htp.p(u_sal);
end loop;
end;
show errors;
Now when when I execute my procedure I can change the order by clause all I want, for example:
SQL> set serveroutput on;
SQL> exec gmika.test_dyn('sal','asc');
SMITH
800
ADAMS
1100
WARD
1250
MARTIN
1250
MILLER
1300
TURNER
1500
ALLEN
1600
JLO
2222
BLAKE
2850
JONES
2975
SCOTT
3000
FORD
3000
LOKITZ
4500
KING
5000
JAMES
5151
JAMES
5555
PL/SQL procedure successfully completed.
SQL>
null -
I need to dynamically build the order by clause of my query.
I tried this:
<named-query name="list">
<query>
<![CDATA[
SELECT p FROM Person p
ORDER BY :orderby
]]>
</query>
</named-query>
@SuppressWarnings("unchecked")
public List<Person> list(String sort) {
Query query = getEntityManager().createNamedQuery("list");
query.setParameter("orderby", sort);
return query.getResultList();
}But at runtime it throws an exception:
com.microsoft.sqlserver.jdbc.SQLServerException:
L'elemento SELECT identificato da ORDER BY 1 include una variabile nell'espressione che identifica la posizione di una colonna.
Le variabili sono consentite solo nell'ordinamento in base a un'espressione che fa riferimento a un nome di colonna.The translation of the italian message is something like:
The SELECT element identified by ORDER BY 1 includes a variable that identifies the position of a column.
The valid variables in the order by clause must refer to the name of a columnThe value of the parameter sort is_ the name of a column!
Any hint?My solution was to append the order clause to an "namedQuery" like this:
- declare the named query as usual, with annotation
- create a simple helper function like findNamedQuery to find the query string for a given class and queryName (using reflection)
- if you need to execute the query without sort order - use EntityManager.createNamedQuery (as usual)
- BUT: if you want to sort data: use EntityManager.createQuery with the string obtained from findNamedQuery and the sort clause
I guess the is a performance penalty, but.. .it works. -
Popup lov with order by clause
I created a form manually using the document from the url:
http://otn.oracle.com/products/database/htmldb/howtos/tabular_form.html#MANUAL
I used the following query from that document.
select htmldb_item.hidden(1,empno) empno,
ename,
htmldb_item.select_list_from_query(3,job,'select distinct job, job from emp') job,
htmldb_item.popupkey_from_query(4,mgr,'select ename, empno from emp',10) mgr,
wwv_flow_item.date_popup(6,null,hiredate) hiredate,
htmldb_item.text(7,sal,10) sal,
htmldb_item.text(8,comm,10) comm,
htmldb_item.select_list_from_query(9,deptno,'select dname, deptno from dept') deptno
from emp
This works fine.
But if I add an order by clause to the query the popup key for mgr column doesn't work.
select htmldb_item.hidden(1,empno) empno,
ename,
htmldb_item.select_list_from_query(3,job,'select distinct job, job from emp') job,
htmldb_item.popupkey_from_query(4,mgr,'select ename, empno from emp',10) mgr,
wwv_flow_item.date_popup(6,null,hiredate) hiredate,
htmldb_item.text(7,sal,10) sal,
htmldb_item.text(8,comm,10) comm,
htmldb_item.select_list_from_query(9,deptno,'select dname, deptno from dept') deptno
from emp
order by ename
Thanks
Chandra.Duplicate post, see:
popup lov in a report is not working if I have an order by caluse
Sergio -
Query taking 6mins to execute wityh order by clause, 3secs without orderby
Dear All,
The below query is taking nearly 6minutes time to execute (as i have order by clause in the query)
/* Formatted on 2007/09/26 10:03 (Formatter Plus v4.8.0) */
SELECT (SELECT DISTINCT grndate
FROM fs_lg_grnhdr
WHERE grnid = pl.grnid AND custwhid = pl.custwhid)
grndate,
pl.grnid,
(SELECT DISTINCT vi.orderno
FROM fs_lg_vendorinvoicehdr vi, fs_lg_grndtl gd
WHERE gd.vendorinvoiceid = vi.vendorinvoiceid
AND gd.custwhid = vi.custwhid
AND gd.custwhid = pl.custwhid
AND gd.grnid = pl.grnid
AND gd.partid = pl.partid) orderno,
pl.expirydate, pl.batchno, pl.packuom,
NVL (pl.receiptqty, 0) receiptqty, pl.putawayid, pl.lineno,
(SELECT customscontrolno
FROM fs_lg_putawaydtl
WHERE custwhid = pl.custwhid
AND putawayid = pl.putawayid
AND partid = pl.partid
AND locationto = pl.locationid) cctrlno,
(SELECT customspermitno
FROM fs_lg_putawayhdr
WHERE custwhid = pl.custwhid
AND putawayid = pl.putawayid) cpermitno,
(SELECT SUM (pdtl.pickqty)
FROM fs_lg_pickticketdtl pdtl,
fs_lg_picktickethdr phdr
WHERE pdtl.custwhid = pl.custwhid
AND pdtl.putawayid = pl.putawayid
AND pdtl.putawaylineno = pl.lineno
AND phdr.custwhid = pdtl.custwhid
AND phdr.pickticketid = pdtl.pickticketid
AND phdr.pickdate < '01-SEP-2007'
AND pdtl.status = 'CM') previousoutqty,
(SELECT SUM (pdtl.pickqty)
FROM fs_lg_pickticketdtl pdtl,
fs_lg_picktickethdr phdr
WHERE pdtl.custwhid = pl.custwhid
AND pdtl.putawayid = pl.putawayid
AND pdtl.putawaylineno = pl.lineno
AND phdr.custwhid = pdtl.custwhid
AND phdr.pickticketid = pdtl.pickticketid
AND phdr.pickdate BETWEEN '01-SEP-2007'
AND '25-SEP-2007'
AND pdtl.status = 'CM') presentoutqty,
NVL ((SELECT SUM (qty)
FROM fs_lg_internaltransdtl
WHERE putawayid = pl.putawayid
AND fromputawaylineno = pl.lineno
AND custwhid = pl.custwhid),
0
) toistqty,
NVL ((SELECT SUM (qty)
FROM fs_lg_internaltransdtl
WHERE custwhid = pl.custwhid
AND putawayid = pl.putawayid
AND slno = pl.lineno),
0
) fromistqty
FROM fs_lg_partloads pl
WHERE pl.partid = '2ERCH-2022'
AND pl.custwhid = 'RNH-CSM'
AND inventoryflag IN ('AVAIL','')
AND pl.status = 'CM'
AND pl.grndate <= '25-SEP-2007'
ORDER BY grndate, pl.grnid, pl.putawayid, pl.lineno;
But when i don't use the order by clause it is executing within 3 seconds. But i need to get the output in the sorted order as shown in the order by clause.
Is there any way to avoid order by clause and to get the same output as with order by clasue, and i need to execute the query with less time.
Please help me in this.
Thanks in advance
MahiDear Alok Kumar,
When i execute sql>set autotrace traceonly statistics ;
I am getting the below errors...
SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled
SP2-0611: Error enabling STATISTICS report
What could be the problem, how to resolve this to get the statistics?
But when i use sql>set autotrace traceonly explain; i got the below output for the above query..
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_GRNHDR'
2 1 INDEX (UNIQUE SCAN) OF 'SYS_C00293078' (UNIQUE)
3 0 SORT (UNIQUE)
4 3 NESTED LOOPS
5 4 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_GRNDTL'
6 5 INDEX (RANGE SCAN) OF 'SYS_C00293075' (UNIQUE)
7 4 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_VENDORINVOICEH
DR'
8 7 INDEX (UNIQUE SCAN) OF 'PK_VENDORINVOICE' (UNIQUE)
9 0 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_PUTAWAYDTL'
10 9 INDEX (UNIQUE SCAN) OF 'SYS_C00293260' (UNIQUE)
11 0 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_PUTAWAYHDR'
12 11 INDEX (UNIQUE SCAN) OF 'SYS_C00293263' (UNIQUE)
13 0 SORT (AGGREGATE)
14 13 NESTED LOOPS
15 14 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_PICKTICKETDTL'
16 15 INDEX (RANGE SCAN) OF 'F_L_P_CWI_IND1' (NON-UNIQUE)
17 14 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_PICKTICKETHDR'
18 17 INDEX (UNIQUE SCAN) OF 'SYS_C00293202' (UNIQUE)
19 0 SORT (AGGREGATE)
20 19 NESTED LOOPS
21 20 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_PICKTICKETDTL'
22 21 INDEX (RANGE SCAN) OF 'F_L_P_CWI_IND1' (NON-UNIQUE)
23 20 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_PICKTICKETHDR'
24 23 INDEX (UNIQUE SCAN) OF 'SYS_C00293202' (UNIQUE)
25 0 SORT (AGGREGATE)
26 25 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_INTERNALTRANSDTL
27 26 INDEX (RANGE SCAN) OF 'PK_INTERNALTRANSDTL' (UNIQUE)
28 0 SORT (AGGREGATE)
29 28 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_INTERNALTRANSDTL
30 29 INDEX (RANGE SCAN) OF 'PK_INTERNALTRANSDTL' (UNIQUE)
31 0 SORT (ORDER BY)
32 31 TABLE ACCESS (BY INDEX ROWID) OF 'FS_LG_PARTLOADS'
33 32 INDEX (RANGE SCAN) OF 'PK_PARTLOADS' (UNIQUE)
Please advice me regarding this...
Thanks in advance
Mahi -
With clause in SQL query data model
Hello!
isn't it possible to use the with clause in sql query data models?
for example following query:
WITH
a_test as (
select dummy from dual
select *
from a_test
brings up a "XML Parsing Error: no element found"-error...
BR PaulI tried a slightly different query (see below) and the query worked fine and retrieved data.. I did not get any errors.
WITH
a_test as (
select 'dummy' from dual
select *
from a_test
This works as well.. retrieving the value of the parameter
WITH
a_test as (
select :Test_ID from dual
select *
from a_test
thanks,
BIPuser -
Is parameter in ORDER BY clause possible?
I'm using a function to return a ref cursor and currently pass a parameter without any problems. I would like to change the sort on the fly by passing a parameter to the order by clause, but Oracle ignores it.
CREATE OR REPLACE PACKAGE pkg_agent_appt_status AS
TYPE rcur IS REF CURSOR;
FUNCTION f_agent_appt_status (ssn IN VARCHAR2, sort_str IN VARCHAR2) RETURN rcur;
END pkg_agent_appt_status;
CREATE OR REPLACE PACKAGE BODY pkg_agent_appt_status AS
FUNCTION f_agent_appt_status (ssn IN VARCHAR2, sort_str IN VARCHAR2)
RETURN rcur
IS
retval rcur;
BEGIN
OPEN retval FOR
SELECT agncy.CORPORATE_NAME "Agency Name",
agnt_state.APPT_STATE "State",
agnt.AGENT_STATUS "Appt Status",
TO_CHAR(agnt_state.APPT_STATE_EFF_DT,'mm/dd/yyyy') "Effective Date",
agnt.AGENT_NUMBER "Agent ID",
agnt.AGENT_STATUS "Agent Status",
STATE.STATE_NAME
FROM AGNT_APPT_STAT_PRDCR_WRK agnt,
AGNT_APPT_STAT_WRK agncy,
AGNT_APPT_STATE_STAT_PRDCR_WRK agnt_state,
STATE
WHERE agnt.AGENT_TAX_ID = ssn
AND agnt.COMPANY_CODE = agncy.COMPANY_CODE
AND agnt.PARENT_AGENT_AGENCY_ID = agncy.AGENT_NUMBER
AND agnt.COMPANY_CODE = agnt_state.COMPANY_CODE
AND agnt.AGENT_AGENCY_ID = agnt_state.AGENT_AGENCY_ID
AND agnt.AGENT_NUMBER = agnt_state.AGENT_NUMBER
AND agnt_state.APPT_STATE = STATE.STATE_CODE
ORDER BY
sort_str;
RETURN retval;
END f_agent_appt_status;
END pkg_agent_appt_status;If you want to do this, you'd have to use dynamic SQL (execute immediate or DBMS_SQL). For the easier 'execute immediate' approach, you'd do something like
create or replace someProc( someArg varchar2 )
as
strSQL varchar2(4000)
begin
strSQL := <<string containing your SQL statement up to the order by clause>>
strSQL := strSQL || 'ORDER BY ' || someArg
execute immediate strSQL;
endJustin -
Is passing parameter to ORDER BY clause possible?
I'm using a function to return a ref cursor and currently pass a parameter without any problems. I would like to change the sort on the fly by passing a parameter to the order by clause, but Oracle ignores it.
CREATE OR REPLACE PACKAGE pkg_agent_appt_status AS
TYPE rcur IS REF CURSOR;
FUNCTION f_agent_appt_status (ssn IN VARCHAR2, sort_str IN VARCHAR2) RETURN rcur;
END pkg_agent_appt_status;
CREATE OR REPLACE PACKAGE BODY pkg_agent_appt_status AS
FUNCTION f_agent_appt_status (ssn IN VARCHAR2, sort_str IN VARCHAR2)
RETURN rcur
IS
retval rcur;
BEGIN
OPEN retval FOR
SELECT agncy.CORPORATE_NAME "Agency Name",
agnt_state.APPT_STATE "State",
agnt.AGENT_STATUS "Appt Status",
TO_CHAR(agnt_state.APPT_STATE_EFF_DT,'mm/dd/yyyy') "Effective Date",
agnt.AGENT_NUMBER "Agent ID",
agnt.AGENT_STATUS "Agent Status",
STATE.STATE_NAME
FROM AGNT_APPT_STAT_PRDCR_WRK agnt,
AGNT_APPT_STAT_WRK agncy,
AGNT_APPT_STATE_STAT_PRDCR_WRK agnt_state,
STATE
WHERE agnt.AGENT_TAX_ID = ssn
AND agnt.COMPANY_CODE = agncy.COMPANY_CODE
AND agnt.PARENT_AGENT_AGENCY_ID = agncy.AGENT_NUMBER
AND agnt.COMPANY_CODE = agnt_state.COMPANY_CODE
AND agnt.AGENT_AGENCY_ID = agnt_state.AGENT_AGENCY_ID
AND agnt.AGENT_NUMBER = agnt_state.AGENT_NUMBER
AND agnt_state.APPT_STATE = STATE.STATE_CODE
ORDER BY
sort_str;
RETURN retval;
END f_agent_appt_status;
END pkg_agent_appt_status;This is quite easy, as you are already using a REF CURSOR. Instead of
OPEN retval FOR
SELECT ...
ORDER BY sort_str;we can code this:
OPEN retval FOR
'SELECT ...
ORDER BY '|| sort_str;Watch out for the single quotes in your query e.g. the date format mask: you need to wrap these in an additional set of single quotes i.e. 'mm/dd/yyyy' becomes ''mm/dd/yyyy''.
Cheers, APC
Maybe you are looking for
-
How to Sort one key figure values in two column based on single char
hi gurus, I would really appreciate if some one can help me out with my question. I have to design a query based on a Multiprovider built on three ODS, Purchasing, Confirmations & Invoic ODS Purchase order Value and Number data in PO ODS, and confirm
-
Changing Tax Code in Sales Order
Hi All, I've a requirement to change the tax code of MWST CT from normal value XX to a new tax code in sales order for few excpetion cases. For normal cases the tax code will always be XX for MWST CT in the sales order. However for very specific busi
-
Sourcing Cockpit Worklist - Failure to pre-load worklist
Hello SRM Experts We are running SRM 5.00 in an extended classic scenario. I have a question that is bugging me so hopefully you can help. I have a user who is the sole purchaser in a purchasing group for a specific company code. He is responsible fo
-
So yesterday i was using my mac watching a movie with vlc. Then the movie started lagging and didn't respond properly. I tried closing vlc without luck, so then i used the command + alt + esc and closed vlc that way. However, this didn't stop the pro
-
How to change Textures in Diagramms?
cant believe it. i tried to change my diagramm texture into realistic wood-grain, but cant find out how to do it?!