Query a table according to SYSTIMESTAMP for records within an interval
Hello ,
I am trying to query a table based on the systimestamp and taking two timestamp as intervals.Following is the query:
select * FROM MY_TBL where to_char(SYSTIMESTAMP,'YYYY-MM-DD HH24:MI:SS')
BETWEEN (to_char(SYSTIMESTAMP - INTERVAL '40' hour, 'yyyy-mm-dd HH24:MI:SS'))
AND (to_char(SYSTIMESTAMP - INTERVAL '16' hour, 'yyyy-mm-dd HH24:MI:SS'));
I am not getting any results.(no rows selected)
So i tried:
SELECT * FROM MY_TBL AS OF TIMESTAMP
to_date(to_char(SYSTIMESTAMP - INTERVAL '40' hour, 'yyyy-mm-dd HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS')
- to_date(to_char(SYSTIMESTAMP - INTERVAL '16' hour, 'yyyy-mm-dd HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS');
ERROR at line 3:
ORA-00932: inconsistent datatypes: expected TIMESTAMP got DATE JULIAN
Since TIMESTAMP is in a different format.I may be getting this error.How do i cast TIMESTAMP in the above query to map to the intervals.
Please let me know how to approach this issue.
Thanks in Advance,
Santosh
Thanks for the quick and prompt replies....
To provide a quick background.I am providing a daily report to my customer which is based on column (DATE type) in the table.But the records were inconsistent.Hence it was agreed that we get the report based on systime stamp.
Range is : between day-before-yesterday midnight(START_TIME) and yesterday midnight(END_TIME).A perl script runs the report at midnight 2 AM as cron .So i figure the interval can be :
(SYSTIMESTAMP - INTERVAL '40' hour) - It is 12 AM day before-yesterday-night if run at 2 AM - Interval 1
--------------------------------------------------------BETWEEN----------------------------------------------------------------------------
(SYSTIMESTAMP - INTERVAL '16' hour) - It is 12 AM day yesterday-night if run at 2 AM - Interval 2
SQL> select to_timestamp(to_char(SYSTIMESTAMP - INTERVAL '40' hour, 'yyyy-mm-dd HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS')START_TIME from dual;
START_TIME
08-JUN-09 06.43.59.000000000 PM
SQL> select to_timestamp(to_char(SYSTIMESTAMP - INTERVAL '16' hour, 'yyyy-mm-dd HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS') END_TIME from dual
2 ;
END_TIME
09-JUN-09 06.44.46.000000000 PM
How do i get the records for these two intervals.
Thankyou..
-Santosh
Similar Messages
-
Query a table and exit when first record found
I want to query a table and just want to know if any rows matching my query criteria exist in the table. I just want to find one row, irrespective of order and stop the query right there. How do I do that?
The most efficient way would be either to use rownum = 1 as part of the condition in your second query, but, as written, both will return multiple rows. Your first will need to have an additional predicate and rownum = 1 in addition to the exists.
Assuming that the predicate can use an index, then the most efficient approach would be either:
SELECT 1 FROM table
WHERE <conditions> and
rownum = 1or possibly:
SELECT 1 FROM dual
WHERE EXISTS (SELECT 1 FROM table
WHERE <conditions>)Both will do a range scan on the applicable index, stopping when the find the first matching entry. To my mind, the first is clearer in intent.
To illustrate the error in your first query, consider:
SQL> SELECT * FROM t;
ID DESCR
1 One
2 Two
3 Three
4 Four
5 Five
1 One
2 Two
3 Three
4 Four
5 Five
SQL> SELECT * FROM t
2 WHERE id = 1 and
3 rownum = 1;
ID DESCR
1 One
SQL> SELECT * FROM t
2 WHERE EXISTS (SELECT 1 FROM t
3 WHERE id = 1);
ID DESCR
1 One
2 Two
3 Three
4 Four
5 Five
1 One
2 Two
3 Three
4 Four
5 FiveJohn
Edited by: John Spencer on Oct 2, 2009 12:06 PM
Added queries from t -
SELECT query & Database Table Difference in number of records
Hi All,
In program it’s selecting 3 records based on selection parameters whereas when i execute SE16 with same selection criteria gives 4 records.
Please suggest when we will face these kind of issue
Thanks,
SpandanaSELECT objnr wlges
FROM bpge
INTO TABLE t_bpge
FOR ALL ENTRIES IN t_prps
WHERE lednr EQ c_0002
AND objnr EQ t_prps-objnr
AND wrttp EQ c_41.
Here t_prps-objnr has the following values
PR00473170
PR00397060
PR00397061
PR00397062
PR00397063
PR00397064
PR00397065
For this selection criteria there are 4 records in BPGE table where as the program is fetching only 3 -
Slow performance of Query-Large Table how to optimize for performance
Hi Friends,
I am an ORacle DBA and just recently I have been asked to Administer an ORacle HRMS Database as a substitute for the HRMS DBA who have gone on vacation.
I have been reported that few queries are taking a long time to refresh and populate the forms. After some investigation it is found that the tables: HR.PAY_ELEMENT_ENTRY_VALUES_F has some more than 15 million rows in it. The storage parameters specified for table r Oracle Defaults. The table has grown a lot big and even a Count(*) takes more than 7 mins to respond.
My question is: Is there anyway it can be tuned for better performance without an overhaul. Is it normal for this table to grow this big for 6000 employees data for 4 years....
Any response/help in this regard will be appreciated. U may please ans me at [email protected]
Thanks in Advance.
Rajeev.That was a good suggestion by Karthick_Arp, but there is a chance that it is not logically identical depending on the data (I believe that is the reason for his warning).
Try this rewrite, which moves T6 to an inline view and uses the DECODE function to determine if the one row returned from T6 should be used:
SELECT
ASSOC.NAME_FIRST || ' ' || ASSOC.NAME_LAST AS CLIENT_MANAGER
FROM
T1 ASSOC,
T2 CE,
T3 AA,
T4 ACT,
T5 CC,
(SELECT
CA.ASSOC_ID
FROM
T6 CA
WHERE
CA.COMP_ID = :P_ENT_ID
AND CA.CD_CODE IN ('CMG','RCM','BCM','CCM','BAE')
GROUP BY
CA.ASSOC_ID) CA
WHERE
CE.ENT_ID = ACT.PRIMARY_ENT_ID(+)
AND CE.ENT_ID = :P_ENT_ID
AND ASSOC.ID = DECODE(AA.ASSOC_ID, NULL, CA.ASSOC_ID, AA.ASSOC_ID)
AND NVL(ACT.ACTIVITY_ID, 0) = NVL(AA.ACTIVITY_ID, 0)
AND ASSOC.BK_CODE = CC.CPY_NO
AND ASSOC.CENTER = CC.CCT_NO
AND AA.ROLE_CODE IN ('CMG', 'RCM', 'BCM', 'CCM', 'BAE');Charles Hooper
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc. -
Query for records on a block with Query Data Source Type : Procedure
Hi All,
The veriosn of form I'm using is:
Forms [32 Bit] Version 6.0.8.23.2
I have a block based on a procedure.
But when I enetr-query and search for records specific to ceratin criteria even then the result of the Query is all records.
Is Query not allowed on a block with Query Data Source Type : Procedure.
Hope my question is clear.
Thanks in advance.
Regards
ArifWhen you use a table based block, forms can construct any select with any where clause based on the given inputs. Using a procedure based block, forms cannot "know" which in or out parameter of the procedure corresponds to which item. Even if Forms could pass the value of an item to an argument automagically, the procedure would have to "do something" with the argument, and you´d have to code it.
So, any item that should be used in the where-clause must be mapped to an argument.
Perhaps it would be easier to use a table based block querying a view? For DDL, you could use an instead-of-trigger on the view.
Regards,
Gerd -
Update Query is Performing Full table Scan of 1 Millions Records
Hello Everyboby I have one update query ,
UPDATE tablea SET
task_status = 12
WHERE tablea.link_id >0
AND tablea.task_status <> 0
AND tablea.event_class='eventexception'
AND Exists(SELECT 1 from tablea ltask where ltask.task_id=tablea.link_id
AND ltask.task_status = 0)
When I do explain plan it shows following result...
Execution Plan
0 UPDATE STATEMENT Optimizer=CHOOSE
1 0 UPDATE OF 'tablea'
2 1 FILTER
3 2 TABLE ACCESS (FULL) OF 'tablea'
4 2 TABLE ACCESS (BY INDEX ROWID) OF 'tablea'
5 4 INDEX (UNIQUE SCAN) OF 'PK_tablea' (UNIQUE)
NOW tablea may have more than 10 MILLION Records....This would take hell of time even if it has to
update 2 records....please suggest me some optimal solutions.....
Regards
MaheshI see your point but my question or logic say i have index on all columns used in where clauses so i find no reason for oracle to do full table scan,,,,
UPDATE tablea SET
task_status = 12
WHERE tablea.link_id >0
AND tablea.task_status <> 0
AND tablea.event_class='eventexception'
AND Exists(SELECT 1 from tablea ltask where ltask.task_id=tablea.link_id
AND ltask.task_status = 0)
I am clearly statis where task_status <> 0 and event_class= something and tablea.link_id >0
so ideal case FOR optimizer should be
Step 1)Select all the rowid having this condition...
Step 2)
For each row in rowid get all the row where task_status=0
and where taskid=linkid of rowid selected above...
Step 3)While looping for each rowid if it find any condition try for rowid obtained from ltask in task 2 update that record....
I want to have this kind of plan,,,,,does anyone know how to make oracle obtained this kind of plan......
It is try FULL TABLE SCAN is harmfull alteast not better than index scan..... -
Need help for record deletion from custom table
Hi friends
I have to write a custom program which will be generic to delete any table record with date field.
This program needs to be generic (should be able to delete records from any custom table) in nature with selection screen parameters as:
Table Name and Number of Days prior to which records are deleted, both mandatory.
Program Flow:
1. From number of days calculate date before which records are deleted, ( current date u2013 no. of days = past date).
2. Custom table have date field, delete records prior to that date.
3. Program may be scheduled for background job, put default values for both fields. No. of days should not be less than 60.
4. Classical Report output with number of records deleted.
My query is how will I know the name of the Date field so that I can write a DELETE query.
If I use 'DDIF_FIELDINFO_GET' it gives me all field names but how to filter out?
with regards
samikhyaHi
I have added field on the selection screen as p_fieldname and got the F4 help for it , so that the user will get the field name run time as per the table name.
Now I am facing problem while writing the DELETE query.
I wrote like
DELETE (fp_tab)
where (fp_fieldname) LE date
It is not working. I also tried with taking a string to concatenate fp_fieldname, LE and date to l_string
when I write like this:
DELETE (fp_tab)
where (l_string) , sy-subrc is getting 4 and no records are getting deleted.
I do not understand where the dynamic Delete is failing??
with reagards
Samikhya -
No record found in the table while using condition for the new added field
Hi,
I have added a new field in Z table. There is lots of record in the table. The field which I added have null records. When I am checking the record using the condition new field equal(EQ) to space or blank. This shows no record in the table, but when I execute whole of the table, it shows entries for all field.
Please suggest. Thanks in Advance.
Rgds,
Hemant MauryaHi Suhas,
Thanks for your quick response.
Yes I have run SE14 and activate & adjust the database, But problem is same.
My select query is:
SELECT VBELN
PI
GJAHR
KUNNR
GPD
GPI
INTO TABLE I_GP_DATA
FROM ZFI_GP_DISCOUNTS
WHERE AUGDT BETWEEN ZFI_GP_DISCOUNTS-AUGDT AND ZFI_GP_DISCOUNTS-P_DATE
AND DOC_NO EQ SPACE.
Thanks & Regards,
Hemant Maurya -
How to search in a table according to search criteria for many fields ??
Hello all,
I required any suggestion regarding easy method for searching a table according to search criteria.
I have 7 dropdown list in the userinterface and user can select 1 dropdown or many according to his choice. After selecting 1 or many dropdown list when he clicks SEARCH button the related records for filled dropdown list should be displayed if present in table. But the problem is that its getting complecated as I have to code for 7 dropdown list. many combinations comes in the way.
So can anybody tell me that how to getrid of this complicated process and is there any easy method for this...??
thanks,
SimadriHi.,
It wont get complicated., try this.,
Let us say you have 3 drop down lists., for ID, Name , Priority., now in OnActionSearch.,
DATA:RT_RANGES_ID TYPE RANGE OF ZDE_ID, " Data Element for ID
RS_RANGES_ID LIKE LINE OF RT_RANGES_ID,
RT_RANGES_NAME TYPE RANGE OF ZDE_NAME, " Data Element for Name
RS_RANGES_NAME LIKE LINE OF RT_RANGES_NAME,
RT_RANGES_PRI TYPE RANGE OF ZDE_PRIORITY, " Data Element for Priority
RS_RANGES_PRI LIKE LINE OF RT_RANGES_PRI.
*Read the Values in Drop down List using get_attribute( ).
now.,
*Appending ID to Range Table
if lv_id is not initial. " here lv_id is the drop down value in Drop Down List for ID
RS_RANGES_ID-OPTION = 'EQ'.
RS_RANGES_ID-LOW = lv_id. " appending ID
RS_RANGES_ID-SIGN = 'I'.
APPEND RS_RANGES_ID TO RT_RANGES_ID.
endif.
if lv_name is not initial.
RS_RANGES_Name-OPTION = 'EQ'.
RS_RANGES_NAME-LOW = lv_name. " appending Name
RS_RANGES_NAME-SIGN = 'I'.
APPEND RS_RANGES_NAME TO RT_RANGES_NAME.
endif.
if lv_priority is not initial.
RS_RANGES_PRI-OPTION = 'EQ'.
RS_RANGES_PRI-LOW = lv_priority. " appending Priority
RS_RANGES_PRI-SIGN = 'I'.
APPEND RS_RANGES_PRI TO RT_RANGES_PRI.
endif.
* Fetching Values for Selction Criteria
Select * from <TABLE> into lt_int_tab where ID IN RT_RANGES_ID
AND NAME IN RT_RANGES_NAME
AND PRIORITY IN RT_RANGES_PRI.
similarly You do for your 7 Drop Downs..
hope this helps u.,
Thanks & Regards,
Kiran -
Query is taking too much time for inserting into a temp table and for spooling
Hi,
I am working on a query optimization project where I have found a query which takes hell lot of time to execute.
Temp table is defined as follows:
DECLARE @CastSummary TABLE (CastID INT, SalesOrderID INT, ProductionOrderID INT, Actual FLOAT,
ProductionOrderNo NVARCHAR(50), SalesOrderNo NVARCHAR(50), Customer NVARCHAR(MAX), Targets FLOAT)
SELECT
C.CastID,
SO.SalesOrderID,
PO.ProductionOrderID,
F.CalculatedWeight,
PO.ProductionOrderNo,
SO.SalesOrderNo,
SC.Name,
SO.OrderQty
FROM
CastCast C
JOIN Sales.Production PO ON PO.ProductionOrderID = C.ProductionOrderID
join Sales.ProductionDetail d on d.ProductionOrderID = PO.ProductionOrderID
LEFT JOIN Sales.SalesOrder SO ON d.SalesOrderID = SO.SalesOrderID
LEFT JOIN FinishedGoods.Equipment F ON F.CastID = C.CastID
JOIN Sales.Customer SC ON SC.CustomerID = SO.CustomerID
WHERE
(C.CreatedDate >= @StartDate AND C.CreatedDate < @EndDate)
It takes almost 33% for Table Insert when I insert the data in a temp table and then 67% for Spooling. I had removed 2 LEFT joins and made it as JOIN from the above query and then tried. Query execution became bit fast. But still needs improvement.
How I can improve further. Will it be good enough if I create Indexes on the columns for the temp table and try.or what If I use derived tables?? Please suggest.
-PepHow I can improve further. Will it be good enough if I create Indexes on the columns for the temp table and try.or what If I use derived tables??
I suggest you start with index tuning. Specifically, make sure columns specified in the WHERE and JOIN columns are properly indexed (ideally clustered or covering, and unique when possible). Changing outer joins to inner joins is appropriate
if you don't need outer joins in the first place.
Dan Guzman, SQL Server MVP, http://www.dbdelta.com -
Search for records in a table on the basis of a function
Hi,
How is it possible to use a function as search criteria in a sql query ?
For example, I have the following query :
select a.job_name JOB_NAME, substr(a.job_name,instr(a.job_name,'.',-1)+1) as AUTNAME
FROM autosys.job a
where a.job_name like %PRD%' and a.command like '%dsjob%'
and a.command not like 'substr(a.job_name,instr(a.job_name,'.',-1)+1)';
This is now working because of the use of function "substr" on the right side of the query.
How can I write the query so as to find the same result as using this function ?
Can someone help me out on this ?
ThanksAmong other things, you have the quotes in the wrong place in the NOT LIKE predicate. As posted, you are searching for records where command does not contain the literal string substr(a.job_name,instr(a.job_name,'.',-1)+1). I don't think that is really what you are after. You need to concatenate the operators to the results of the SUBSTR function. Something more like:
SELECT a.job_name job_name,
SUBSTR(a.job_name, INSTR(a.job_name, '.', -1)+1) as autname
FROM autosys.job a
WHERE a.job_name LIKE 'HP.TM.%PRD.%' and
a.command LIKE '%dsjob.sh%' and
a.command NOT LIKE '%'||SUBSTR(a.job_name, INSTR(a.job_name, '.', -1)+1)||'%'; John -
The Connection String for the Query Log table is automatically encrypted.
When I try to use the Usage Based Optimization to apply Aggregation Design to my measure group, it shows me the following
error message.
The connection string cannot be found. Open Microsoft SQL Server Management Studio and, in the Analysis Server Properties
page, check the value of the Log\QueryLog\QueryLogConnectionString
property.
I encountered this error like two weeks ago. At that time I just reset the connection string and every things seem
to be fine. A week ago, I successfully applied the Usage Based Optimization for one of my cubes. However when I tried to apply UBO for my other cubes today, I encountered the same issue again! I believe no one has changed the property of
the connection string.
Also if I query the Query Log table, I can see those latest queries made by the users. I'm sure the queries are still
logging into this table.
This is really strange. Anyone else has encountered the same issue? Thanks.Hello Thomas,
I encounterd this issue. And I am struggling trying to solve this problem. If you have resolved this issue and I guess you must've, because this post is two years old, could you kindly post how you resolved this issue?
Thanks in advance
Best Regards,
Neeraja -
Hi
I have a aqm 8.5.2 server with uccx , we have configured diffrent workflow (Quality managemnt) and Archive workflow.
Now when a supervisor having AQM license , try to play the file it play as audio file and the reasin come on the portal for recording is "archive".
However the Evaluation button is greyed out and he was not able to evaluate the same .
Does that mean that archive calls cannot be evaluated.
And why this calls are going to archive state ..
Regards
RCHi
AQM needs to know the windows username of each user, as this is what ties the calls that are recorded back to a particular user when you are searching for calls etc.
If you had the same account for each user, it would appear that all calls were made by the same agent... so no, it's not really possible. The desktop software also detects who is logging on to the PC console, so it's not a matter of changing the account the service runs as.
You say you are not integrated to AD, but are you not using AD at all for your desktop PC logons?
Aaron -
Dear all,
I'm trying to create a query joining 2 tables: CATSDB and PROJ, because I want to visualize the project and the wbs at the same time according the working time recorded in cat2.
But when I execute the query doesn't appear any values. But if I create a query separately, i.e, table by table, the values appears without problems.
Please anyone can help me???
Thanks,
P.There should be Field/s that link these tables in order for you to create an infoset out of a table join.
e.g. PA0008 and PA0007 both have the field PERNR.
If there is no field common between the two, your query won't be extracting any data as you've experienced.
These two tables don't have any field that is common to both of them. Table join won't be possible. -
Query Locks Table in SQL Server 2000!!
Hi all!
I am facing a strange problem. I am using MS SQL Server 2000.
I have a JDBC program.It executes a query on a table (STUDENT) and fetches some record from it.
The query gets executed fine for the first time but when the SELECT query is executed on the same table (i.e. STUDENT) from some other block of code within the same program the program hangs at the location where resultset is pointed to the first record i.e. RS.next();
When I try to execute the SELECT query on the same table (i.e. STUDENT) from a query tool when the program is running it also gets hanged!!!
It seems that after running the query for the first time on the STUDENT table from the next time its getting hanged....i believe the Table gets locked for some reason!!
Is that normal with SQL Server 2000.....The same code works fine with other database!
Please suggest...wht has to b done to gt it fixed!
Thankz a loadz bforehand!
ArunBy default (transaction isolation level TRANSACTION_READ_COMMITTED ), SQL Server applies a shared read lock when you do a SELECT. This is should not prevent other selects on the same row / page but it will prevent updates / deletes.
I found a link that explains SQL Server locking: http://databasejournal.com/features/mssql/article.php/3289661
Maybe you are looking for
-
How to Position Identity Plate Overlay in Print Module?
When I print portraits, I want to include my name and date overlaying the portrait in the lower right hand corner. Currently I have to open the file in Photoshop and add this to the portrait. I saved the text information (name and date) in a transpar
-
Lables fully not visible in the Tree node
Hi friends, Some text in the tree node were not visible fully. example : instead of documentation, it just displays doc... instead of Library, it just displays lib.... And the problem doesn't appear continuously. Sometime the text is fully visible an
-
Actions and EEWB (Business Transactions)
Hi, I've extended a business transaction (service ticket) with 5 new fields using EEWB. I'm creating a new action to print out a letter. I want it to print only if one of the new fields is filled in. - The action works fine if I trigger it on a stan
-
Update group in credit management
Hi friends , can anybody please tell me what is the use of update group in credit management. regards shyam
-
Unable to update application from App Store
I bought a used mac mini and I was viewng the App Store and wanted to purchase IPhoto app but it was purchase previously and could not update because not associated with my Apple ID. The error message reads I would need to purchase it again My issu