Query for selecting distinct by date
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
I have a simple table that has an ID, Title, and Date.
I need to select the most recent ID (without duplicates). I was looking at using a UNION but couldn't quite get it to work.
P3XGL2FV96 Test 1 11-AUG-10 03.38.06.000000000 PM
1VGJ74PSNW Test 2 11-AUG-10 04.02.22.000000000 PM
1VGJ74PSNW Test 2 12-AUG-10 09.49.09.000000000 AM
Hi,
You could achieve it like this :
CREATE TABLE MY_TABLE
+(+
ID VARCHAR2(10),
TITLE VARCHAR2(10),
MY_DATE TIMESTAMP
+);+
insert into my_table values ('P3XGL2FV96', 'Test 1', '11-AUG-10 03.38.06.000000000 PM');
insert into my_table values ('1VGJ74PSNW', 'Test 2', '12-AUG-10 09.49.09.000000000 AM');
insert into my_table values ('1VGJ74PSNW', 'Test 2', '11-AUG-10 04.02.22.000000000 PM');
commit;
SELECT id, title, my_date
FROM (SELECT id,
title,
my_date,
RANK () OVER (PARTITION BY id ORDER BY my_date DESC) rk
FROM my_table)
WHERE rk = 1;
ID |TITLE |MY_DATE
----------|----------|---------------------------------------------------------------------------
+1VGJ74PSNW|Test 2 |12-AUG-10 09.49.09.000000 AM+
P3XGL2FV96|Test 1 |11-AUG-10 03.38.06.000000 PM
Remark : if one id have twice the same date they will be both ranked first
Kind regards,
Ludovic
Edited by: ludovic.sz on Aug 12, 2010 8:38 AM
Similar Messages
-
Query for select CLOB data field
Hi All,
I want to know how to write a SQL query for select CLOB tyoe data from a tablw. when I am trying to use the simple SQL it gives an messageLOB types requires OCI8 mode and currently uasing OCI7 ode.
Also I am not aware of oci mode?
If its working for OCI8 mode how I should changer it in to OCI8 mode? (I am using 10g rel 2)
Thans and regards
BuddhikeHi ,
i don't want to use loop (sy-tabix) ..
any particular reason for this ?
as u cannot automatically generate serial number, u have to go for loop....endloop.
Thanks
Karthik -
Need of SQL query in selecting distinct values from two tables
hi,
I need a query for selecting distinct values from two tables with one condition.
for eg:
there are two tables a & b.
in table a there are values like age,sex,name,empno and in table b valuses are such as age,salary,DOJ,empno.
here what i need is with the help of empno as unique field,i need to select distinct values from two tables (ie) except age.
can anybody please help me.
Thanks in advance,
RatheeshNot sure what you mean either, but perhaps this will start a dialog:
SELECT DISTINCT a.empno,
a.name,
a.sex,
b.salary,
b.doj
FROM a,
b
WHERE a.empno = b.empno;Greg -
Error while executing a sql query for select
HI All,
ORA-01652: unable to extend temp segment by 128 in tablespace PSTEMP i'm getting this error while i'm executing the sql query for selecting the data.I am having 44GB of temp space, while executing the below query my temp space is getting full, Expert please let us know how the issue can be resolved..
1. I dont want to increase the temp space
2. I need to tune the query, please provide your recomendations.
insert /*+APPEND*/ into CST_DSA.HIERARCHY_MISMATCHES
(REPORT_NUM,REPORT_TYPE,REPORT_DESC,GAP,CARRIED_ITEMS,CARRIED_ITEM_TYPE,NO_OF_ROUTE_OF_CARRIED_ITEM,CARRIED_ITEM_ROUTE_NO,CARRIER_ITEMS,CARRIER_ITEM_TYPE,CARRIED_ITEM_PROTECTION_TYPE,SOURCE_SYSTEM)
select
REPORTNUMBER,REPORTTYPE,REPORTDESCRIPTION ,NULL,
carried_items,carried_item_type,no_of_route_of_carried_item,carried_item_route_no,carrier_items,
carrier_item_type,carried_item_protection_type,'PACS'
from
(select distinct
c.REPORTNUMBER,c.REPORTTYPE,c.REPORTDESCRIPTION ,NULL,
a.carried_items,a.carried_item_type,a.no_of_route_of_carried_item,a.carried_item_route_no,a.carrier_items,
a.carrier_item_type,a.carried_item_protection_type,'PACS'
from CST_ASIR.HIERARCHY_asir a,CST_DSA.M_PB_CIRCUIT_ROUTING b ,CST_DSA.REPORT_METADATA c
where a.carrier_item_type in('Connection') and a.carried_item_type in('Service')
AND a.carrier_items=b.mux
and c.REPORTNUMBER=(case
when a.carrier_item_type in ('ServicePackage','Service','Connection') then 10
else 20
end)
and a.carrier_items not in (select carried_items from CST_ASIR.HIERARCHY_asir where carried_item_type in('Connection') ))A
where not exists
(select *
from CST_DSA.HIERARCHY_MISMATCHES B where
A.REPORTNUMBER=B.REPORT_NUM and
A.REPORTTYPE=B.REPORT_TYPE and
A.REPORTDESCRIPTION=B.REPORT_DESC and
A.CARRIED_ITEMS=B.CARRIED_ITEMS and
A.CARRIED_ITEM_TYPE=B.CARRIED_ITEM_TYPE and
A.NO_OF_ROUTE_OF_CARRIED_ITEM=B.NO_OF_ROUTE_OF_CARRIED_ITEM and
A.CARRIED_ITEM_ROUTE_NO=B.CARRIED_ITEM_ROUTE_NO and
A.CARRIER_ITEMS=B.CARRIER_ITEMS and
A.CARRIER_ITEM_TYPE=B.CARRIER_ITEM_TYPE and
A.CARRIED_ITEM_PROTECTION_TYPE=B.CARRIED_ITEM_PROTECTION_TYPE
AND B.SOURCE_SYSTEM='PACS'
Explain Plan
==========
Plan
INSERT STATEMENT ALL_ROWSCost: 129 Bytes: 1,103 Cardinality: 1
20 LOAD AS SELECT CST_DSA.HIERARCHY_MISMATCHES
19 PX COORDINATOR
18 PX SEND QC (RANDOM) PARALLEL_TO_SERIAL SYS.:TQ10002 :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1
17 NESTED LOOPS PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1
15 HASH JOIN RIGHT ANTI NA PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,098 Cardinality: 1
4 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 63 Bytes: 359,283 Cardinality: 15,621
3 PX SEND BROADCAST PARALLEL_TO_PARALLEL SYS.:TQ10001 :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621
2 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621
1 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621
14 NESTED LOOPS ANTI PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 40,256,600 Cardinality: 37,448
11 HASH JOIN PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 6,366,160 Cardinality: 37,448
8 BUFFER SORT PARALLEL_COMBINED_WITH_CHILD :Q1002
7 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 1 Bytes: 214 Cardinality: 2
6 PX SEND BROADCAST PARALLEL_FROM_SERIAL SYS.:TQ10000 Cost: 1 Bytes: 214 Cardinality: 2
5 INDEX FULL SCAN INDEX CST_DSA.IDX$$_06EF0005 Cost: 1 Bytes: 214 Cardinality: 2
10 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448
9 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448
13 TABLE ACCESS BY INDEX ROWID TABLE PARALLEL_COMBINED_WITH_PARENT CST_DSA.HIERARCHY_MISMATCHES :Q1002Cost: 0 Bytes: 905 Cardinality: 1
12 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT SYS.HIERARCHY_MISMATCHES_IDX3 :Q1002Cost: 0 Cardinality: 1
16 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT CST_DSA.IDX$$_06EF0001 :Q1002Cost: 1 Bytes: 5 Cardinality: 1 -
Query for selecting the 4 highest marks of the student
query for selecting the 4 highest marks of the student
Guys dont start an argument,
tey this one; please
Hi,
Try this
Top 4
Select ename,
sale
From dept d,
emp e1
Where d.deptno = e1.deptno
And &p > (Select Count(e2.sal)
From emp e2
Where e2.sal > e1.sal
And e2.deptno = e1.deptno
Order By 1,2
Bottom 4
Select ename,
sale
From dept d,
emp e1
Where d.deptno = e1.deptno
And &p > (Select Count(e2.sal)
From emp e2
Where e2.sal < e1.sal
And e2.deptno = e1.deptno
Order By 1, 2
&P you use any value say 3,4,5,6
This is top N analysis
Regards
Umesh -
Query for selecting first 3 characters of name of any person
query for selecting first 3 characters of name of any person
10:52:44 SQL> SELECT SUBSTR(ename, 1, 3) first_three FROM emp;
FIRST_THREE
SMI
ALL
WAR
JON
MAR
BLA
CLA
SCO
KIN
TUR
ADA
FIRST_THREE
JAM
FOR
MIL
Ton
15 rows selected.
Elapsed: 00:00:00.00 -
Help! Howto use the join function in a query with select distinct ?
Hi!
I have 2 tables. I want to select only 1 painting of each artists.
select distinct idartist
from tbl_artworks
where blah blah blah
order by rand()
how does the "join" function work for add: name, lastname, title, image and much more... i try... but i fail...
tbl_artists
idartist
name
lastname
1
Paul
Gaugain
2
Vincent
Van Gogh
3
Pablo
Picasso
tbl_artworks
idartwork
idartist
title
image
1
1
days of gods
image1.jpg
2
2
sunflower
image2.jpg
3
3
Dora maar au chat
image3.jpg
4
2
Sky
image4.jpg
5
3
La vie
image5.jpgGetting a single random image for each probably requires a combination of sql and cf. It would take someone smarter than me to do it with sql alone. I would probably try something like this:
1. Run a database query that gets all the images from all the artists.
2. Run a Q of Q that gets a distinct list of artist ids.
3. Loop through that list and run a Q of Q to get all the images for that artist.
4. Still in that loop, use randrange (1 to the recordcount) to select a random record from your Q of Q -
Delta field not enabled for selection in generic data source
Hi
I have created a generic data source for the table VBFA....and for the delta pick up i have put the delta option as CALDAY on the field ERDAT...and i have selected that field for the selection option. but after i made it delta enabled the selection option got disabled.
Now when i check the info package delta selection tab that date column is not apperaing.
But when i have to run the info package for the first i dont want all the data as it has a huge set of data.
I wanted to take only this months data.
So is there any option to be set to enable this selection in info package.
please suggest.
Regards
ShilpaHi there,
That's the stardard behaviour. If you use delta based om ERDAT, that field won't be available for selecting.
You could for example try to build a view over VBFA, and let the field ERDAT there and another field, for example ZERDAT (that is just another alias for ERDAT). Create the delta based onyour view over the field (ERDAT), but you can still control the restrictions over the extractore with your ZERDAT.
I don't know if this is possible, this is only an assumption.
Another option could be first to create an extractor based on the table VBFA but without delta, that field ERDAT would be available. Do your full data restricting it, and after that, change your datasource to use deltas based on ERDAT. It will be unavailable than, but since you've already loaded previous full data, you could than use your delta like it is. But here, remember, your deltas will bring new and change data based on ERDAT. If it brings delta based on changed data over ERDAT to a record that you didn't brought over your full (only some data), it will be incorrect records.
Also just an assumption, did not try it.
Diogo. -
A test query for selecting by ticketid
This is a test query to select tickets by ticketid , starting with the most recent, as to get the top5 most recent tickets. There will be still mistakes in it. please don't tell me those about stupid mistakes,and spaces, at first and obvious syntax mistakes. Otherwise I don't learn it. My question has to do with the loop. Do you think it is useful to use a loop for this, or should it stay as it is, or should it be something else.
DECLARE
Define, and open a cursor;
min_ticket NUMBER; -- minimum ticketid
laatste_ticket NUMBER; -- latest ticketid
tussen_ticket NUMBER; -- in between ticket
Query_to_use VARCHAR2(4000);
BEGIN
Select max(ticketid) into laatste_ticketid from ticket;
Select count(*) into teller from ticket where (ticketid<laatste_ticketid ) AND (ticketid>(laatste_ticketid-6));
Select ticketid, categoriecd, titel into cursor from ticket where (ticketid<laatste_ticketid ) AND (ticketid>(laatste_ticketid-6));
Select min(ticketid) into min_ticketid from ticket;
If teller= < 5
If teller = 5
Query_to_use := Query_to_use || ';';
Return Query_to_use;
else
--Loop through records from laatste_ticketid to min_ticketid
Select gebruikerid into te_testen_veld from ticket where ticketid = tussen_ticketid ;
If te_testen_veld is NULL THEN
tussen_ticketid := tussen_ticketid - 1;
te_testen_veld := NULL;
Else
Query_to_use := query_to_use || ' UNION select ticketid, categoriecd, titel from ticket '||
' where ticketid = tussen_ticketid ';
te_testen_veld := NULL;
Teller := teller + 1;
If (teller < 5)
tussen_ticketid := tussen_ticketid - 1;
Else if (teller = 5)
teller := 6;
End if;
End if;
--End Loop;
End if;
End if;
Query_to_use := Query_to_use || ';';
Return Query_to_use;
END;You can get all this using one SQL statement, without resorting to explicit cursors. Have a look at http://asktom.oracle.com and search for Top-N Query.
Depending on what you are doing, you may want to use a cursor for loop.
I assume this is for some sort of electronic queueing system. if you gave us more detail as to what you are trying to do, you may get better advice. -
Query for selecting current date when running report
Hi all
I need a query that will copy today's date on posted sales order via DTW then that query will be linked to an alert and be sent to the sales manager every morning after the import went through successfully.
The report at the moment is running fine as i pulling through the other info required the only problem is it's pulling all the sales orrders on the system , we want it to pull only the days orders imported.You could use either of these queries
SELECT T0.DocNum, T0.DocDueDate, T0.CardCode, T0.CardName, T0.DocTotal, T0.U_ROUTEMARKTN, T0.U_ROUNDS, T0.U_DAYOFWEEK
FROM [dbo\].[ORDR\] T0
WHERE T0.DocDate = GETDATE()
ORDER BY T0.U_ROUTEMARKTN, T0.U_ROUNDS, T0.U_DAYOFWEEK, T0.DocDueDate
OR
SELECT T0.DocNum, T0.DocDueDate, T0.CardCode, T0.CardName, T0.DocTotal, T0.U_ROUTEMARKTN, T0.U_ROUNDS, T0.U_DAYOFWEEK
FROM [dbo\].[ORDR\] T0
WHERE DATEDIFF(Day, T0.DocDate, GETDATE()) = 0
ORDER BY T0.U_ROUTEMARKTN, T0.U_ROUNDS, T0.U_DAYOFWEEK, T0.DocDueDate -
I need to make a query that checks to see if the start_date is less than sysdate and the end_date is greater than sysdate
SELECT * FROM table WHERE OFFICE_START_DATE < SYSDATE AND OFFICE_END_DATE > SYSDATE
What is the easiest way of doing this?
Thanksuser9179751 wrote:
It wasn't working for me initially but I had to format the date to validate.
SELECT * FROM TABLE WHERE OFFICE_START_DATE < TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS')
AND OFFICE_END_DATE > TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS');As skvaish said, it looks as if your columns are character (varchar2, most likely) and not dates. And if so, your solution is still buggy. You should be doing
select *
from mytable
where to_date(office_start_date) < sysdate
and to_date(office_end_date) > sysdate;If you insist on thinking that a chracter string that looks like a date is a date, what do you make of this:
First, create a table with a char column used as a date:
SQL> drop table mydemo;
Table dropped.
SQL> create table mydemo (
2 alfa_date varchar2(11),
3 rite_date date
4 );
Table created.Now insert some data
SQL> --
SQL> insert into mydemo values ('01-JAN-2010', to_date('01-JAN-2010','DD-MON-YYYY'));
1 row created.
SQL> insert into mydemo values ('01-FEB-2010', to_date('01-FEB-2010','DD-MON-YYYY'));
1 row created.
SQL> insert into mydemo values ('01-APR-2010', to_date('01-APR-2010','DD-MON-YYYY'));
1 row created.
SQL> insert into mydemo values ('02-JAN-2010', to_date('02-JAN-2010','DD-MON-YYYY'));
1 row created.
SQL> insert into mydemo values ('02-FEB-2010', to_date('02-FEB-2010','DD-MON-YYYY'));
1 row created.
SQL> insert into mydemo values ('02-APR-2010', to_date('02-APR-2010','DD-MON-YYYY'));
1 row created.
SQL> insert into mydemo values ('03-JAN-2010', to_date('03-JAN-2010','DD-MON-YYYY'));
1 row created.
SQL> insert into mydemo values ('03-FEB-2010', to_date('03-FEB-2010','DD-MON-YYYY'));
1 row created.
SQL> insert into mydemo values ('03-APR-2010', to_date('03-APR-2010','DD-MON-YYYY'));
1 row created.
SQL> commit;
Commit complete.Now, select, and order on the alfa-date;
SQL> select * from mydemo order by alfa_date;
ALFA_DATE RITE_DATE
01-APR-2010 01-APR-10
01-FEB-2010 01-FEB-10
01-JAN-2010 01-JAN-10
02-APR-2010 02-APR-10
02-FEB-2010 02-FEB-10
02-JAN-2010 02-JAN-10
03-APR-2010 03-APR-10
03-FEB-2010 03-FEB-10
03-JAN-2010 03-JAN-10
9 rows selected.Are they in date sequence?
No they are not.
Why not?
Now select, and order on the properly defined date column.
SQL> select * from mydemo order by rite_date;
ALFA_DATE RITE_DATE
01-JAN-2010 01-JAN-10
02-JAN-2010 02-JAN-10
03-JAN-2010 03-JAN-10
01-FEB-2010 01-FEB-10
02-FEB-2010 02-FEB-10
03-FEB-2010 03-FEB-10
01-APR-2010 01-APR-10
02-APR-2010 02-APR-10
03-APR-2010 03-APR-10
9 rows selected.
SQL> spo off -
Query For Large Amount of Data
Hello All,
I apologize in advance if I am not posting this in the right section. I am fairly new to APEX and database designing. My goal is to create an inquiry screen for a database of people.
I am running APEX 4.2 on 11g. The information is store in 3 tables; Names, Demographics, Address. Each table had a PIN ID column that ties them all together. Each table has almost a million rows in them.
Currently I have it set up that the person types in the name they want to search and it gets passed into a hidden page item on the next page where there is a report with a select statement based on the page item. Everything works right now however it is slow. I am having a 5-10 second delay before the results come up.
My question is, is there a better way to set up these tables. What is the best way to make this faster?
I'm sorry if this is a vague question but any help, or point in the right direction will be greatly appreciated
Thank You !976533 wrote:
Hello All,Welcome to the forum: please read the FAQ and forum sticky threads (if you haven't done so already), and update your forum profile with a real handle instead of "976533".
When you have a problem you'll get a faster, more effective response by including as much relevant information as possible upfront. This should include:
<li>Full APEX version
<li>Full DB/version/edition/host OS
<li>Web server architecture (EPG, OHS or APEX listener/host OS)
<li>Browser(s) and version(s) used
<li>Theme
<li>Template(s)
<li>Region/item type(s) (making particular distinction as to whether a "report" is a standard report, an interactive report, or in fact an "updateable report" (i.e. a tabular form)
With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. If you expect a detailed answer then it's appropriate for you to take on a significant part of the effort by getting as far as possible with an example of the problem on apex.oracle.com before asking for assistance with specific issues, which we can then see at first hand.
I apologize in advance if I am not posting this in the right section. I am fairly new to APEX and database designing. My goal is to create an inquiry screen for a database of people.It might be more appropriate to the {forum:id=75} forum, so you should look at the following entries on their FAQ as well:
<li>{message:id=9360002}
<li>{message:id=9360003}
I am running APEX 4.2 on 11g. The information is store in 3 tables; Names, Demographics, Address. Each table had a PIN ID column that ties them all together. Each table has almost a million rows in them.
Currently I have it set up that the person types in the name they want to search and it gets passed into a hidden page item on the next page where there is a report with a select statement based on the page item. Everything works right now however it is slow. I am having a 5-10 second delay before the results come up.
My question is, is there a better way to set up these tables. What is the best way to make this faster? Are there suitable indexes on the tables?
Does the report query use them?
As described above, either: reproduce the problem on apex.oracle.com; or post DDL to allow us to recreate the tables and indexes, and the SQL from your report. -
How can I enforce automatic spell checking for selected fields of data entered by form users?
I'd like to be able to enforce spell checking of selected fields in the forms that I've created using LiveCycle Designer 8.2 at run time, as opposed to design time. I understand the version LCD 8 has a nifty new spell checker for form designers. But I want to spell check the data entered by users using Acrobat Reader. And I want to enforce the spell checking automatically on selected fields only.
Presently it seems that users filling in my forms, must know how to manually right-click on each field and select "Spell Check" from the resulting dialog box in order to check for spelling errors in the data the user has entered in the form.
I would like to discover a way to enforce spell checking in selected fields, just as I am able to do in forms created using Acrobat Pro. In Acrobat Pro, I can set a property for each field to require spell checking. but that feature seems to be missing in Livecycle Designer.
I've check the Object model for XFA forms hoping that I might find a method I can call with a Javascript, to check spelling based on an event such as onBlur. But I haven't found a spell check method.
Am I missing something simple? Is there a way to set each field to be spell checked when a user is filling in the form using the free Acrobat Reader?
Our users are not sophisticated and requiring them to spell check each field separately just won't cut it...
Any help on this will be greatly appreciated.
Thanks!
-David BartholomewHi David,
Two things...
At design time set the locale of the form to one that Acrobat spell checks. For example English (US) and English (UK) locales have spell checkers; however English (Ireland) does not. Check the Warnings tab to see if spell checking is supported for your locale.
If your form locale supports spell checking then you can go to the button script below.
If you form locale does NOT support spell checking then Stephanie has a great work around to force spell checking (http://forums.adobe.com/message/2233945#2233945).
Bring a regular button onto the form and in the click event have the following:
app.execMenuItem("Spelling:Check Spelling");
Which will open the spell checker for all fields. Thanks to Paul for extracting all of the accessible menu items (http://forums.adobe.com/message/1912914#1912914).
Good luck,
Niall -
Query for Business Partner Master data
Respected Sir/Madam,
I want a Query in Bp Master Data----> "Name" Should Allow Only Capital Letters.Can anyone please helpme out from this.Hi,
Apply FMS to BP Name field.
Set below query in FMS and tick auto refresh with "When Exiting Altered Column" and select field Quantity and select "Refresh Regularly" .
Select UCASE($[OCRD.CardName)
Regards,
Clint -
Query for months & quarter in date functions
Hi All
Could some on assist me how to get Last Year 1st,2nd,,, months and Current Year 1st,2nd,3rd,,, months and same way Quarterly please.
I have date column Trade_date (dd/Mon/yyyy), Trade_price in Trade table
DB:Oracle 11g
Any assist would be appreciatedAll you have done is repeat your unclear question with more words.
Here is how to get all the months for prior year and this year
SQL> alter session set nls_date_format = 'Mon-YYYY';
Session altered.
SQL> select
2 add_months(this_year, - 12) last_year,
3 this_year
4 from
5 (
6 select
7 add_months(trunc(sysdate,'y'), level - 1) this_year
8 from
9 dual
10 connect by
11 level <= 12
12 );
LAST_YEA THIS_YEA
Jan-2010 Jan-2011
Feb-2010 Feb-2011
Mar-2010 Mar-2011
Apr-2010 Apr-2011
May-2010 May-2011
Jun-2010 Jun-2011
Jul-2010 Jul-2011
Aug-2010 Aug-2011
Sep-2010 Sep-2011
Oct-2010 Oct-2011
Nov-2010 Nov-2011
Dec-2010 Dec-2011
12 rows selected.And quarters
SQL> select
2 add_months(this_year, - 12) last_year,
3 this_year
4 from
5 (
6 select
7 add_months(trunc(sysdate,'y'), (level - 1) * 3) this_year
8 from
9 dual
10 connect by
11 level <= 4
12 );
LAST_YEA THIS_YEA
Jan-2010 Jan-2011
Apr-2010 Apr-2011
Jul-2010 Jul-2011
Oct-2010 Oct-2011
SQL> alter session set nls_date_format = 'dd/mm/yyyy';
Session altered.
SQL> select
2 add_months(this_year, - 12) last_year,
3 this_year
4 from
5 (
6 select
7 add_months(trunc(sysdate,'y'), (level - 1) * 3) this_year
8 from
9 dual
10 connect by
11 level <= 4
12 );
LAST_YEAR THIS_YEAR
01/01/2010 01/01/2011
01/04/2010 01/04/2011
01/07/2010 01/07/2011
01/10/2010 01/10/2011As you can see from the second example, the display format of dates is controlled by the session,
>
he date column is trade_date (dd/mm/yyyy)
>
So this is still incorrect - if it is a date the format is not dd/mm/yyyy and, it is still not clear how this relates to your other questions.
Maybe you are looking for
-
Need help with adding formatted text and images to Crystal Report?
Here's my scenario: I have a customer statement that's generated as a crystal report and that has a placeholder for advertisement. The advertisement is mixture of formatted text and images. Until now we only had one advertisement that was always used
-
how can I open .mov files in Photoshop elements 7
-
hi , good evening to all , can any body send me the material regarding ale idocs, ie theory as well as programming point of view.if possibe provide links thanks®ards suresh
-
Clock in /Clock out automation and Tracking LCC.
Hello All Experts, To keep better control over login/licence usage and to track the LCC we are planning to implement badge readers... The isea is to send data to MES throgh batch reader when user is loging in and loging out... the same time should be
-
Hi Everyone, I am planning to setup the training /development environment for internal tarining/demo/pocs purpose. Can anyone tell me , does oracle provides any free environment/URL for the same (apart from the 30 day trial environment). Has anyone s