Howto: SQL query to obtain latest n rows
Hey everyone,
I want to query a subset of a table to return, at most, a certain number of rows. The problem is that 'rowcnt' is not going to be good enough. Here's the situation:
I have a table with lots of data (15 days worth). It will accumulate over time, but I want to extract, say, only the last 10 rows that were placed into the table. That would be simple, but there is one other catch, there is a key column and I may want to select rows from each "key". So a simple row count won't work :(.
Here's a sample table:
key varchar(10)
val1 varchar(5)
val2 varchar(5)
epoch_time number(30)Now, this would ALMOST work:
select key, val1, val2, epoch_time from t where key='KEYVAL1' and rowcnt <= 10 order by epoch_time desc;
Because the decending sort on epoch_time guarentees that the latest 10 rows will be returned. The problem arises when I want this:
select key, val1, val2, epoch_time from t where key IN ('KEYVAL1', 'KEYVAL2') and rowcnt <= 10 order by epoch_time desc;
I intend to get 10 rows (or less) returned for each 'KEYVAL1' and 'KEYVAL2', but since rowcnt is a global count of rows returned this obviously won't work as desired.
Keep in mind that I could have 5 rows, 10 rows, 1000 rows for a key...so I could be selecting three keys, one with 5 rows, the next with 40 and the next with 7. Therefore, if I did something like assume I'll get back 30 rows (10 per key) this situtation would render that solution invalid because I'd get 5 from the first and 25 from the second and none from the 3rd.
So, the actual question is, can I make some modification to the above query such that I can get the last 10 rows from both 'KEYVAL1' and 'KEYVAL2'. Possibly changing the order by clause to order by both key and epoch_time and then somehow switching the rowcnt to a value that would be capable of returning itself to 0 upon encountering a new key value?? I think I could do this with PL/SQL, but I'd have to use a static value to hold the row count and last passed key value, and that wouldn't work if more than one query executed at once unless there were some kind of "query specific data" (analogous to thread specific data) that I could utilize.
If not, I guess I'll have to write a PL/SQL routine to simulate the entire query because I can't use unions (at least I don't think I can) because I have to be capable of using an IN list to determine the key values I desire.
If anyone has a suggestion, I'd really appreciate it. THANKS!
Brian Gregg
Computer Sciences Corp.
Are you running with 8.1.6 Enterprise Edition or higher? If so, you can solve your problem with Analytic functions, specifically RANK() or DENSE_RANK().
SELECT * FROM
( SELECT key, val1, val2, epoch_time,
DENSE_RANK() OVER (PARTITION BY key ORDER BY epoch_time DESC) AS ep_rank
FROM t
WHERE key IN ('KEYVAL1', 'KEYVAL2')
) WHERE ep_rank <= 10;Caveat: this code is typed without benefit of database so you may need to check the syntax.
Cheers, APC
Similar Messages
-
I just wanted to note this on the forum..
I'm using Apex 3.0.1.00.08
My DEV environment has just been upgraded from 10g version 10.2.0.2.0 to 10.2.0.4.0.
I created the following process to select some values into some items on my Form page.
select MAX(STAT_YEAR+1)
, pcd.pct_id
, pcd.stat_type_id
, pcd.stat_period_type_id
, pcd.measurement_id
into :P11_STAT_YEAR
, :P11_PCT_ID
, :P11_STAT_TYPE_ID
, :P11_STAT_PERIOD_TYPE_ID
, :P11_MEASUREMENT_ID
from plant_commodity_data pcd
, stat_type stt
where pcd.STAT_TYPE_ID = stt.STAT_TYPE_ID
and pcd.pct_id = :P0_PCT_ID
and stt.stat_type = 'PRD'
group by pcd.pct_id
, pcd.stat_type_id
, pcd.stat_period_type_id
, pcd.measurement_id;The process should run conditionally if there was at least one row to select...
So I copied the SQL into the Process condition, removed the "into" section and set the condition type to be "Exists (SQL query retruns at least one row) ...
select MAX(STAT_YEAR+1)
, pcd.pct_id
, pcd.stat_type_id
, pcd.stat_period_type_id
, pcd.measurement_id
from plant_commodity_data pcd
, stat_type stt
where pcd.STAT_TYPE_ID = stt.STAT_TYPE_ID
and pcd.pct_id = :P0_PCT_ID
and stt.stat_type = 'PRD'
group by pcd.pct_id
, pcd.stat_type_id
, pcd.stat_period_type_id
, pcd.measurement_id;This worked perfectly until the DEV environment was upgraded from 10g version 10.2.0.2.0 to 10.2.0.4.0.
The condition would fire even if there were no rows returning.
I pasted the condition code into SQL Developer connected to the DEV (10.2.0.4.0) environment and it returned no rows.
To solve the problem, I removed the MAX.
You can test this using this code if you have access to the two versions... select MAX(1)
, sysdate
, 'Gus'
from dual
where 1 = 2
group by sysdate, 2Now I know the MAX isn't required in the condition as I'm just trying to find out if any rows exist, but it was there as I copied the code in... I was just wondering why this happened between 10.2.0.2.0 and 10.2.0.4.0?
Gus..Hi Gus,
try to execute
select count(*) from dual where exists (select MAX(1)
, sysdate
, 'Gus'
from dual
where 1 = 2
group by sysdate, 2)in SQL Developer. The above statement is generated by APEX for an "Exists (SQL query retruns at least one row)". Can't test it, because I don't have a 10.2.0.4.0 at hand.
Does SQL Developer now show the same behavior?
Patrick
My APEX Blog: http://www.inside-oracle-apex.com
The APEX Builder Plugin: http://builderplugin.oracleapex.info/
The ApexLib Framework: http://apexlib.sourceforge.net/ -
SQL Query (PL/SQL Function Body returning SQL query) doesn't return any row
I have a region with the following type:
SQL Query (PL/SQL Function Body returning SQL query).
In a search screen the users can enter different numbers, separated by an ENTER.
I want to check these numbers by replacing the ENTER, which is CHR(13) || CHR(10) I believe, with commas. And then I can use it like this: POD IN (<<text>>).
It's something like this:
If (:P30_POD Is Not Null) Then
v_where := v_where || v_condition || 'POD IN (''''''''||REPLACE(''' || :P30_POD || ''', CHR(13) || CHR(10), '','')||'''''''''')';
v_condition := ' AND ';
End If;
But the query doesn't return any rows.
I tried to reproduce it in Toad:
select * from asx_worklistitem
where
POD IN (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
==> This is the query that does't return any rows
select (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
from dual;
==> This returns '541449200000171813','541449206006341366'
select * from asx_worklistitem
where pod in ('541449200000171813','541449206006341366');
==> and when I copy/paste this in the above query, it does return my rows.
So why does my first query doesn't work?
Doe anyone have any idea?
Kind regards,
Geert
Message was edited by:
ZorryThanks for the help.
I made it work, but via the following code:
If (:P30_POD Is Not Null) Then
v_pods := REPLACE(:P30_POD, CHR(13) || CHR(10));
v_where := v_where || v_condition || 'POD IN (';
v_counter := 1;
WHILE (v_counter < LENGTH(v_pods)) LOOP
v_pod := SUBSTR(v_pods, v_counter, 18);
IF (v_counter <> 1) THEN
v_where := v_where || ',';
END IF;
v_where := v_where || '''' || v_pod || '''';
v_counter := v_counter + 18;
END LOOP;
v_where := v_where || ')';
v_condition := ' AND ';
End If;But now I want to make an update of all the records that correspond to this search criteria. I can give in a status via a dropdownlist and that I want to update all the records that correspond to one of these POD's with that status.
For a region you can build an SQL query via PL/SQL, but for a process you only have a PL/SQL block. Is the only way to update all these records by making a loop and make an update for every POD that is specified.
Because I think this will have a lot of overhead.
I would like to make something like a multi row update in an updateable report, but I want to specify the status from somewhere else. Is this possible? -
SQL query to fetch approximately 9000 rows
Hi,
I am using the following SQL query in a java class. Using JDBC to connect to an Oracle database using JRUN app server connection pooling.
SELECT PT.ACCOUNT_NUMBER,PAYMENT_REF_ID, TO_CHAR (PT.DATE_CREATED, 'MM/DD/YYYY'),
PT.AMOUNT_PAID, DECODE(STATUS_VALUE,'Cancelled','Canceled',STATUS_VALUE)
FROM EPAY_PAYMENT_TRANSACTIONS PT, EPAY_STATUS_LOOKUP SL
WHERE
PT.CLIENT_NAME = 'someclientname'
AND TO_CHAR(DATE_PAYMENT_SCHEDULED,'MM/DD/YYYY') = '08/28/2006'
AND PT.PAYMENT_STATUS = SL.STATUS_CODE
ORDER BY PT.DATE_CREATED DESC
EPAY_PAYMENT_TRANSACTIONS is a huge table consisting of thousands of rows. There are 4 indexes defined on this table but not on the columns used in the join condition of the query.
EPAY_STATUS_LOOKUP is a much smaller table mainly used for lookup consisting of some 100 rows.
The above query fetches approx 9000 records and takes a very long time to execute. Is there any way it can be optimized or we can change some attributes on the tables involved for speeding up the query?
Thanks in advance,
Nisha.So the task is to avoid FTS on EPAY_PAYMENT_TRANSACTIONSWell, maybe...
But I believe that we have yet to hear more details about data distribution, execution plans and so on.
Because it all depends...
Consider simple testcase:
SQL> select * from v$version where rownum = 1;
BANNER
Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
SQL> -- Create "small" table
SQL>
SQL> create table build_t as
2 select rownum x,
3 rpad('*', 200, '*') padding
4 from dual
5 connect by level <= 100;
Table created.
SQL> -- Create "large" table - initially, add 9000 rows which satisfy join criteria
SQL>
SQL> create table probe_t as
2 select mod(rownum - 1, 100) + 1 x,
3 dbms_random.value y,
4 rpad('*', 200, '*') padding
5 from dual
6 connect by level <= 9000;
Table created.
SQL> -- Now, add some extra rows to large table - "thousands of rows"
SQL>
SQL> insert into probe_t
2 select rownum + 100,
3 0,
4 rpad('*', 200, '*') padding
5 from dual
6 connect by level <= 100000;
100000 rows created.
SQL> exec dbms_stats.gather_table_stats(user, 'BUILD_T')
PL/SQL procedure successfully completed.
SQL> exec dbms_stats.gather_table_stats(user, 'PROBE_T')
PL/SQL procedure successfully completed.
SQL> -- Ok, let's measure ...
SQL>
SQL> set autot traceonly
SQL>
SQL> select a.*, b.*
2 from build_t a,
3 probe_t b
4 where a.x = b.x
5 order by b.y;
9000 rows selected.
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1387 Card=109 Bytes=45017)
1 0 SORT (ORDER BY) (Cost=1387 Card=109 Bytes=45017)
2 1 HASH JOIN (Cost=1386 Card=109 Bytes=45017)
3 2 TABLE ACCESS (FULL) OF 'BUILD_T' (Cost=5 Card=100 Bytes=20400)
4 2 TABLE ACCESS (FULL) OF 'PROBE_T' (Cost=1355 Card=109000 Bytes=22781000)
Statistics
0 recursive calls
0 db block gets
3280 consistent gets
0 physical reads
0 redo size
360756 bytes sent via SQL*Net to client
7096 bytes received via SQL*Net from client
601 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
9000 rows processedOn my server, this query finished in less that second and took 3280 LIO to complete.
Now, which index did you mean to build? I guess it's and index on join column, isn't it?
If so - let's build it and measure again:
SQL> create index idx_probe_t on probe_t(x);
Index created.
SQL> select /*+ ORDERED USE_NL(a b) */
2 a.*, b.*
3 from build_t a,
4 probe_t b
5 where a.x = b.x
6 order by b.y;
9000 rows selected.
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=211 Card=109 Bytes=45017)
1 0 SORT (ORDER BY) (Cost=211 Card=109 Bytes=45017)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'PROBE_T' (Cost=3 Card=1 Bytes=209)
3 2 NESTED LOOPS (Cost=210 Card=109 Bytes=45017)
4 3 TABLE ACCESS (FULL) OF 'BUILD_T' (Cost=5 Card=100 Bytes=20400)
5 3 INDEX (RANGE SCAN) OF 'IDX_PROBE_T' (NON-UNIQUE) (Cost=2 Card=1)
Statistics
0 recursive calls
0 db block gets
9124 consistent gets
21 physical reads
0 redo size
360756 bytes sent via SQL*Net to client
7096 bytes received via SQL*Net from client
601 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
9000 rows processedLook at this - 9124 consistent gets, almost three times larger than in case of hash join.
Full table scan is not something to be avoided at all cost.
Indexing - sometimes it is good,
sometimes it's just useless,
sometimes it only makes things worse...
It all depends on underlying data distribution. That's why I asked user527580 to tell us more.
Kind regards. -
SQL Query of an OWB map (row based)
If I trace a session, execute an OWB map (row based), will the trace file contain the actual SQL query ?
The problem with me is that when I am executing this row -based OWB map, it is throwing me an error CursorFetchMapTerminationRTV20007 BUT ( plus taking a long time) when I am taking out the intermediate SQL insert query,it is working fine ( and also within a very short period of time)
Execution status = COMPLETE
message text = ORA-06502: PL/SQL: numeric or value error: character string buffer too small
message text = CursorFetchMapTerminationRTV20007
No. task errors = 0
No. task warnings = 2
No. errors = 1
Since this OWB map (Truncate Insert) is row based hence I cannot cannot get the back end query from the OWB generated pl/sql package so wondering if I trace the session, check the trace file, may be I will able to see the exact SQL query generated. But wanted to confirm the same.Yes, the actual SQL run in the session will be in the trace file.
-
Need Sql Query that Suppress the repeating rows.
Hi Sir,
I have below data set.
DeptID Sum(SAL) Avg(Sal)
10 1300 1300
10 2450 1300
10 5000 1300
20 800 800
20 1100 800
20 2975 800
20 3000 800
30 800 800
30 1100 800
30 2975 800
40 3000 800
40 4000 900
I Need SQL query that can remove the duplicate or suppress.Just like below data set.
Output:
DeptID Sum(SAL) Avg(Sal)
10 1300 1300
2450 1300
5000 1300
20 800 800
1100 800
2975 800
3000 800
800 800
30 1100 800
2975 800
40 3000 800
4000 900
Could you please help me on this..Your requiremnt is more of a reporting request which should not be handled in SQL. For example in SQL Plus you can use the BREAK command
SQL> break on deptno
SQL> select deptno, ename from emp order by deptno;
DEPTNO ENAME
10 KING
CLARK
20 JONES
SCOTT
SMITH
ADAMS
30 TURNER
MARTIN
WARD
ALLEN
BLAKE
11 rows selected.
SQL>
But if you still wish to do it in SQL you can use ROW_NUMBER analytic function and achieve it like this
select decode(rno, 1, deptno) deptno
, ename
from (
select row_number() over(partition by deptno order by ename) rno
, deptno
, ename
from emp -
SQL Query does not have all rows in ResultSet
I am using JDK 1.4.2 and an MS Access 2000 database where I attempt to retrieve data and I get in the ResultSet a maximum of around 280 rows, but there are more that seem to be ignored. In Access I can see them using the same query.
The Statement.getMaxRows() returns 0 and I do not understand why I do not get the other ones. The query is issued using Statement.executeQuery(String), but using execute() does not make a difference, There is just one ResultSet returned.
I would appreciate your help.I had this same problem once because in my Java code I was connecting to our alpha database and when I was running the query manually I was connecting to our production database.
The only other thing I can think of that might cause this is if on the 281st row there is something wrong with the row and maybe the SQLException isn't being processed? Can't really say without seeing your code, but if you don't have a printStackTrace() or some indicator when a SQLExcpetion is thrown it could be breaking without your knowing. If those aren't the problems maybe you could post your code. -
SQL Query : sum only numbers in row - need help
Pls see data below. I would like to display only 8 rows and BRH CCN rows should be merged together and displayed as - BRH 98 2 instead of 2 rows. The rest of the rows should remain as is. Please help.
CCN SERVICES MANUFACTURING
ASL 138 NA
BRH 98 NA
BRH NA 2
C10000 NA 0
C40000 NA 0
DAO NA 10
E10000 NA 0
I10000 NA 0
M10000 NA 0
Edited by: auxilia on Nov 7, 2009 6:25 AMwith t as (
select 'ASL' ccn,'138' services,'NA' manufacturing from dual union all
select 'BRH','98','NA' from dual union all
select 'BRH','NA','2' from dual union all
select 'C10000','NA','0' from dual union all
select 'C40000','NA','0' from dual union all
select 'DAO','NA','10' from dual union all
select 'E10000','NA','0' from dual union all
select 'I10000','NA','0' from dual union all
select 'M10000','NA','0' from dual
select ccn,
nvl(max(case services when 'NA' then null else services end),'NA') services,
nvl(max(case manufacturing when 'NA' then null else manufacturing end),'NA') manufacturing
from t
group by ccn
CCN SERVICES MANUFACTURING
E10000 NA 0
C10000 NA 0
BRH 98 2
M10000 NA 0
C40000 NA 0
ASL 138 NA
I10000 NA 0
DAO NA 10
8 rows selected.
SQL> SY.
Edited by: Solomon Yakobson on Nov 7, 2009 6:46 AM -
SQL query results. more than 10 rows
Home>SQL>SQL Commands
Results tab says
More than 10 rows available. Increase rows selector to view more rows.
How can I "Increase rows selector to view more rows."?Sim,
above the text area for the sql command you find a combobox with the label "Display". Initially only 10 records will be displayed.
~Dietmar. -
SQL Query updateable report with row selector. Update process.
I have a SQL Query updateable report with the row selector(s).
How would I identify the row selector in an update process on the page.
I would like to update certain columns to a value of a select box on the page.
Using the basic:
UPDATE table_name
SET column1=value
WHERE some_column=some_value
I would need to do:
UPDATE table_name
SET column1= :P1_select
WHERE [row selector] = ?
Now sure how to identify the [row selector] and/or validate it is checked.
Thanks,
BobI don't have the apex_application.g_f01(i) referenced in the page source...In the page source you wouldn't find anything by that name
Identify the tabular form's checkbox column in the page(firebug/chrome developer panel makes this easy)
It should be like
<input id="..." value="" type="checkbox" name="fXX" >we are interested in the name attribute , get that number (between 01 and 50)
Replace that number in the code, for instance if it was f05 , the code would use
apex_application.g_f05
--i'th checked record' primary keyWhen you loop through a checkbox array, it only contains the rows which are checked and it is common practice to returns the record's primary key as the value of the checkbox(available as the the i'th array index as apex_application.g_f05(i) , where i is sequence position of the checked row) so that you can identify the record. -
I ran into a problem which i cant figure out, i wand to write
a SQL query which will give me rows 5 - 10 as output.
So far i only get first row to last or limit it to 5 but i
cant tell it i want rows 5, 6, 7, 8, 9, 10. Basicly minus the first
5, in the DB are 100 entries. anyone know how that would look like.
or has a tutorial or something for me to read.This should give you all the rows minus the first 5 in the
table:
SELECT * FROM YourTable
WHERE TheID NOT IN
SELECT TOP 5 TheID
FROM YourTable
Pat.
"ToXiT44" <[email protected]> wrote in
message
news:f36aa4$hq0$[email protected]..
>I ran into a problem which i cant figure out, i wand to
write a SQL query
>which
> will give me rows 5 - 10 as output.
> So far i only get first row to last or limit it to 5 but
i cant tell it i
> want
> rows 5, 6, 7, 8, 9, 10. Basicly minus the first 5, in
the DB are 100
> entries.
> anyone know how that would look like. or has a tutorial
or something for
> me to
> read.
> -
SQL Query (updateable report) CheckBox Update Problem
My process will update 1 or 2 rows, but fails on three or more rows. All the rows on the page can be processed, up to 2 at a time.
The SQL Query Report can have 50 rows on a page. Only the check box and the hidden primary key column are returned by the report to the process (marked as edit).
If I issue the update myself, I can update any number of rows with no error.
If I change the update SQL to a select, it works for the all of the checked lines (the correct count is displayed in the process message.
The only thing I see for the failure is a url
http://d101dbaxeaa2llb:10700/apex/wwv_flow.accept
Process is:
DECLARE
vRow BINARY_INTEGER;
item NUMBER;
BEGIN
item := 0;
FOR i IN 1 .. apex_application.g_f01.COUNT
LOOP
item := item + 1;
vRow := apex_application.g_f01(i);
update #OWNER#.B_ATT_DAYS_FUT
set day_status_cd =
case
when day_status_cd = -1 and day_dt is not null then 2
when day_status_cd = -1 and day_dt is null then 0
when day_status_cd = 6 then 7
else 2
end
where days_pk = to_number(apex_application.g_f02 (vRow));
END LOOP;
:P35_CHECKED_CT := item;
END;
This is in APEX Application Express 3.1.0.00.32 on Oracle 11.1.0.6.0.Query is at the end. The Report Regions is a SQL Query (Updatable Report).
I don't thinks this is my code problem.
The system I'm using is dieing. It has had two disk crashes, which spinrite brought back. I've restored from a partition image and a full cold backup. Then I've had a number of blue screen failures. One of the DBAs working for me rebuilt the 11g instance on a VM and restored the cold backup. Everything runs fine there. I even applied the latest code export from the failing systems development workspace to the VM based system. Still runs fine.
There are a number of abends in the alert log ORA-07445 and ORA-21779 for which our on-site ASC Engineer has opened a TAR/SR. I suspect that some part of one of the FLOW tablespaces was damaged, a part which deals with runtime APEX. Build time is running fine. Application just does not, either as a runtime or in the development system.
We are moving to a new AIX server, just finishing the setup and then I can send over the exports. That should put this to bed.
SELECT
DAYS_PK
, NAME_TX
, DAY_CD
, DAY_DESC_TX
, DAY_STATUS_CD
, DAY_STATUS_DESC_TX
, DAY_DT
, REASON_TX
, TEN_DAY_PERIOD_FL
, EARNED_ON_DT
, EXPIRES_ON_DT
, PLANNED_ON_DT
, GUARANTEED_DAY_CD
, GUARANTOR
FROM
(SELECT
DAYS."DAYS_PK"
, A_ATT_USERS.NAME_TX
, DAYS."DAY_CD"
, DAY_CD."DAY_DESC_TX"
, DAYS."DAY_STATUS_CD"
, DAY_ST_CD."DAY_STATUS_DESC_TX"
, DAYS."DAY_DT"
, DAYS."REASON_TX"
, DAYS."TEN_DAY_PERIOD_FL"
, DAYS."EARNED_ON_DT"
, DAYS."EXPIRES_ON_DT"
, DAYS."PLANNED_ON_DT"
, CASE DAYS."GUARANTEED_DAY_CD"
WHEN 'E' THEN 'GUARANTEED'
WHEN 'R' THEN 'GUARANTOR'
ELSE NULL
END GUARANTEED_DAY_CD
, G_ATT_USERS.NAME_TX "GUARANTOR"
FROM
"B_ATT_DAYS_FUT" DAYS
LEFT OUTER JOIN "A_ATT_USERS" G_ATT_USERS
ON
"DAYS"."GUARANTEED_COMIT_ID" = "G_ATT_USERS"."COMIT_ID"
LEFT OUTER JOIN "A_ATT_USERS"
ON
"DAYS"."COMIT_ID" = "A_ATT_USERS"."COMIT_ID"
, "T_ATT_DAY_CD" DAY_CD
, "T_ATT_DAY_STATUS_CD" DAY_ST_CD
WHERE
DAYS."DAY_CD" = DAY_CD."DAY_CD"
AND DAYS."DAY_STATUS_CD" = DAY_ST_CD."DAY_STATUS_CD"
AND DAYS.COMIT_ID IN
SELECT DISTINCT
( R.COMIT_ID )
FROM
ATT_ATTENDANCE.A_ATT_STAFF_ROLE R
WHERE
R.COMIT_ID <> :P1_COMIT_ID_HIERARCHY START
WITH R.COMIT_ID = :P1_COMIT_ID_HIERARCHY
CONNECT BY PRIOR R.COMIT_ID = R.MGR_COMIT_ID
AND DAYS.DAY_STATUS_CD IN ( 1, -1, 6 )
AND DAYS.COMIT_ID <> :P1_COMIT_ID
ORDER BY
A_ATT_USERS.NAME_TX
, DAYS.DAY_DT
, DAYS.DAY_CD DESC
, DAYS.EARNED_ON_DT)
WHERE
INSTR(UPPER(NAME_TX),UPPER(COALESCE(:P35_S_NAME,NAME_TX))) > 0 -
How can I show all the results returned by a sql query?
Hi guys,
I need your help.
Let's say I have one table: TableA. Fields of TableA are aleg, anon, apes. The following sentence can return, in general, several rows: select anon from TableA where aleg = somevalue. I'd like to show the result of column anon but no luck. If I try to show the results in a TextArea and the origin is an sql query only shows the first row value. I tried Show as: show as text (based in PLSQL) and coding an anonymous plsql block as
DECLARE
v_anon TableA.anon%TYPE;
CURSOR v_cur IS
select anon from TableA where aleg = somevalue;
BEGIN
OPEN v_cur;
LOOP
FETCH v_cur INTO v_anon;
EXIT WHEN v_cur%NOTFOUND;
:FIELD_IN_FORM := v_anon;
END LOOP;
CLOSE v_cur;
END;
but in this case it's not shown any result.
So the first question is what kind of field should I use to show the result. And the second one is what can I do to being able to show all the results returned by the query (provided that is more than one single row).
regardsHi Denes,
Just starting with apex. I think I know how to show the results in a report region. I've simplified the posted question.
A more detailed question would be: Suppose you have a region where you have put several text areas to accommodate the result of a multi-column query (lets say for TableA) that only returns one row, each column value returned put in a different text area. Also you want to show the values of other fields in TableB that depends on some value just retrieved from TableA and that you want all values retrieved (from TableA and the linked TableB) to be show in the same region. Is that possible? If yes, how?
Thank you in advance -
Conditional display of region with PL/SQL function returning SQL query
Hello,
ApEx 2.0.
I use PL/SQL functions that return SQL queries to display the contents of a region.
How could I conditionally display such region ? If no data is found, the region shouldn't be shown. I tried with "SQL query returns at least one row" but this doesn't seem to work.
Thanks,
MatthiasHi Matthias,
Are the regions in question report regions? So your PL/SQL process is returning a SQL query and then populating a report?
The EXISTS(SQL Query returns at least one row) condition should work, try running the query you are using in the Expression 1 textarea inside SQL*Plus, or SQL developer using the same parameters, and see what gets returned.
If you are still stuck, can you post the query you are using inside your Expression 1 textarea of the Conditions section and I can take a look at it for you.
Hope this helps,
Cj -
Hai ,
I am having doubt regarding NOT EXISTS sql query,
I want to select rows from table1 where column2 < column3 and column1 value should not exists in another two tables.
When i tried with NOT IN clause i got the answer but i didnt get when i tried with NOT EXISTS.....can anyone give me the answer....
select * from TABLE1 where mark2< mark3 AND
name NOT IN (select name from TABLE2 UNION
select name from TABLE3);Your query can be re-written in the following way by using not exists clause:
SELECT *
FROM table1 t1
WHERE mark2 < mark3
AND NOT EXISTS (
SELECT 1
FROM table2
WHERE name = t1.name)
AND NOT EXISTS (
SELECT 1
FROM table3
WHERE name = t1.name)Go through http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:442029737684
on when to use NOT IN and NOT EXISTS.
Hope this is helpful.
- RK
Maybe you are looking for
-
I have multiple iTunes Previous Libraries
I am trying to delete stuff to allow for extra space in my hard Drive. I have multiple iTunes Previous Libraries.....Can I delete these & would it actually help? Also how can I identify the correct ones to delete? If it says previous does that defina
-
I have a charge off with credit union account due to drop off credit report 6/16. I've call them a few times but all they do is give me a number to a collection agency! They refuse to talk to me about the account! The OCA is no where listed on any of
-
HTML Display without Report Templates
Hi all I am saving html page (with all data and formats) in a table. On next step I will query this table and will display this column and will disply it on the region. But I dont want to use HTMLDB report templates. Because I want to control the for
-
MacBook cant find AirPort Express
Hi all, Now i'm not sure if i should post this one under macbook section or not but i'll give it a shot here. My problem is that suddenly the other day my macbook lost it's connection to my airport express. It could find all the other wireless networ
-
Can't not choose field for filter in recordset dialogbox
I deveop website by DreamweaverMX. I have some problem with dynamic page for ASP when I click binding-->recordset if I choose field for filter or choose URL Paramiter when I test webpage It say "The page cannot be displayed" If I choose filter is "No