Help in query from table
Hi,
I am having a strange issue,
i have a table containing the following amgst others
rec_time sys_date
7:00 04/08/2010
8:00 04/08/2010
9:00 05/08/2010
I need to query this table and return the max(rec_time) for all sys_date = sysdate
its not working if i do the following
select max(rec_time) from table
where sys_date = sysdate;
hello,
this is my table structure for hourly_sales
ID NUMBER,
PRODUCT VARCHAR2(25 BYTE) NOT NULL,
GAME_ID NUMBER NOT NULL,
SYS_DATE DATE NOT NULL,
CONFIRMED CHAR(1 BYTE) DEFAULT 'N',
ACT_AMT NUMBER NOT NULL,
CUMM_AMT NUMBER NOT NULL,
COUNT_SALES NUMBER NOT NULL,
CREATED_BY VARCHAR2(25 BYTE),
CREATION_DATE DATE,
LAST_UPDATED_BY VARCHAR2(25 BYTE),
LAST_UPDATED_DATE DATE,
REC_TIME VARCHAR2(25 BYTE) NOT NULL,
ORDER_ID NUMBERI have created a small application in APEX that has an LOV for rec_time from 7.00 to 22.00. this is just an indication to the times that values are being entered.
Now those geezers were making mistakes and the reason why i wanted my query was to enable them to roll-back on a button click
delete from hourly_sales
where rec_time = max(rec_time)
and trunc(sys_date) = trunc(sysdate);but when i was querying it was not returning any values.
Similar Messages
-
Hi,
I'm creating an ad hoc query to retrieve data from table PPDIT by filtering the transaction key. This is to get a list of amounts posted to the technical accounts(Transaction key HRA). However, the query output and the output from table PPDIT through SE16 are different. It seems like the query only picks up transaction key HRF. Anyone with any ideas why?Hi,
Than you add the additional field from extras option.
click on extras tab.
From there add table add field add structure.
If you want to add a field write the name of the field and continue.
suppose the field is matnr.
Long text = material number
header = material number
and in like reference = mara-matnr.
tablename-field name.
let me know if this helps you.
Regrds,
Nikhil. -
J2IUN Mismatch with query from table J_1IPART2
Hi experts,
If I run the TCODE J2IUN there is a marked difference for the RG23C register BED, AED, Cess, and HCess values that have been taken from table J_1IPART2 for the same period. What could be the cause for these differences and why did they occur or do I have to take addtional records from another table also. Well I am considering the Opening balances also.
Please can you help me regarding this.
Regards
Yao ChhangYou will have to first trace the difference. In the next step, go through J2IUN in debug mode with Abaper & check from where all the data is being picked. Next check whether all the data pick point are considered in Query.
Regards,
Rajesh Banka
Reward suitable points. -
Need help with query from .csv file
I am trying to import a csv file with only 1 column in it.
The column will only contain a 9 digit ID number. I want to read
the file then use the contents to query a table to get the names
and other information and display it. Here is what I have so far:
<cffile action="read" file="#form.FiletoUpload#"
variable="csvfile">
<cfloop index="index" list="#csvfile#">
<cfquery name="massimport" datasource="data1">
SELECT * FROM IDTable
WHERE CardNumber = ('#csvfile#')
</cfquery>
</cfloop>
<cfoutput>#Name# #ID# #Site#</cfoutput>
I get no errors but I am not getting any results. Just a
blank page. Does anyone know how to query directly from a csv
import? Thanks.You need to convert your file to a list somehow. Not sure if
this is the most efficient way but, you can use the cfhttp tag to
produce a query. Then your where clause becomes,
where cardnumber in (#quotedvaluelist(query.column)#)
and you won't need a loop. -
[Help] Join query from 3 tables
Hi, I'm new to database. I have a question about joining 3 tables, pardon me for my bad english.
My tables look like this
table 1: Person (id,firstname, lastname)
table 2: AssignPersonAddress (id,personid,addressid,type)
table 3: Address (id,telefon, street, etc)
I need AssignPersonAddress table, because in my data structure a person can have more than 1 address and the address type should be saved (for eg: private, work)
I want to make a select query to report all of person with his private telefon and work telefon, like this.
PERSON | PRIVATE | WORK
At the moment my query looks like this
select p.name , a1.tel AS Private, a2.tel AS Work
from person p,
addresse a1 ,
AssignPersonAddress apd1,
AssignPersonAddress apd2,
addresse a2
where p.id = apd1.person (+)
and apd1.adresse = a1.id
and apd1.art = 'Private'
and p.objectid = apd2.person (+)
and apd2.adresse = a2.id
and apd2.art = 'Work'the problem is I only get the person who has private and work address. But what I want is all person no matter if the person has only 1 address or 2 address.
As you can see I put the outer left join at the where condition, but I'm still getting the wrong result.
thx in advance
Danny
Edited by: raitodn on Oct 1, 2009 3:51 AM
Edited by: raitodn on Oct 1, 2009 4:12 AMHi,
You're essentially doing an inner join, because some of the comparisons are missing the + markerr.
Do this instead:
select p.name , a1.tel AS Private, a2.tel AS Work
from person p
, addresse a1
, AssignPersonAddress apd1
, AssignPersonAddress apd2
, addresse a2
where p.id = apd1.person (+)
and apd1.adresse = a1.id (+)
and apd1.art (+) = 'Private'
and p.objectid = apd2.person (+)
and apd2.adresse = a2.id (+)
and apd2.art (+) = 'Work'
;What does this mean?
where p.id = apd1.person (+)It means "include rows from p even if they don't have any matching rows in apd1". Whenever that happens, all the colummns from apd1 will be NULL.
So far, so good.
Now, what happens if you follow that with
and apd1.adresse = a1.id The condition above means "include this row from apd1 only if there is matching row in a1". If apd1 is NULL, this condition will never be TRUE (even if a1.id is NULL).
When you do a cascading outer join like this, all columns in the distal table (the table farther away from the table that must be present) need to be marked with the + sign. That includes conditions involving a constant, like
and apd1.art (+) = 'Private' By the way, when posting code or results on this site, always type these 6 characters:
(small letters only, inside curly brackets) to preserve spacing and to keep some strings, such as the outer-join marker, form being interpreted as emoticons.
Edited by: Frank Kulash on Oct 1, 2009 6:37 AM
Added explanation -
How to Query from table and insert into another table.
Hi
I am using the following query in VO and all the columns are attached to EO ( table name emp_temp)
select a.npw_number, a.person_id,b.assignment_id,a.title,a.last_name,a.first_name,a.date_of_birth,a.sex,
b.organization_name,b.organization_id,b.job_id,b.job_name,b.position_id,b.position_name,b.supervisor_id,
b.supervisor_name,b.location_id,b.effective_start_date,b.effective_end_date
from per_all_people_f a,per_assignments_v b
where a.person_id=b.person_id
and a.npw_number=:1
I can query the data in screen. I need into insert the data into the emp_temp.
I don't know how to do this . Please help me.
Thanks
SubraYou can create a VO based on EO on emp_temp table.....
And u have attached a Different VO on the page... Right...
Now what u can do is....once u click on apply....
u can set the each attributes of EO based VO explicitly via code, from the values of second VO.... and then commit.....
Perhaps this might help... -
Need help with calc from tables
I have a table that contains query #1 and have another table
that contains a field that needs to use the result of the cfset in
another calc.
The new calc in query #2 needs to divide the Num_Checks_Trans
from query #1 by the by the Weekly_Hours_Recorded in query #2.
Can anyone help me figure this out?
<b>1.</b>
<cfquery name="QryEmployeeDetail"
datasource="NBProdReports">
SELECT TblContractInfo_SubMenuTable.User_ID,
TblContractInfo_SubMenuTable.Contract_Number,
TblContractInfo_SubMenuTable.Transaction_Type,
TblContractInfo_SubMenuTable.Num_Checks_Trans, TblTransType.Value,
TblContractInfo_SubMenuTable.Notes, TblMasterTrans.Date_Opened
from TblContractInfo_SubMenuTable, TblMasterTrans,
TblTransType
WHERE TblContractInfo_SubMenuTable.Task_Number =
TblMasterTrans.Task_Number
and TblTransType.Transaction_Type =
TblContractInfo_SubMenuTable.Transaction_Type
And TblMasterTrans.Date_Opened BETWEEN
#createODBCDate(DED_startDate)# AND #createODBCDate(DED_endDate)#
order BY TblMasterTrans.Date_Opened ASC,
TblContractInfo_SubMenuTable.User_id ASC
</cfquery>
<cfset totalTrans = 0 />
<cfloop query="QryEmployeeDetail">
<cfset totalTrans = totalTrans +
(QryEmployeeDetail.Num_Checks_Trans * QryEmployeeDetail.Value)
/></cfloop>
Text
2.
<cfquery name="QryEmployeeDetail"
datasource="NBProdReports">
SELECT TblContractInfo_SubMenuTable.User_ID,
TblContractInfo_SubMenuTable.Contract_Number,
TblContractInfo_SubMenuTable.Transaction_Type,
TblContractInfo_SubMenuTable.Num_Checks_Trans, TblTransType.Value,
TblContractInfo_SubMenuTable.Notes, TblMasterTrans.Date_Opened
from TblContractInfo_SubMenuTable, TblMasterTrans,
TblTransType
WHERE TblContractInfo_SubMenuTable.Task_Number =
TblMasterTrans.Task_Number
and TblTransType.Transaction_Type =
TblContractInfo_SubMenuTable.Transaction_Type
And TblMasterTrans.Date_Opened BETWEEN
#createODBCDate(DED_startDate)# AND #createODBCDate(DED_endDate)#
order BY TblMasterTrans.Date_Opened ASC,
TblContractInfo_SubMenuTable.User_id ASC
</cfquery>This can be rewritten as a single query which is good for a
number of reasons, including we only make one trip to the database
and we do our calculations on the SQL backend, which is faster than
doing them in CFML.
What you're going to want to do is SUM() the total
transaction values by having a column like SUM(Num_Checks_Trans *
Value) AS totalTrans. To get the value for your other column you
can calculate that like Num_Checks_Trans / Weekly_Hours_Recorded. I
didn't see the latter in either of your queries so I'm not sure
where it comes from, but you can definitely use it in your SELECT
clause when calculating.
Since SUM() is an aggregate function, you'll have to use a
GROUP BY clause to make it work. You'll have to GROUP BY each
column in the SELECT statement. If some of the columns have
differing data that you won't want to use in the GROUP, you can
always use a nested subquery as part of your FROM clause and then
join that to the original queries with the totals.
I hope that helps.
- William -
Fetch Insert / Update Query From Table Trigger
Hi everyone !,
I have a situation, is there any way where I can get insert/update query by before-insert / after insert trigger when a user inserts/updates any row in the table.
Plz....help me....champs.....
Regards,
NaushadThat was a nice thing but it works only on some oracle 9i with DML statements.
On database versions 9.2.0.1 to 9.2.0.6 ora_sql_text works and returns the calling text for dml triggers, where as starting from 9.2.0.7 the behavior has changed and returns NULL.
Cause
This issue had surfaced from 9.2.0.7.0 patchset. After discussions in Bug 4171597 which was closed as a duplicate of Bug 4230721 it was concluded that it was the expected behavior i.e ORA_SQL_TXT should return null when dml triggers are used.
ORA_SQL_TXT is a "System defined event attribute" and is supposed to work only with "System triggers". This is also what the Documentation says - "Application Developers Guide : Fundamentals(9.2)
Chapter 16 Working with System events".
Bye Alessandro -
Query from table a and insert to table b
Hi,
I would like to create an attendance page to record student's attendance on a particular dates.
I have 2 tables - students and attendance tables; in which attendance table will consist of PK from students table and date.
How do I create a form that display all the students record in a page with checkbox and date column; and when user check the boxes and click save; it will insert record into attendance table? Thanks!
Layout similar to the below:
Date: 1/1/2010 (user input)
Name: Attend
student 1 (checkbox)
student 2 (checkbox)
student 3 (checkbox)
student 4 (checkbox)
.....Hi Aaron,
For this you can do the following
1. Create a Tabular Form on The STUDENT table, i.e. the table you are using as a Fecth only table
2. Make the ApplyMRU and ApplyDRD process conditions Never so they will not be executed
3. Write your own custom process to write the checked rows into Attendence Table.
In the process you will have to refer to the checkbox f+nn+ item using APEX_APPLICATION.G_F+nn+ array and write from similar arrays for the other tabular form items
You will find useful code snippets in the Apex Help , Advanc3ed Tutorials as well as here http://www.oracle.com/technology/products/database/application_express/howtos/tabular_form.html#MANUAL
Regards, -
How to query from tables?
Hi!
I have two table, and I want to execute a query statement from them. How to do this?
Thanks so much!Hi,
If you go to otn.oracle.com/products/jdev you find tutorials and Oracle By Example (OBE) instructions.
These get you started
Frank -
PLS HELP CONVERT QUERY FROM UPDATE TO MERGE
Hi all,
Can you help me in converting this update statement into merge? I will really appreciate your help. Thanks
UPDATE dm_organizations tt
SET (cost_ctr_desc, cost_ctr_hier_lvl_1, cost_ctr_hier_lvl_2,
cost_ctr_hier_lvl_3, cost_ctr_hier_lvl_4, cost_ctr_hier_lvl_5, rgn_nm,
cntry_nm, load_date, update_date) =
(SELECT t.cost_ctr_desc, t.cost_ctr_hier_lvl_1,
t.cost_ctr_hier_lvl_2, t.cost_ctr_hier_lvl_3,
t.cost_ctr_hier_lvl_4, t.cost_ctr_hier_lvl_5, t.rgn_nm,
t.cntry_nm, t.load_date, SYSDATE
FROM dmi_cc_upload_stg t
WHERE t.run_id = 1831
AND t.status = 'Published'
AND t.cost_ctr_id = tt.cost_ctr_id
AND t.div_code = tt.div_code
AND t.fcn_code = tt.fcn_code
AND t.mkt_code = tt.mkt_code
AND t.corp_id = tt.corp_id
AND ROWNUM = 1)
WHERE EXISTS (
SELECT t.cost_ctr_desc, t.cost_ctr_hier_lvl_1,
t.cost_ctr_hier_lvl_2, t.cost_ctr_hier_lvl_3,
t.cost_ctr_hier_lvl_4, t.cost_ctr_hier_lvl_5, t.rgn_nm,
t.cntry_nm, t.load_date, SYSDATE
FROM dmi_cc_upload_stg t
WHERE t.run_id = 1831
AND t.status = 'Published'
AND t.cost_ctr_id = tt.cost_ctr_id
AND t.div_code = tt.div_code
AND t.fcn_code = tt.fcn_code
AND t.mkt_code = tt.mkt_code
AND t.corp_id = tt.corp_id);why not use existing UPDATE?
UPDATE dm_organizations tt
SET ( cost_ctr_desc, cost_ctr_hier_lvl_1, cost_ctr_hier_lvl_2,
cost_ctr_hier_lvl_3,
cost_ctr_hier_lvl_4, cost_ctr_hier_lvl_5, rgn_nm, cntry_nm,
load_date, update_date ) = (SELECT t.cost_ctr_desc,
t.cost_ctr_hier_lvl_1,
t.cost_ctr_hier_lvl_2,
t.cost_ctr_hier_lvl_3,
t.cost_ctr_hier_lvl_4,
t.cost_ctr_hier_lvl_5,
t.rgn_nm,
t.cntry_nm,
t.load_date,
SYSDATE
FROM dmi_cc_upload_stg t
WHERE t.run_id = 1831
AND t.status = 'Published'
AND t.cost_ctr_id = tt.cost_ctr_id
AND t.div_code = tt.div_code
AND t.fcn_code = tt.fcn_code
AND t.mkt_code = tt.mkt_code
AND t.corp_id = tt.corp_id
AND ROWNUM = 1)
WHERE EXISTS (SELECT t.cost_ctr_desc,
t.cost_ctr_hier_lvl_1,
t.cost_ctr_hier_lvl_2,
t.cost_ctr_hier_lvl_3,
t.cost_ctr_hier_lvl_4,
t.cost_ctr_hier_lvl_5,
t.rgn_nm,
t.cntry_nm,
t.load_date,
SYSDATE
FROM dmi_cc_upload_stg t
WHERE t.run_id = 1831
AND t.status = 'Published'
AND t.cost_ctr_id = tt.cost_ctr_id
AND t.div_code = tt.div_code
AND t.fcn_code = tt.fcn_code
AND t.mkt_code = tt.mkt_code
AND t.corp_id = tt.corp_id); -
Help with query to return results from group within table?
Hi
Im a total noob, so please be gentle....!
I am looking at a table that has a WORD column and a WORD_TYPE_ID column.
Words can have the same type_id.
What I am trying to do is write a query that will return the longest word for each word_type_id.
I have been trying for hours to get this and all I seem to get is either error messages or I return the longest word in the whole WORD column.
The furthest I can get before things break down is.....
select word
from table
where
length(word) =
select
max(length(word))
from table
Any help on this or if I could be pointed in the right direction it would be greatly appreciated.
ThanksHi,
Welcome to the forum!
Here's one way:
SELECT word_type_id
, MIN (word) KEEP (DENSE_RANK LAST ORDDER BY LENGTH (word)) AS longest_word
FROM table_x
GROUP BY word_type_id;If there happens to be a tie within some word_type_id (that is, 2 or more words have exactly the same length, which is the longest in that group) the expression above will return the first one, in alphabetic order. (That's what MIN means here.)
Edited by: Frank Kulash on Aug 11, 2009 1:56 PM
You almost had it.
As you noticed, you were getting the longest row in the whole table. That's because your sub-query was looking at the whole table.
If you correlate the sub-query to the row in the main table, as shown below, you can get the longest word in each group:
select word
from table m -- m for main
where length (word) = (
select max (length(word))
from table
where word_type_id = m.word_type_id -- New
); -
Query to return list of all missing primary key ids from table T1
I found this query online that returns a start and stop for a range of all missing primary key id values from table T1. However i want to rewrite this query to return a whole list of all the missing primary key ids and not a start and stop range. any help plz?
select strt, stp
from (select m.id + 1 as strt,
(select min(id) - 1 from T1 x where x.id > m.id) as stp
from T1 m left outer join T1 r on m.id = r.id - 1 where r.id is null)x where stp is not nullwith t as
select 1 as id from dual union all
select 2 as id from dual union all
select 3 as id from dual union all
select 5 as id from dual union all
select 8 as id from dual union all
select 10 as id from dual union all
select 11 as id from dual union all
select 20 as id from dual
select id_start + level missing_id
from (
select id id_start,
nullif(lead(id) over(order by id) - 1, id) id_end
from t
start with id_end is not null
connect by prior id_start = id_start
and prior dbms_random.random is not null
and level <= id_end - id_start
MISSING_ID
4
6
7
9
12
13
14
15
16
17
18
MISSING_ID
19
12 rows selected.Or:
with t as
select 1 as id from dual union all
select 2 as id from dual union all
select 3 as id from dual union all
select 5 as id from dual union all
select 8 as id from dual union all
select 10 as id from dual union all
select 11 as id from dual union all
select 20 as id from dual
select id_start + level - 1 missing_id
from (
select min(id) id_start,
max(id) id_end
from t
connect by level <= id_end - id_start
minus
select id
from t
MISSING_ID
4
6
7
9
12
13
14
15
16
17
18
MISSING_ID
19
12 rows selected.SY. -
Pagination query help needed for large table - force a different index
I'm using a slight modification of the pagination query from over at Ask Tom's: [http://www.oracle.com/technology/oramag/oracle/07-jan/o17asktom.html]
Mine looks like this when fetching the first 100 rows of all members with last name Smith, ordered by join date:
SELECT members.*
FROM members,
SELECT RID, rownum rnum
FROM
SELECT rowid as RID
FROM members
WHERE last_name = 'Smith'
ORDER BY joindate
WHERE rownum <= 100
WHERE rnum >= 1
and RID = members.rowidThe difference between this and the one at Ask Tom's is that my innermost query just returns the ROWID. Then in the outermost query we join the ROWIDs returned to the members table, after we have pruned the ROWIDs down to only the chunk of 100 we want. This makes it MUCH faster (verifiably) on our large tables, as it is able to use the index on the innermost query (well... read on).
The problem I have is this:
SELECT rowid as RID
FROM members
WHERE last_name = 'Smith'
ORDER BY joindateThis will use the index for the predicate column (last_name) instead of the unique index I have defined for the joindate column (joindate, sequence). (Verifiable with explain plan). It is much slower this way on a large table. So I can hint it using either of the following methods:
SELECT /*+ index(members, joindate_idx) */ rowid as RID
FROM members
WHERE last_name = 'Smith'
ORDER BY joindate
SELECT /*+ first_rows(100) */ rowid as RID
FROM members
WHERE last_name = 'Smith'
ORDER BY joindateEither way, it now uses the index of the ORDER BY column (joindate_idx), so now it is much faster as it does not have to do a sort (remember, VERY large table, millions of records). So that seems good. But now, on my outermost query, I join the rowid with the meaningful columns of data from the members table, as commented below:
SELECT members.* -- Select all data from members table
FROM members, -- members table added to FROM clause
SELECT RID, rownum rnum
FROM
SELECT /*+ index(members, joindate_idx) */ rowid as RID -- Hint is ignored now that I am joining in the outer query
FROM members
WHERE last_name = 'Smith'
ORDER BY joindate
WHERE rownum <= 100
WHERE rnum >= 1
and RID = members.rowid -- Merge the members table on the rowid we pulled from the inner queriesOnce I do this join, it goes back to using the predicate index (last_name) and has to perform the sort once it finds all matching values (which can be a lot in this table, there is high cardinality on some columns).
So my question is, in the full query above, is there any way I can get it to use the ORDER BY column for indexing to prevent it from having to do a sort? The join is what causes it to revert back to using the predicate index, even with hints. Remove the join and just return the ROWIDs for those 100 records and it flies, even on 10 million records.
It'd be great if there was some generic hint that could accomplish this, such that if we change the table/columns/indexes, we don't need to change the hint (the FIRST_ROWS hint is a good example of this, while the INDEX hint is the opposite), but any help would be appreciated. I can provide explain plans for any of the above if needed.
Thanks!Lakmal Rajapakse wrote:
OK here is an example to illustrate the advantage:
SQL> set autot traceonly
SQL> select * from (
2 select a.*, rownum x from
3 (
4 select a.* from aoswf.events a
5 order by EVENT_DATETIME
6 ) a
7 where rownum <= 1200
8 )
9 where x >= 1100
10 /
101 rows selected.
Execution Plan
Plan hash value: 3711662397
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 521K| 192 (0)| 00:00:03 |
|* 1 | VIEW | | 1200 | 521K| 192 (0)| 00:00:03 |
|* 2 | COUNT STOPKEY | | | | | |
| 3 | VIEW | | 1200 | 506K| 192 (0)| 00:00:03 |
| 4 | TABLE ACCESS BY INDEX ROWID| EVENTS | 253M| 34G| 192 (0)| 00:00:03 |
| 5 | INDEX FULL SCAN | EVEN_IDX02 | 1200 | | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("X">=1100)
2 - filter(ROWNUM<=1200)
Statistics
0 recursive calls
0 db block gets
443 consistent gets
0 physical reads
0 redo size
25203 bytes sent via SQL*Net to client
281 bytes received via SQL*Net from client
8 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
101 rows processed
SQL>
SQL>
SQL> select * from aoswf.events a, (
2 select rid, rownum x from
3 (
4 select rowid rid from aoswf.events a
5 order by EVENT_DATETIME
6 ) a
7 where rownum <= 1200
8 ) b
9 where x >= 1100
10 and a.rowid = rid
11 /
101 rows selected.
Execution Plan
Plan hash value: 2308864810
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 201K| 261K (1)| 00:52:21 |
| 1 | NESTED LOOPS | | 1200 | 201K| 261K (1)| 00:52:21 |
|* 2 | VIEW | | 1200 | 30000 | 260K (1)| 00:52:06 |
|* 3 | COUNT STOPKEY | | | | | |
| 4 | VIEW | | 253M| 2895M| 260K (1)| 00:52:06 |
| 5 | INDEX FULL SCAN | EVEN_IDX02 | 253M| 4826M| 260K (1)| 00:52:06 |
| 6 | TABLE ACCESS BY USER ROWID| EVENTS | 1 | 147 | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - filter("X">=1100)
3 - filter(ROWNUM<=1200)
Statistics
8 recursive calls
0 db block gets
117 consistent gets
0 physical reads
0 redo size
27539 bytes sent via SQL*Net to client
281 bytes received via SQL*Net from client
8 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
101 rows processed
Lakmal (and OP),
Not sure what advantage you are trying to show here. But considering that we are talking about pagination query here and order of records is important, your 2 queries will not always generate output in same order. Here is the test case:
SQL> select * from v$version ;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> show parameter optimizer
NAME TYPE VALUE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 10.2.0.1
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
SQL> show parameter pga
NAME TYPE VALUE
pga_aggregate_target big integer 103M
SQL> create table t nologging as select * from all_objects where 1 = 2 ;
Table created.
SQL> create index t_idx on t(last_ddl_time) nologging ;
Index created.
SQL> insert /*+ APPEND */ into t (owner, object_name, object_id, created, last_ddl_time) select owner, object_name, object_id, created, sysdate - dbms_random.value(1, 100) from all_objects order by dbms_random.random;
40617 rows created.
SQL> commit ;
Commit complete.
SQL> exec dbms_stats.gather_table_stats(user, 'T', cascade=>true);
PL/SQL procedure successfully completed.
SQL> select object_id, object_name, created from t, (select rid, rownum rn from (select rowid rid from t order by created desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid ;
OBJECT_ID OBJECT_NAME CREATED
47686 ALL$OLAP2_JOIN_KEY_COLUMN_USES 28-JUL-2009 08:08:39
47672 ALL$OLAP2_CUBE_DIM_USES 28-JUL-2009 08:08:39
47681 ALL$OLAP2_CUBE_MEASURE_MAPS 28-JUL-2009 08:08:39
47682 ALL$OLAP2_FACT_LEVEL_USES 28-JUL-2009 08:08:39
47685 ALL$OLAP2_AGGREGATION_USES 28-JUL-2009 08:08:39
47692 ALL$OLAP2_CATALOGS 28-JUL-2009 08:08:39
47665 ALL$OLAPMR_FACTTBLKEYMAPS 28-JUL-2009 08:08:39
47688 ALL$OLAP2_DIM_LEVEL_ATTR_MAPS 28-JUL-2009 08:08:39
47689 ALL$OLAP2_DIM_LEVELS_KEYMAPS 28-JUL-2009 08:08:39
47669 ALL$OLAP9I2_HIER_DIMENSIONS 28-JUL-2009 08:08:39
47666 ALL$OLAP9I1_HIER_DIMENSIONS 28-JUL-2009 08:08:39
11 rows selected.
SQL> select object_id, object_name, last_ddl_time from t, (select rid, rownum rn from (select rowid rid from t order by last_ddl_time desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid ;
OBJECT_ID OBJECT_NAME LAST_DDL_TIME
11749 /b9fe5b99_OraRTStatementComman 06-FEB-2010 03:43:49
13133 oracle/jdbc/driver/OracleLog$3 06-FEB-2010 03:45:44
37534 com/sun/mail/smtp/SMTPMessage 06-FEB-2010 03:46:14
36145 /4e492b6f_SerProfileToClassErr 06-FEB-2010 03:11:09
26815 /7a628fb8_DefaultHSBChooserPan 06-FEB-2010 03:26:55
16695 /2940a364_RepIdDelegator_1_3 06-FEB-2010 03:38:17
36539 sun/io/ByteToCharMacHebrew 06-FEB-2010 03:28:57
14044 /d29b81e1_OldHeaders 06-FEB-2010 03:12:12
12920 /25f8f3a5_BasicSplitPaneUI 06-FEB-2010 03:11:06
42266 SI_GETCLRHSTGRFTR 06-FEB-2010 03:40:20
15752 /2f494dce_JDWPThreadReference 06-FEB-2010 03:09:31
11 rows selected.
SQL> select object_id, object_name, last_ddl_time from (select t1.*, rownum rn from (select * from t order by last_ddl_time desc) t1 where rownum <= 1200) where rn >= 1190 ;
OBJECT_ID OBJECT_NAME LAST_DDL_TIME
37534 com/sun/mail/smtp/SMTPMessage 06-FEB-2010 03:46:14
13133 oracle/jdbc/driver/OracleLog$3 06-FEB-2010 03:45:44
11749 /b9fe5b99_OraRTStatementComman 06-FEB-2010 03:43:49
42266 SI_GETCLRHSTGRFTR 06-FEB-2010 03:40:20
16695 /2940a364_RepIdDelegator_1_3 06-FEB-2010 03:38:17
36539 sun/io/ByteToCharMacHebrew 06-FEB-2010 03:28:57
26815 /7a628fb8_DefaultHSBChooserPan 06-FEB-2010 03:26:55
14044 /d29b81e1_OldHeaders 06-FEB-2010 03:12:12
36145 /4e492b6f_SerProfileToClassErr 06-FEB-2010 03:11:09
12920 /25f8f3a5_BasicSplitPaneUI 06-FEB-2010 03:11:06
15752 /2f494dce_JDWPThreadReference 06-FEB-2010 03:09:31
11 rows selected.
SQL> select object_id, object_name, last_ddl_time from t, (select rid, rownum rn from (select rowid rid from t order by last_ddl_time desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid order by last_ddl_time desc ;
OBJECT_ID OBJECT_NAME LAST_DDL_TIME
37534 com/sun/mail/smtp/SMTPMessage 06-FEB-2010 03:46:14
13133 oracle/jdbc/driver/OracleLog$3 06-FEB-2010 03:45:44
11749 /b9fe5b99_OraRTStatementComman 06-FEB-2010 03:43:49
42266 SI_GETCLRHSTGRFTR 06-FEB-2010 03:40:20
16695 /2940a364_RepIdDelegator_1_3 06-FEB-2010 03:38:17
36539 sun/io/ByteToCharMacHebrew 06-FEB-2010 03:28:57
26815 /7a628fb8_DefaultHSBChooserPan 06-FEB-2010 03:26:55
14044 /d29b81e1_OldHeaders 06-FEB-2010 03:12:12
36145 /4e492b6f_SerProfileToClassErr 06-FEB-2010 03:11:09
12920 /25f8f3a5_BasicSplitPaneUI 06-FEB-2010 03:11:06
15752 /2f494dce_JDWPThreadReference 06-FEB-2010 03:09:31
11 rows selected.
SQL> set autotrace traceonly
SQL> select object_id, object_name, last_ddl_time from t, (select rid, rownum rn from (select rowid rid from t order by last_ddl_time desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid order by last_ddl_time desc
2 ;
11 rows selected.
Execution Plan
Plan hash value: 44968669
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 91200 | 180 (2)| 00:00:03 |
| 1 | SORT ORDER BY | | 1200 | 91200 | 180 (2)| 00:00:03 |
|* 2 | HASH JOIN | | 1200 | 91200 | 179 (2)| 00:00:03 |
|* 3 | VIEW | | 1200 | 30000 | 98 (0)| 00:00:02 |
|* 4 | COUNT STOPKEY | | | | | |
| 5 | VIEW | | 40617 | 475K| 98 (0)| 00:00:02 |
| 6 | INDEX FULL SCAN DESCENDING| T_IDX | 40617 | 793K| 98 (0)| 00:00:02 |
| 7 | TABLE ACCESS FULL | T | 40617 | 2022K| 80 (2)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("T".ROWID="T1"."RID")
3 - filter("RN">=1190)
4 - filter(ROWNUM<=1200)
Statistics
1 recursive calls
0 db block gets
348 consistent gets
0 physical reads
0 redo size
1063 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
11 rows processed
SQL> select object_id, object_name, last_ddl_time from (select t1.*, rownum rn from (select * from t order by last_ddl_time desc) t1 where rownum <= 1200) where rn >= 1190 ;
11 rows selected.
Execution Plan
Plan hash value: 882605040
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 62400 | 80 (2)| 00:00:01 |
|* 1 | VIEW | | 1200 | 62400 | 80 (2)| 00:00:01 |
|* 2 | COUNT STOPKEY | | | | | |
| 3 | VIEW | | 40617 | 1546K| 80 (2)| 00:00:01 |
|* 4 | SORT ORDER BY STOPKEY| | 40617 | 2062K| 80 (2)| 00:00:01 |
| 5 | TABLE ACCESS FULL | T | 40617 | 2062K| 80 (2)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("RN">=1190)
2 - filter(ROWNUM<=1200)
4 - filter(ROWNUM<=1200)
Statistics
0 recursive calls
0 db block gets
343 consistent gets
0 physical reads
0 redo size
1063 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
11 rows processed
SQL> select object_id, object_name, last_ddl_time from t, (select rid, rownum rn from (select rowid rid from t order by last_ddl_time desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid ;
11 rows selected.
Execution Plan
Plan hash value: 168880862
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 91200 | 179 (2)| 00:00:03 |
|* 1 | HASH JOIN | | 1200 | 91200 | 179 (2)| 00:00:03 |
|* 2 | VIEW | | 1200 | 30000 | 98 (0)| 00:00:02 |
|* 3 | COUNT STOPKEY | | | | | |
| 4 | VIEW | | 40617 | 475K| 98 (0)| 00:00:02 |
| 5 | INDEX FULL SCAN DESCENDING| T_IDX | 40617 | 793K| 98 (0)| 00:00:02 |
| 6 | TABLE ACCESS FULL | T | 40617 | 2022K| 80 (2)| 00:00:01 |
Predicate Information (identified by operation id):
1 - access("T".ROWID="T1"."RID")
2 - filter("RN">=1190)
3 - filter(ROWNUM<=1200)
Statistics
0 recursive calls
0 db block gets
349 consistent gets
0 physical reads
0 redo size
1063 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
11 rows processed
SQL> select object_id, object_name, last_ddl_time from (select t1.*, rownum rn from (select * from t order by last_ddl_time desc) t1 where rownum <= 1200) where rn >= 1190 order by last_ddl_time desc ;
11 rows selected.
Execution Plan
Plan hash value: 882605040
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 62400 | 80 (2)| 00:00:01 |
|* 1 | VIEW | | 1200 | 62400 | 80 (2)| 00:00:01 |
|* 2 | COUNT STOPKEY | | | | | |
| 3 | VIEW | | 40617 | 1546K| 80 (2)| 00:00:01 |
|* 4 | SORT ORDER BY STOPKEY| | 40617 | 2062K| 80 (2)| 00:00:01 |
| 5 | TABLE ACCESS FULL | T | 40617 | 2062K| 80 (2)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("RN">=1190)
2 - filter(ROWNUM<=1200)
4 - filter(ROWNUM<=1200)
Statistics
175 recursive calls
0 db block gets
388 consistent gets
0 physical reads
0 redo size
1063 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
4 sorts (memory)
0 sorts (disk)
11 rows processed
SQL> set autotrace off
SQL> spool offAs you will see, the join query here has to have an ORDER BY clause at the end to ensure that records are correctly sorted. You can not rely on optimizer choosing NESTED LOOP join method and, as above example shows, when optimizer chooses HASH JOIN, oracle is free to return rows in no particular order.
The query that does not involve join always returns rows in the desired order. Adding an ORDER BY does add a step in the plan for the query using join but does not affect the other query. -
SAP Query - Additional field that collects information from table RESB
Hello gurus. I have a question.
I want to create a SAP Query that shows me the stock level of a list of materials, and also show me the total quantity of order reservations in an additional field.
I created an InfoSet with table MARD, which is the one that holds the Stock information in a plant. Then I created an additional field which would read information from table RESB, the table that holds order reservations per material.
So I wrote this piece of code:
SELECT * FROM RESB
WHERE MATNR EQ MARD-MATNR and
WERKS EQ MARD-WERKS.
ENDSELECT.
if ( sy-dbcnt NE '0').
MOVE RESB-BDMNG to ZQTY.
ELSE.
MOVE '' to ZQTY.
ENDIF.
This works fine. However, this is currently just catching the first record in table RESB that matches my condition.
What I would like is to collect every instance of RESB-BDMNG and add them to field "ZQTY", have it loop in RESB until it finishes finding every record that match the MATNR and WERKS. With this I could get the total number of order reservations that this material has in that table.
Could someone share some coding that would help me achieve this?Yes! That did it. That's what I needed to do. Thank you so much.
While I'm at it, let me ask you a related question.
When I execute the query, in the first records of the query where there's no value from RESB to transfer, the value of field ZQTY appears empty. Once it finds the first record in RESB and it populates ZQTY with a value, then the rest of the records with no hit get the proper value of 0.
Do you know why the first records in the query appear empty and not with a 0? Is there anything I should add to the coding to fix this?
Maybe you are looking for
-
DO I GET AN AWARD FOR THIS??? WORST DELIVERY EVER???
Hold on to your hats, because this one is a doozy, and I've worked in Warehouse Supervisor for many years, and worked closely with Customer/Client services for a large computer company, so I couldn't even believe the insanity that would follow. It’s
-
IMessage sent from iPad to iPhone never reaches destination
Just tried to send a test iMessage from my iPad iOS5 to my iPhone 4GS, and it doesn't seem to reach the phone even tho the iPad reports it as "delivered". Anyone else experience this?
-
Returning content type of application/RFC822
I have a servlet which needs to return a data stream that the browser shoule save as a file on the users local hard drive. My servlet seems to work just fine with Netscape 4.7 but IE always saves the original HTML Form p
-
Calling Stored procedure from portal report
I have a simple portal report. ie. select empname from emp where dept = :dept The users can customize the portlet and change the value of the bind variable (:dept). On the Additional PL/SQL section of the report I need to call a procedure and pass th
-
Background in table load delay, or slow load
I just put together this page and things are working pretty well, but I'm not happy with how the background image loads last. First you see the text on the screen, and then you see the image load in from top to bottom. The image is only 96kb, so it s