Query needed for sorting by time value
Hi Folks
We have table it consists two columns like below
Job_name varchar2(50)
Scheduled_time date
The filed scheduled time keep date and time value like below
25-Jul-2009 4:00:10 AM
26-Jul-2009 4:00:01 PM
27-Jul-2009 4:00:00 PM
28-Jul-2009 4:05:00 PM
01-Jul-2009 4:06:00 PM
02-Jun-2009 4:15:40 AM
We need output as sorting by time value NOT date value. Expected output to be below
25-Jul-2009 4:00:10 AM
02-Jun-2009 4:15:40 AM
27-Jul-2009 4:00:00 PM
26-Jul-2009 4:00:01 PM
28-Jul-2009 4:05:00 PM
01-Jul-2009 4:06:00 PM
I am using oracle 10G
Thanks in Advance
Here's how :
SQL> create table job_table (job_name varchar2(50) not null, scheduled_time date);
Table created.
SQL> insert into job_table
2 values ('Job_abc',to_date('25-JUL-2009 04:00:00','DD-MON-YYYY HH24:MI:SS'));
1 row created.
SQL> insert into job_table
2 values ('Job_fdw',to_date('02-JUN-2009 04:15:40','DD-MON-YYYY HH24:MI:SS'));
1 row created.
SQL> insert into job_table
2 values ('Job_fxj',to_date('27-JUL-2009 03:59:00','DD-MON-YYYY HH24:MI:SS'));
1 row created.
SQL> insert into job_table
2 values ('Job_rjt',to_date('20-JUL-2009 14:59:00','DD-MON-YYYY HH24:MI:SS'));
1 row created.
SQL> commit;
Commit complete.
SQL> alter session set nls_date_format='DD-MON-YYYY HH:MI:SS AM';
Session altered.
SQL> select job_name, scheduled_time from job_table
2 order by to_char(scheduled_time,'HH24:MI:SS');
JOB_NAME SCHEDULED_TIME
Job_fxj 27-JUL-2009 03:59:00 AM
Job_abc 25-JUL-2009 04:00:00 AM
Job_fdw 02-JUN-2009 04:15:40 AM
Job_rjt 20-JUL-2009 02:59:00 PM
SQL>
Similar Messages
-
What is needed for sorting on two fields in a table control
Hi Everybody
I am going to certification in a couple of days. I need some help and was hopeing that you guys could help.
What is needed for sorting on two fields in a table control?
One sorted table and two processing blocks
Two standard tables and one processing blocks
Two standard tables and two processing
Which one is corret??
//ScriptHi Kimallan
I am not sure what is meant by a "processing block". However, it seems the question wants the original table order to be preserved. If so; as far as I understood the problem we need:
itab_proxy[] = itab_main[] .
"two standard tables"
SORT itab_proxy BY field1 field2 .
If we have a sorted table, then it is always sorted by its keys. So, the question seems to become obsolete for that option.
Hope I've understood correct...
Regards
*--Serdar
[email protected] -
BEx query needs to count unique characteristic values
Is there any way to build a query using BEx query designer to count the number of unique values of a characteristic. For instance, my cube has detailed transactions for claim information. Each claim number can have multiple products. My query need to show the number of claims that exist for each product. I don't want the detail of the claim number, just how many claims exist.
Product Gross Paid Loss Claim Count
Total Auto $ 43,865.01 ?
Total Property $ 4,068,321.57 ?
Not assigned 19,426Hi,
Creat calculated keyfigure with data functions Count value and save with technical name.
Right click on that go to propertes, select count with exception aggregation - Claim Number,
also use after aggregation and decimal places '0'.
Regards
Malyadri -
Can some help me please below query has been running for a long time I am unable to fix it
SELECT lmt.tab, pr.tab6, pr.tab7,
pr.activity_id, pr.resource_id, lmt.tab2,
lmt.tab5, pr.txn_lmt_trans_id, pr.analysis_type,
pr.resource_type, pr.resource_category, pr.resource_sub_cat,
pr.trans_dt, cd.start_dt, cd.end_dt, pr.currency_cd, pr.rt_type,
pr.resource_quantity, pr.resource_amount, pr.foreign_amount,
pr.foreign_currency, 2, 'S', pr.resource_id_from,
hdr.contract_sign_dt, cd.retainage_id, cd.discount_id, 0, 0,
cd.limit_bi_cntrl_flg, hdr.ca_rqst_src, 0, hdr.currency_cd,
hdr.rt_type, 0, 0, pr.bi_distrib_status, pr.gl_distrib_status
FROM ps_c1 lmt, ps_c2 hdr, ps_c3 cd,
ps_c4 pr
WHERE lmt.tab = 836626
AND hdr.tab2 = lmt.tab2
AND cd.tab2 = lmt.tab2
AND cd.tab5 = lmt.tab5
AND cd.pricing_structure = 'RATE'
AND pr.tab6 = cd.tab6_pc
AND pr.tab2 = cd.tab2
AND pr.tab5 = cd.tab5
AND (pr.analysis_type IN ('BIL', 'OLT', 'PMR', 'ROL')
AND pr.bi_distrib_status <> 'I'
OR pr.analysis_type = 'REV'
AND pr.gl_distrib_status IN ('C', 'N'))
AND NOT pr.ca_fee_status IN ('2', '3', '4', '5')
AND 0 >= (SELECT count(*)
FROM ps_ca_lmt4_tao4 lmt4
WHERE lmt4.tab = 836626
AND lmt4.tab6 = pr.tab6
AND lmt4.tab7 = pr.tab7
AND lmt4.activity_id = pr.activity_id
AND lmt4.resource_id = pr.resource_id))
Below is the execution plan
ID PID Operation Name Rows Bytes Cost CPU Cost IO Cost Temp space IN-OUT PQ Dist PStart PStop
0 SELECT STATEMENT 2 598 99885 2G 99823
1 0 NESTED LOOPS
2 1 NESTED LOOPS 1 299 99885 2G 99823
3 2 NESTED LOOPS 1 264 99883 2G 99821
4 3 NESTED LOOPS 3 273 8 114779 8
5 4 INDEX RANGE SCAN ps_c1 6 138 1 8321 1
6 4 TABLE ACCESS BY INDEX ROWID ps_c3 1 68 2 17743 2
7 6 INDEX UNIQUE SCAN ps_c3 1 1 9021 1
8 3 TABLE ACCESS BY INDEX ROWID ps_c4 1 173 33292 671M 33271
9 8 INDEX RANGE SCAN ps_c4 55808 10139 320M 10129
10 9 INDEX UNIQUE SCAN PS_CA_LMT4_TAO4 1 46 0 1050 0
11 2 INDEX UNIQUE SCAN ps_c2 1 1 9021 1
12 1 TABLE ACCESS BY INDEX ROWID ps_c2 1 35 2 17413 2
Can someone please help its really kind of urgentcheck the cardinalities: the CBO expects to access only a few rows and uses a lot of NL joins - and that's probably not the best solution. You could start with a llok at the cardinality of step 5, the index range scan on ps_c1. The CBO expects only 6 rows - is this a good guess? Of course you could just create a plan with rowsource statistics (gather_plan_statistics hint) and compare E- and A-rows.
-
QUERY NEED FOR TIME DIFFERENCE
Hi
I need a query to find the difference between time
for example
5.00 hours - 0.30 minutes = 4.30 hours
Thanks in Advance
AdinaIs this what you are looking for -
1 select to_date('05:00', 'hh24:mi') - 0.5/24 --Subtract ½ Hr from time
2* from dual
SQL> /
TO_DATE('05:
200804010430
1 select to_date('05:00', 'hh24:mi') - 3/24 --Subtract 3 Hrs from time
2* from dual
SQL> /
TO_DATE('05:
200804010200
1 select to_date('05:30', 'hh24:mi') + 0.5/24 --Adds ½ Hr to the time
2* from dual
SQL> /
TO_DATE('05:
200804010600
1 select to_date('20080416 00:02', 'yyyymmdd hh24:mi') - 0.5/24 --Subtract ½ Hr from time 2* from dual
SQL> /
TO_DATE('200
200804152332Shailender Mehta -
Query Needed for Partitioning table
Hi,
I have created a table called Test. There is a column named business_name.
There are several businesses like ABC,BCD,ADE....
There will be lakhs of rows corresponding to each business, i mean there will be lakhs of entires corresponding to ABC,BCD....
So i like to partition the table according to business_name so that the search will be more faster.As we had partitioned according to the business_name, i hope we need to search only on the partition corresponding to the particular business.
can any one provide the Query to partition the table ' TEST ' according to the column ' business_name ' .
Also can anyone provide Query to modify the already existing table ' TEST ' to incorporate partition for the column ' business_name '.We can partiton a table by the following
create table Generalledger (
record_id number,
business_name varchar2(3)
sales_dt date,
amount number(10)
partition by list (business_name)
partition ct values ('ABC'),
partition ca values ('BCD'),
partition def values (default)
But if we dont know the values like 'ABC' , 'BCD'
....how can we do the partitionuse SQL to generate part (or all) of your DDL statement. The following will output one partition statement for each business_name:
SELECT DISTINCT 'partition p_' || BUSINESS_NAME || ' values (''' ||
BUSINESS_NAME || '''),'
FROM GENERALLEDGER; -
Hi All,
Following is the query which is working for aging for condition and round(st.close_dt - st.open_dt) >60 and corresponding column output count(round(st.close_dt - st.open_dt)) ">60" but we need the same in report of column of
count(round(st.close_dt - st.open_dt)) "<15"
count(round(st.close_dt - st.open_dt)) "16 to 30"
count(round(st.close_dt - st.open_dt)) "31 to 45"
count(round(st.close_dt - st.open_dt)) "45 to 60"
which is based on condition round(st.close_dt - st.open_dt) <15
round(st.close_dt - st.open_dt) between 16 and 31
round(st.close_dt - st.open_dt) between 31 and 45
round(st.close_dt - st.open_dt) between 46 and 60
but we can't use this all condition at a time as individual it is working fine.
Could you please let me know how we can user this all in one so the I can get the output at a time <15, 16 to 30, 31 to 45, 46 to 60 and >60.
{select count(round(st.close_dt - st.open_dt)) ">60"
from stat.csr_master_tbl m,
stat.customers c,
stat.proj_csrs p,
stat.appl_type ap,
stat.csr_type_cd tp,
stat.csr_status st,
stat.csr_status_cd sc,
stat.wrkflw_defn w
where m.cust_id = c.cust_id
and m.csr_id = p.csr_id (+)
and m.sd_cd = p.sd_cd (+)
and m.appl_cd = ap.appl_cd
and m.sd_cd = ap.sd_cd
and m.sd_cd = tp.sd_cd
and m.csr_type = tp.csr_type_cd
and m.sd_cd = st.sd_cd
and m.csr_id = st.csr_id
and st.csr_status_cd = sc.csr_status_cd
and st.sd_cd = sc.sd_cd
and tp.csr_type_cd = sc.csr_type_cd
and m.wrkflw_id = w.wrkflw_id
and (m.sd_cd in ('11i','AVA') or (m.sd_cd in ('STR') ))
and ( st.close_dt between to_date(:beg_date,'MM/DD/YYYY') and to_date(:end_date,'MM/DD/YYYY')
or st.closed_status_flag <> 'Y')
--and sc.descr <> 'Cancel'
AND sc.descr IN ('Close')
and p.proj_cd='OAPS'
and round(st.close_dt - st.open_dt) >60
and tp.descr in ('Break-Fix Datafix'
,'Break-Fix Configuration'
,'Break-Fix Development'
,'Vendor Patch')
and c.first_name in ('Springville'
,'Cookeville'
,'Bangalore'
,'Deer Park'
,'Sulphur Springs'
,'P11i'
,'Singapore'
,'Bangalore Chemical'
,'Baton Rouge'
,'Kaohsiung'
,'Bangalore Controls'
,'Damam'
,'Dayton Foundry'
,'Edmonton'
,'Jebel Ali'
,'Melbourne'
,'Philadelphia')}You might try something like
select
sum(case when round(st.close_dt - st.open_dt) < 15 then 1 else 0 end) "< 15", -- shouldn't it be <=15?
sum(case when round(st.close_dt - st.open_dt) between 16 and 30 then 1 else 0 end) "16 to 30",
...and you should have posted this question in the PL/SQL forum.
Edited by: UW (Germany) on 17.08.2012 12:15 -
Help needed for sorting contacts
Long time User of Treos (Palm Versions) and I just purchased Treo 800W. Love the speed and versatility however having problem sorting out contacts. In the Palm Versions, I was allowed to use sub folders in my outlook however when contacting the help desk, I was notified I have to put my all my contacts in one folder (Contacts). Needless to say when you have many contacts you will not be able to find them efficiently. Need help in the best way to sort out contacts and have them filed accordingly. Please advise and thanks.
Post relates to: Treo 800w (Sprint)Hi .. Welcome to Palm forums. In contacts on the 800w there is a option for catagories. You can create different catagories as you wish. You can also do the same in outlook. Then on the device you will find a filter option and when selected will show only the catagory you select at the time, for instance business. Now for searching if you type in the entire name it will take a long time to find the contact if it ever does. The way to search is to enter the first initial space last initial. To further specify you can add additional initials ie, first initial space last two initials.
Post relates to: Centro (Sprint) -
Query needed for Cumulative data
HI Friends,
I need output like this.
Frequency Percent (%) Cumulative
Frequency Cumulative Percent
4468 0.91 4468 0.91
21092 4.31 25560 5.23
57818 11.82 83378 17.05
6274 1.28 89652 18.33
I am using Oracle 9i.
My output data like this and I need to write the query for 3 columns (Percent ,Cumulative frequency and Cumulative percent)
1:The formula for Percent column data is (Frequency/Sum of cumulative frequency)*100
2:The formula for Cumulative Frequency column data is (Cumulative of Frequency column data)
3:The formula for Cumulative Percent column data is (Cumulative of Percent column data)
What should be the analytic function and how to write the query.
Thanks,
LonyHi Friends,
I need output like this.
Frequency Percent (%) Cumulative Frequency Cumulative Percent
4468 0.91 4468 0.91
21092 4.31 25560 5.23
57818 11.82 83378 17.05
6274 1.28 89652 18.33
I am using Oracle 9i.
My output data like this and I need to write the query for 3 columns (Percent ,Cumulative frequency and Cumulative percent)
1:The formula for Frequency column data is sum of (dd+cc+mc_cc_mc).
1:The formula for Percent column data is (Frequency/Sum of cumulative frequency)*100
2:The formula for Cumulative Frequency column data is (Cumulative of Frequency column data)
3:The formula for Cumulative Percent column data is (Cumulative of Percent column data)
What should be the analytic function and how to write the query.Please find the sample data and table script.
CREATE TABLE all_lony (
campno varchar2(20),
dd INTEGER,
cc INTEGER,
mc INTEGER,
cc_mc INTEGER
insert into all_lony (campno,dd,cc,mc,cc_mc)
values(36,156,1320,445,2547);
insert into all_lony (campno,dd,cc,mc,cc_mc)
values(40,233,19711,263,885);
=============
Please find my query below
SELECT campno
|| ','
|| dm
|| ','
|| cc
|| ','
|| mc
|| ','
|| cc_mc
|| ','
|| frequency
|| ','
|| per
||','
||cumulative_fr
||','
|| SUM (per) OVER (ORDER BY per ROWS UNBOUNDED PRECEDING)
FROM (SELECT q3.campno campno, q3.dm, q3.cc, q3.mc, q3.cc_mc,
q3.frequency, q3.cumulative_fr,
(q3.Frequency / SUM (q3.cumulative_fr)) * 100 per
FROM (SELECT q2.campno campno, SUM (q2.dm) dm, SUM (q2.cc) cc,
SUM (q2.mc) mc, SUM (q2.cc_mc) cc_mc,
(SUM ( NVL (q2.dm, 0)
+ NVL (q2.cc, 0)
+ NVL (q2.mc, 0)
+ NVL (q2.cc_mc, 0)
) frequency,
SUM (SUM ( NVL (q2.dm, 0)
+ NVL (q2.cc, 0)
+ NVL (q2.mc, 0)
+ NVL (q2.cc_mc, 0)
) OVER (ORDER BY SUM ( NVL (q2.dm, 0)
+ NVL (q2.cc, 0)
+ NVL (q2.mc, 0)
+ NVL (q2.cc_mc,0)
) ROWS UNBOUNDED PRECEDING)
cumulative_fr
from all_lony
q1 )q2
GROUP BY q3.campno) q3
GROUP BY campno, dm, cc, mc,cc_mc, frequency,cumulative_fr)
Can anybody just verify the query and let me know. -
Query needed to find what time a sales order was closed
Hi to All,
Need to find when a sales order was closed. Meaning the exact time. I know the flags that needed to be considered. But what table/column holds the exact time that the sales order was closed.
ThanksIf your workflow process details are not purged below query end_date will be order closed date.
select a.instance_id
, to_char(b.begin_date, 'DD-MON-RR HH24:MI:SS') begin_date
,to_char(b.end_date, 'DD-MON-RR HH24:MI:SS') end_date
, a.process_name process
from wf_process_activities a, wf_item_activity_statuses b
where b.item_type = 'OEOH'
and b.item_key in (select to_char(header_id) from oe_order_headers_all where order_number = <Ordrer_num>)
and a.process_name = 'CLOSE_HEADER_PROCESS'.
and b.process_activity = a.instance_idIn R12 if you do not have any customizations ,
Current close process defines wake up time as last day of month, there is no time component.
So order will be eligible from midnight of the last day of the month.
First run of Workflow background process program for item type OEOH should be closing them.
For example : If the Wait activity in 'Close - Order' process encountered first time on 09-May-2013(Any time in the month of May), then Wake up time will be last day of current month I.e. 31-May-2013 00:00. -
Approval Query needed for AR Reserve Invoice
Need to create an approval for delivery doc- If AR reserve invoice not paid need to triger an approval. how can I cutomise the query to look at base document.
SELECT DISTINCT 'TRUE' FROM OINV T0 WHERE T0.[isIns] = 'Y' AND T0.[DocStatus] <> 'C'
Thanks and RegardsHi Anoop,
This one should do it I believe. I have attachde the query as not everything gets copied in this forum. The query below will not work.
SELECT distinct 'true' FROM DLN1 T0 WHERE T0.[BaseType] = 13 and $[$38.45.1] in (SELECT docentry FROM OINV T0 WHERE isins = 'Y' and paidtodate <> doctotal)
There are a few limitations with approvals in B1 that are based on values on the linelevel like this one.
The query can not see past the first line of the document. So it will only check the basedoc of the first item in the Delivery (it is possible to add an item on the first line after copying the Reserve Invoice details into the delivery).
Apart from that, the query only checks if the payment have been fully done "(paidtodate <> doctotal)", if it has been partially paid it will still trigger the approval. If partial payment is acceptable you can change that to "paidtodate <> 0".
Hope it helps,
Jesper -
How big a hard drive do I need for iMac and Time Machine?
Sorry if this has been answered elsewhere already. I am going to buy an iMac, probably the new 24" with a 320G internal HDD. I already have one Lacie external 320G HDD so I was wondering whether I can use this for Time Machine backups, or do I need to buy a bigger one? If so, how big? Is there a rule of thumb for working out how much hard drive space you need to have for Time Machine, for instance if I were to buy the 500G iMac what would I need?
thanks.I agree with the "double the size" rule of thumb. You should also consider how much of the 320GB you are actually using and are likely to use in the next year or two. After all, it's the amount of storage you use that matters, not the size of the disk. Disks will very likely be cheaper soon. You should also keep in mind that TM deletes old archive data when it runs out of disk space. So as long as you have more disk space than you have data to back up, TM will work, though you will lose older versions of your data.
So if your 320GB drive only has 100GB used and you're not the kind of person who eats up disk like there's no tomorrow, the 320GB drive should be fine for now. If you expect that 320GB disk to be full soon then a 750GB TM disk is more like what you need.
The same logic applies to a 500GB iMac. If you only expect to use 250GB in the next year or two then a 500GB TM disk should be OK. A 1TB drive will be a lot cheaper next year or the year after. -
Insert query waiting for in-definite time.
Hi all,
I had a serious problem in my system.
My application gets stuck when trying to insert a huge xml message in a table blob. Usually there is no problem, the insert query goes into wait state just around or after the gather stats running on this table ends.
The table is partitioned one and around 150Gb in size.
I have seen in toad the wait event for this insert query is SQL* net more data from client.
This might be something related to RBS usage of this stuck insert query - in toad the RBS usage start time is same as the end time of gather stats.
But i m unable to figure out why the insert is stuck just after the gather stats ends, i have simulated this issue many times. My oracle version is 9.0.8.
Could somebody help to figure out why this is happening...?My oracle version is 9.0.8.I doubt this is correct.
Post Operating System (OS) name & version for DB server system.
Post results of SELECT * from v$version.
Now CUT the commands & results & PASTE (post) them back here.
ALTER SESSION SET SQL_TRACE=TRUE;
-- invoke the problem SQL here
ALTER SESSION SET SQL_TRACE=FALSE;
now find the trace file within ./udump folder
tkprof <trace_file.trc> trace_results.txt explain=<username>/<password>
post the contents of trace_results.txt back here
when application "gets stuck" run the following SQL from different session
SELECT DECODE(request,0,'Holder: ','Waiter: ')||sid sess,
id1, id2, lmode, request, type
FROM V$LOCK
WHERE (id1, id2, type) IN
(SELECT id1, id2, type FROM V$LOCK WHERE request>0)
ORDER BY id1, request
/ -
Query Alert for a change in value of the Quantity field of the sales order
Hi Experts,
A query alert has been set up to alert the warehouse employee when a new sales order is created by a sales employee. Our client wants the warehouse employee alerted when the sales employee edits the quantity field of an already added sales order.
Kindly assist in designing a query to notify of this change in the Quantity field of the sales order.
DavidTry this one:
SELECT T0.DocNum, T0.CardCode, T1.ItemCode, T3.Quantity 'Old Qty', T0.Quantity 'New Qty', MAX(T2.LogInstanc) 'Times Changed'
FROM dbo.ORDR T0
INNER JOIN dbo.RDR1 T1 ON T1.DocEntry = T0.DocEntry
INNER JOIN dbo.ADOC T2 ON T2.DocNum = T0.DocNum AND T2.ObjType = '17'
INNER JOIN dbo.ADO1 T3 ON T3.DocEntry = T2.DocEntry AND T3.ItemCode = T1.ItemCode
WHERE T0.DocStatus = 'O' and T0.DocType = 'I' AND T1.Quantity != T3.Quantity
GROUP BY T0.DocNum, T0.CardCode, T1.ItemCode, T1.Quantity, T3.quantity -
CREATE TABLE COUNTRIES(CID INT,CNAME VARCHAR(100))
INSERT INTO COUNTRIES VALUES(1,'AUSTRALIA')
INSERT INTO COUNTRIES VALUES(2,'INDIA')
INSERT INTO COUNTRIES VALUES(3,'FRANCE')
INSERT INTO COUNTRIES VALUES(4,'BERLIN')
SELECT * FROM COUNTRIES
o/p
CID CNAME
2 INDIA
1 AUSTRALIA
4 BERLIN
3 FRANCE
here India should be always first position remaining countries values should be in sorted orderYou can use a conditional sorting =>
SELECT *
FROM COUNTRIES
ORDER BY CASE WHEN CNAME = 'INDIA'
THEN 0
ELSE 1 END,
CNAME
Olaf Helper
[ Blog] [ Xing] [ MVP]
Maybe you are looking for
-
Configure or disable CLDC/MIDP?
I'm having a hard time using java applications on my Nokia XpressMusic 5130. The problem being everytime the app tries to read/write from flash or SD, or connect to the internet via GPRS, this pop-up keeps telling me "Would you like to grant this app
-
Where are the group calendars stored?
I had a server crash and have been restoring info from the old server drive. I have everything working perfectly and restored except the group calendars. thought they would just restore with the wiki. anybody know where the files are stored?
-
Ever since I enabled I-phone Radio, it interferes with my use of regular playlist option s
Ever since I enabled I-phone Radio, the icons turned red & whenever I choose any of my purchased songs, an error pop-up appaers telling me my song does not have radio station creation options. Indeed, now I do not even see meny options for browsing
-
No Audio in the timeline and no sound as well using CS4
We have installed CS4 Premiere Pro. When we imported a video clip, there was an error message "audio conforming error". the image part showed up but there was nothing (no sound, no wave length on the timeline). We can work on this video file on CS3 v
-
To what extent can customer's access usage records?
We all know that Verizon maintains extensive records on the usage of phones. To what extent can the actual customer access the information Verizon stores about the usage of his device?