Subquery with ORDER BY
AFAIK, subquery can have ORDER BY clause in 9iR2. But why I got this error:
SQL> SELECT student_id FROM student
2 WHERE zip =any (SELECT zip
3 FROM zipcode
4 WHERE rownum<=5 ORDER BY zip)
5
SQL> /
WHERE rownum<=5 ORDER BY zip)
ERROR at line 4:
ORA-00907: missing right parenthesis
The error disappear if I remove the ORDER BY clause. My version is 9.2.0.1.0.
I'm sorry. ORDER BY is valid only in inline view and not in sub-query.
SQL>select empno from emp
2 where empno in (select empno from emp order by sal)
3 /
where empno in (select empno from emp order by sal)
ERROR at line 2:
ORA-00907: missing right parenthesis
SQL>select empno from (select empno from emp order by sal)
2 /
EMPNO
7369
7900
7876
7654
7521
7934
7844
7499
7782
7698
7566
7902
7788
7839
8888
9999
16 rows selected.
SQL>Cheers
Sarma.
Similar Messages
-
I don't know what's the meaning of a subquery in order by clause.
for example
select * from table_name
order by (select column from table_name where rownum<=1),
I hope someone can tell me the answerI don't think I can really come up with a situation where it would be any better than other approaches, but it can be used to derive a value which is then used to ORDER the results of the outer query, i.e.
SQL> SELECT a FROM t;
A
A1
B1
2 rows selected.
SQL> SELECT a, seq FROM o;
A SEQ
A1 10
B1 20
2 rows selected.
SQL> SELECT a FROM t
2 ORDER BY ( SELECT seq FROM o WHERE o.a = t.a );
A
A1
B1
2 rows selected.
But, I would still go with a simple join in this situation.
Note, that the subquery can only return one row :
SQL> SELECT * FROM T ORDER BY ( SELECT A FROM T );
SELECT * FROM T ORDER BY ( SELECT A FROM T )
ERROR at line 1:
ORA-01427: single-row subquery returns more than one row -
Hi ,
I have created a sub query with order by on a column.( i have cutomized the IKM control append to put order by).I can see the order by condition.If i use this subquery(yellow interface) in main query(is also yellow interface) i can't see the order by condition
Subquery(Q-yellow interface):
select
PID,
START_TIME,
ACTION_TYPE_CODE
FROM
select DISTINCT
SERVICE_TRACKING_S.PID PID,
TO_TIMESTAMP(TO_CHAR(SERVICE_TRACKING_S.ACTION_TIME,'DD-MON-YY HH24:MI:SS'),'DD-MON-YY HH24:MI:SS') START_TIME,
SERVICE_TRACKING_S.ACTION_TYPE_CODE ACTION_TYPE_CODE
from KSTGDB.SERVICE_TRACKING_S SERVICE_TRACKING_S
where (1=1)
ORDER BY-----------------------------------------------
PID
,START_TIME ASC
ODI_GET_FROM
Main query(Q1--yellow interface):
select
PID,
START_TIME,
ACTION_TYPE_CODE,
RN,
RN_MAX
FROM (
select
Q.PID PID,
Q.START_TIME START_TIME,
CASE WHEN Q.START_TIME-LAG(Q.START_TIME,1,Q.START_TIME) OVER (PARTITION BY Q. PID ORDER BY Q.START_TIME)> numtodsinterval(75,'minute')
or Q.PID!=LAG(Q.PID,1,0) OVER (PARTITION BY Q.PID ORDER BY Q.START_TIME) THEN 1 ELSE Q.ACTION_TYPE_CODE END ACTION_TYPE_CODE,
ROW_NUMBER() OVER(PARTITION BY Q.PID ORDER BY Q.START_TIME) RN,
count(*) over (PARTITION BY Q.PID ORDER BY Q.START_TIME ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING )
RN_MAX
from (
select DISTINCT
SERVICE_TRACKING_S.PID PID, TO_TIMESTAMP(TO_CHAR(SERVICE_TRACKING_S.ACTION_TIME,'DD-MON-YY HH24:MI:SS'),'DD-MON-YY HH24:MI:SS') START_TIME, SERVICE_TRACKING_S.ACTION_TYPE_CODE ACTION_TYPE_CODE
from KSTGDB.SERVICE_TRACKING_S SERVICE_TRACKING_S
where (1=1)
----------------- i don't see order by here--------------------------------
) Q
where (1=1)
) ODI_GET_FROM
thanks in advance
KHi,
Add a new KM step with the SQL you want to use for the sub query and select the +"Use Current Command for Derived-Table sub-select statement"+ checkbox. This new step can be the last one of your IKM.
Basically, you can copy the select statement of the "Insert new rows" step.
Regards,
JeromeFr -
SUBQUERY with INNER JOIN in ABAP
Hi Expert
How Can I write SUBQUERY with INNER JOIN in ABAP.
thanksThanks Sidhharth for your Respose
Actually I need data from VBAP, VBAK, VBUP, VBUK and VBKD with all functional validation satisfied for a sales order item data. The requirement is to report all item data with other information from table VBAK, VBUP, VBUK and VBKD in a corresponding record with ALL data in VBAP.
Your help is appriciated.
see the below query for reference
select alias_vbap~vbeln from vbap as
alias_vbap inner join vbak as alias_vbak
on alias_vbapvbeln eq alias_vbakvbeln
"and alias_vbak~bukrs_vf eq '2400'
inner join vbuk as alias_vbuk
on alias_vbukvbeln = alias_vbapvbeln
inner join vbup as alias_vbup
on alias_vbupvbeln = alias_vbapvbeln
and alias_vbupposnr = alias_vbapposnr
left OUTER join veda as alias_veda
on alias_vedavbeln = alias_vbapvbeln
and alias_vedavposn = alias_vbapposnr
left outer join vbkd as alias_vbkd
on alias_vbkdvbeln = alias_vbapvbeln
and alias_vbkdposnr = alias_vbapposnr -
problem with order in iPhoto. I can't buy a card, because there comes an Message "Ihre Karte enthält offenbar Standardtext, der noch nicht bearbeitet wurde. Gedruckte Karten enthalten diesen Text nicht. Möchten Sie fortfahren?" What should I do?
That message means that you have text boxes that have not been used. The holding text that appears in the box will not be printed. But if you want to get rid of the warning just put a space in the text box.
OR, check to see if the card layout has the same page but without a text box. Most do.
OT -
How to Create Excise Invoice (J1IIN) with order related billing document
Dear Experts,
Is it possible to Create Excise Invoice (J1IIN) with order related billing document? How? please guide
Regards
BK GAIKWADSir,
We have make the supplementary Invoice (Debit Note) as per below process
1) Create sales order_VA01
2) Create billing document_VF01_with reference to sales order
3) Create Excise Invoice With J1IS (Other Movement) It is manually job & due to heavy work load (create 200 invoice per day) it is not possible to do manually.
Hence we want to create excise Invoice with J1IIN instead of J1IS, any alternative solution for that?
Regards
BK GAIKWAD -
Issue with order or sequence of wbs elements appearance in planning layout
Hi Experts
we have an issue with order or sequence of wbs elements appearance in BPS planning layout.
In BW - 0wbs element - hierarchy order is as below
1
2
3
4
5
6
7
8
but when we check the same wbs element in BPS planning layout, it appears as below
1
2
3
4
6
7
5
8
Request you to advice how to correct the order.
Best Regards
krishnaHi,
I came across a similar situation once. I dont remember exactly.
We have two different DataSources on wbs hierarchy. The hiearchy was loaded using the two datasources.
By mistake we were trying to use the hierarchy created by Datasource2, instead of hier created by datasource1.
Can you check that. -
Problem in Outbound delivery with order reference
Hi,
I am facing problem with creation of outbound delivery with order reference from transaction VL01N. When i enter into the transaction with order key in, but in the tab Picking there is one column Pick quantity which is showing as grey field with zero value(Grey field don't allow to change the quantity). This Pick quantity is always allow to put us required quantity but i come across this kind of scenario very first time. Can you please help.
Thank you.Hi,
Your combination of Plant+Storage location is enabled for warehouse management. So directly putting the picking value is not possible. You have two options now.
1. If you know howto put pickign through transfer orders, do it through LT03 and confirm teh TO for picking quantity to be updated in delivery. You have to find out teh stock in the source bin and use it in transfer order. You may get in touch with WM consultant, if you dont know how to do it.
2. If you are ok with just doing picking without WM, then you can change the storage location in delivery and then try picking in delivery itself. The storage location should not be enabled for WM for the plant. -
Vendor Return process with order type ZPO - movement type 161
Dear Friends ,
Here is my question
There are two scenarios for vendor return
while UD and stock posting , we directly post the stock to vendor return 121
but what is the process for vendor return after we move the stock to blocked stock and then return to vendor
I tryed to create new PO with order type PO return , when do the migo GR system always propose 161 and creating inspection lot
how to stream line the process without inspection lot
Thanks & Regards
RajDear Gajesh,
many thanks
but when i enter the Retrun PO in MIGO system automatically propose the movement type 161 , is there any way to change the movement type , is it standard sap settings
Please advice
Thanks & Regards
Raj -
How to use a parameter with Order By?
I am trying to pass in a parameter to a procedure (like 'ColumnName ASC, ColumnName DESC') to use with ORDER BY, but I can't get it to order on the passed in parameter? I have read a few posts but non of my attempts have worked.
Procedure getEquipmentList(io_cursor OUT ref_cursor_Equipment), orderString IN VARCHAR2, RecordStart IN NUMBER, RecordEnd IN NUMBER) IS
Equipment_Cursor refCursor_Equipment;
Use_Order NUMBER := 1;
BEGIN
OPEN Equipment_Cursor
FOR SELECT *
FROM TABLE(
PACKAGE_EQUIPMENT.getRecordSetOfEquipment(
CURSOR(
SELECT * FROM (SELECT idEquipment, strEquipmentName, deletedFlag, Row_Number() OVER (ORDER BY DECODE(Use_Order, 1, orderString)) AS r FROM tblEquipment) WHERE r >= RecordStart AND r <= RecordEnd)));
io_cursor := Equipment_Cursor;
END;
If I replace orderString in the DECODE with say strEquipmentName it orders correctly. If I try 'strEquipmentName' then it does not work. Any ideas would be helpful.SQL>
SQL> create or replace procedure test2(ord in varchar2)
2 is
3 TYPE TCUR IS REF CURSOR;
4 CUR TCUR;
5 v_name varchar2(30);
6 begin
7 open cur for 'select first_name from employees where rownum<=10 order by '||ord;
8 loop
9 fetch cur into v_name;
10 exit when cur%notfound;
11 dbms_output.put_line(v_name);
12 end loop;
13 end;
14 /
Procedure created
SQL> exec test2('employee_id');
Steven
Neena
Lex
Alexander
Bruce
David
Valli
Diana
Nancy
Daniel
PL/SQL procedure successfully completed
SQL> exec test2('salary');
Diana
Valli
David
Bruce
Daniel
Alexander
Nancy
Lex
Neena
Steven
PL/SQL procedure successfully completed
SQL> -
Hello all,
Does anyone know if "order by" has precedence over "for update"? In other words, using the following query. Will the resulting rows be sorted first and then locked or they will be locked first and then sorted?
SELECT /*+ cardinality(al 1) use_nl(al t) */ NULL
BULK COLLECT INTO l_nullvalue_list
FROM TABLE (i_list) al, my_table t
WHERE al.id = t.id
ORDER BY t.id
FOR UPDATE OF t.id;
Any help is very much appreciated.
Regards,
wfThis is the case I'm talking about:
drop table t cascade constraints purge;
create table t as select rownum id, cast('x' as char(100)) pad
from dual connect by level <= 10000;
drop table t1 cascade constraints purge;
create table t1(id int);
-- 1st session
SQL> lock table t1 in exclusive mode;
Table(s) locked
-- 2nd session
declare
type t1_type is table of rowid index by binary_integer;
l_tab t1_type;
begin
execute immediate 'lock table t1 in share mode';
select rowid bulk collect into l_tab
from t order by dbms_random.value
for update;
end;
-- 3rd session
declare
type t1_type is table of rowid index by binary_integer;
l_tab t1_type;
begin
execute immediate 'lock table t1 in share mode';
select rowid bulk collect into l_tab
from t order by dbms_random.value
for update;
end;
/Now 2nd & 3rd sessions are blocked by 1st. Let's release that lock:
-- 1st session
SQL> commit;
Commit complete2nd & 3rd sessions are trying to lock rows of table T, and one of sessions fails with deadlock:
declare
type t1_type is table of rowid index by binary_integer;
l_tab t1_type;
begin
execute immediate 'lock table t1 in share mode';
select rowid bulk collect into l_tab
from t order by dbms_random.value
for update;
end;
ORA-00060: deadlock detected while waiting for resource
ORA-06512: at line 7If you repeat the same scenario with ORDER BY id, then one session will be waiting for enqueue.
So, it's all about order in which row locks are acquired. -
How to create a record for table PLAF with order type 'NB'.
How to create a record for table PLAF with order type 'NB'(standard purchase order).
who can tell me the T-code or some usefull information?
Thanks.Hi
This will be updated automatically when generate planned orders thru MRP. (MD02)
regards
Srinivas -
Create STO with order unit of measure
Hello,
Is there a way to create Plant to plant STO with ordering unit of measure? Based on our customization we are not able to use Unit of issue from supplying plant and we also cant have base unit of measure in the STO.
Any help will be greatly appreciated.
thanks!Hi,
Please refer the KBA: 1980679 - Why the field 'Unit of Issue' of the supplying plant is taken in STO? which explains the standard design. The unit of issue in the supplying plant has the highest priority in case of intra company STO and there is no configuration option to change it as of my knowledge. If you need to alter the standard behavior, you may check the feasibility of development. You may check the BAdI: ME_PROCESS_PO_CUST
Regards,
AKPT -
Prepared Statement with ORDER BY
I am trying to use order by with prepared statement but it is not ordering.
String sql = "SELECT * FROM MATERIAL WHERE (LOWER(NAMEE) LIKE ('%' || ? || '%') ORDER BY ? ";
PreparedStatement ps=CM.getStatement(sql);
ps.setString(1,p);
ps.setString(2,sort);
ResultSet r = ps.executeQuery();
Can any one tell me how do I use prepared statement with order byYou can not parameterize column names and such, only literals. You should build the ORDER BY clause dynamically.
-
Oracle query tuning : query with Order-by clause
Hi
I am having a query in my database :
SELECT * FROM SAPR3.HRP1001 WHERE "MANDT" = 990
ORDER BY
"MANDT" , "OTYPE" , "OBJID" , "PLVAR" , "RSIGN" , "RELAT" , "ISTAT" , "PRIOX" , "BEGDA" , "ENDDA" ,"VARYF" , "SEQNR" ;
Autotrace output is :
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=4649 Card=171895 Byt
es=22862035)
1 0 SORT (ORDER BY) (Cost=4649 Card=171895 Bytes=22862035)
2 1 TABLE ACCESS (FULL) OF 'HRP1001' (Cost=1170 Card=171895
Bytes=22862035)
Statistics
0 recursive calls
5 db block gets
12157 consistent gets
11543 physical reads
0 redo size
38253080 bytes sent via SQL*Net to client
376841 bytes received via SQL*Net from client
34201 SQL*Net roundtrips to/from client
0 sorts (memory)
1 sorts (disk)
512992 rows processed
Since it is a issue with order by , it seems a PGA memory issue. there is 12GB PGA available but only 3GB gets allocated. pga_aggregate target is set in the DB. There is a index created for al the columns on order by, but it is not getting used.
pleas suggest me as I am running into major problems, i can post the output of any query u require from my side. Any help wil be highly apprciated.
Rishi> The query was alwasy spilling over to the One-Parse execution . It can be seen thru ST04N ->resource consumption-> sql work area trace.
>
> An undocumented oracle parameter smmmax_size was set which allowed for more usage of physical memory by single process and there was no spillover to the TEMP tablespaces.
>
> Also the File read time was analysed from Unix level ( From SAP thru ST04 ->filesystem wait s-> Avg rd (ms) and Ang writes (ms) which showed that reading from the File was not happening well. )
Hi Rishi,
the provided execution statistics prove the opposite:
>Statistics
>...
>0 sorts (memory)
> 1 sorts (disk)
>512992 rows processed
This indeed was a single-pass sort, which means it had to use the temp tablespace for one pass of the sorting/grouping.
Remember that Oracle distinguishes three kinds of sorts: 1. "in memory", 2. "single-pass" and 3. "multi-pass".
Only the first one won't need to spill out data to the disks. The others do this by definition.
BTW: the file read times in ST04 are aquired through Oracle V$ views and not directly from the OS - that can make a big difference sometimes.
regards,
Lars
Maybe you are looking for
-
Are /etc/udev/rules.d/86-hpmud* files obsolete?
For a while now, I keep getting the following errors during boot: Sat Jan 21 14:25:13 2012: udevd[148]: unknown key 'SYSFS{idVendor}' in /etc/udev/rules.d/86-hpmud-hp_laserjet_professional_p1102w.rules:9 Sat Jan 21 14:25:13 2012: udevd[148]: invalid
-
SMSY t.code in Solution Manager 3.2
I want the steps for using SMSY t.code. In detail i want to configure the SLD using SMSY. URGENT Satinder Lamba
-
Failed to goto purchased Content in iTunes & App Store
I have recently updated my iPod to "iOS 6.0.1" and when I want to look at my purchased in ether iTunes and App Store it shows that as if it is working while you wait about 20 sec and then shows the home screen. Anyone know how to contact apple about
-
Hello Experts, I want to setup the Enterprise portal with IDM 7.1 (Newly) Identity Management for SAP System Landscapes Configuration Guide -> 3.4.3 Setting up the SAP NetWeaver Portal Environment Use Case says The AS Java that is running the portal
-
Deletion of item in STO -- please help.
Hi All, I want to put deletion indicator against a line item in STO. However the PO history shows there is a DN created and a 641 movement done. Now if I wnat to reverse the entire thing, how do I go about this and what T-codes to be used ? Kindly he