Doubt in Timestamp column
Hi,
In below Query i am trying to retrive the data
,which is greater then the 18-DEC-10,
But its retriving all the datas,why? please help.how to handle this time stamp column?
desc vcps_misc_ch
Name Null Type
ENT_NM NOT NULL VARCHAR2(30)
ATRBT_NM NOT NULL VARCHAR2(30)
TXN_TYPE NOT NULL CHAR(1)
TXN_DT NOT NULL TIMESTAMP(6)
PREV_VALUE VARCHAR2(4000)
CURR_VALUE VARCHAR2(4000)
LAST_UPDT_GMIN VARCHAR2(9)
LAST_UPDT_NM VARCHAR2(4000)
REF_ID NOT NULL VARCHAR2(2000)
SELECT txn_dt,to_char(txn_dt,'dd-mon-yy hh24:mi:ss')
FROM vcps_misc_ch
WHERE to_char(txn_dt,'dd-mon-yy hh24:mi:ss') > TO_CHAR(TO_date('18-DEC-10','DD-MON-YY'),'dd-mon-yyyy hh24:mi:ss')
and rownum<10
TXN_DT TO_CHAR(TXN_DT,'DD-MON-YYHH24:MI:SS')
26-FEB-10 01.14.43.055154000 PM 26-feb-10 13:14:43
25-MAR-10 05.23.35.601172000 PM 25-mar-10 17:23:35
26-MAY-10 08.12.40.106995000 AM 26-may-10 08:12:40
27-MAY-10 10.38.32.033523000 AM 27-may-10 10:38:32
28-MAY-10 11.40.23.313450000 AM 28-may-10 11:40:23
28-MAY-10 01.09.52.332828000 PM 28-may-10 13:09:52
18-JUN-10 02.44.37.614339000 PM 18-jun-10 14:44:37
18-JUN-10 02.46.47.141109000 PM 18-jun-10 14:46:47
24-JUN-10 10.45.43.814528000 AM 24-jun-10 10:45:43
9 rows selected
Hi,
Always compare TIMESTAMP columns to other TIMESTAMPs.
To compare a TIMESTAMP column to a value that is being supplied as a string, convert the string to a TIMESTAMP, not the other way around. It's more efficient, and less prone to error.
For example:
SELECT txn_dt
, to_char (txn_dt,'dd-mon-yy hh24:mi:ss')
FROM vcps_misc_ch
WHERE txn_dt >= TO_TIMESTAMP ( '18-DEC-2010 14:45:00'
, 'DD-MON-YYYY HH24:MI:SS'
;or
SELECT txn_dt
, to_char (txn_dt,'dd-mon-yy hh24:mi:ss')
FROM vcps_misc_ch
WHERE txn_dt >= TO_TIMESTAMP ( p_date
, 'DD-MON-YYYY HH24:MI:SS'
Do not nest conversion functions (such as "TO_CHAR ( TO_TIMESTAMP ...)"). There's almost always a simpler, more efficient way.
TO_CHAR is appropriate for displaying a date (as in the SELECT clause above). If you're tempted to use TO_CHAR for any other purpose (in a WHERE clause, for example), ask yourself why.
Similar Messages
-
Doubt handling Clob columns with Java JDBC api
Hi,
we have a doubt handling Clob columns with Java JDBC api.
Reading Oracle 10g official documentation (document b10979.pdf, page 236), we found this note:
============================================
To write LOB data, the application must acquire a write lock on the LOB object. One way to accomplish this is through a SELECT FOR UPDATE. Also, disable auto-commit mode.
============================================
We also found a java sample code about how to handle Lob objects at this URL:
http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/LOBSample/LOBSample.java.html
In our java2 application, we access Clob objects in a quite different
manner: we use normal setString() and getString() methods, as described into paragraph "Shortcuts For Inserting and Retrieving CLOB Data"
(document b10979.pdf, page 244).
Using those methods, we never lock the table row by a SELECT FOR UPDATE statement (as described into the note above). We use simply SELECT, UPDATE and INSERT prepared statement.
In this way we can insert both clob objects and normal timestamp, number and other types with a single insert statement. Idem for update.
To recap, our question is:
Is it mandatory to create a SELECT FOR UPDATE statement when updating clob data? What may be the consequences if we don't use it? It is also correct to insert with a single sql statement both clob and not clob data using the setString() method for the clob types? And more than one lob column in the same record?
bye,
luca acri.And columns of type FLOAT. These also have, for some unknown reason a metadata type of OTHER, and a type string of 'FLOAT'. Yet PreparedStatement.setNull(x, Types.OTHER) doesn't work and setNull(x, Types.DECIMAL) does.
-
Get millisecond values from timestamp column in v$logmnr_contents
Hello
How do we get millisecond values from timestamp column in v$logmnr_contents.
I tried with following query.
select scn,To_Char(timestamp,'DD-MON-YYYY HH24:MI:SS:FF') from v$logmnr_contents WHERE OPERATION NOT IN('START') and username ='SCOTT' and sql_redo is not null and (seg_owner is null or seg_owner not in('SYS'));
it says ORA-01821: date format not recognized. I want to find the relation of scn with timestamp. In forums i found, scn is derived from timestamp value. I dont know its correct or not.
if i query with out FF in time format i get like
scn timestamp
808743 27-NOV-2007 00:12:53
808743 27-NOV-2007 00:12:53
808743 27-NOV-2007 00:12:53
808744 27-NOV-2007 00:12:53
808744 27-NOV-2007 00:12:53
808744 27-NOV-2007 00:12:53
if scn is derived from timestamp with milliseconds, each scn should be different right?More help pleaseMay be there's an easy way solving your problem, I did it like that:
CREATE TABLE quota_test (test VARCHAR2(50))
INSERT INTO quota_test
VALUES ('update "SCOTT"."NEWTAB1" set a="34" and b="45"')
SELECT test normal, REPLACE(SUBSTR(test,INSTR(test,'"',1),INSTR(test,'.',1)+2),'"','') changed
FROM quota_test
Result is :
NORMAL
update "SCOTT"."NEWTAB1" set a="34" and b="45"
CHANGED
SCOTT.NEWTAB1
If you didn't understand, I can explain what I wrote -
How to create a default value of timestamp column?
I am trying to create a table with a default value on a timestamp column, can it be done?
CREATE TABLE myTbl
FutureDateTime date default TIMESTAMP WITH TIME ZONE '2999-12-31 23:23:59.000'
)user1035690 wrote:
I am trying to create a table with a default value on a timestamp column, can it be done?
CREATE TABLE myTbl
FutureDateTime date default TIMESTAMP WITH TIME ZONE '2999-12-31 23:23:59.000'
)Yes, but you don't have a timestamp column, you have a date column.
CREATE TABLE myTbl
FutureDateTime date default to_date('2999-12-31 23:23:59', 'yyyy-mm-dd hh24:mi:ss')
4 );
Table created.
Elapsed: 00:00:00.09
ME_XE?And just in case you weren't aware, storing "end of time" information like this will be rough on your queries (it skewes the cost based optimizers estimates for cardinalities and could wildly throw off the estimates for your queries, resulting in bad plans). You're better off to store NULL values, NULL denoting not known values.
Just an FYI :) -
How to get data with out having any date/timestamp columns by year wise
hi,
how can i select years wise rows from tables,if that have not any date/timestamp column.Well Govind it quite depends on what is the data type of that column and the format in which it is stored.
If the data type is varchar2/varchar and all the values are in a uniform format then there is no problem. All you need to use is the to_date function to convert the supplied strings to default date format and then use to_char function to only extract the YY or YYYY or RR or RRRR aspect of the data.
For example: If the column is called 'hire_date' and it's data type is varchar2 and the entries in this column are all in a uniform format, say month,date,year like January,12,1999. What you need to do is convert this string to a default date value using to_date function, like to_date(hire_date,'format_model') In the format model mention the format of the hire_date string. The out put of this function can be fed into to_char to extract the year, like to_char(output_of_to_date,'YYYY')
I hope you got what I meant. Let me know if it was of any use. -
ORDER BY timestamp column as a string
Does any one have any tips/tricks for using an ORDER BY clause for a timestamp column that is a string?
I am developing a UNION query that combines data from a table and an audit history table to show current data plus historical data.
I had to convert the timestamp column to a string so the datatypes would match for the UNION query, but now they ORDER BY clause does not work.
For example:
SELECT
location,
'CURRENT' as VALID_DATE
FROM
person
UNION
SELECT
location,
TO_CHAR(audit_date)
FROM
person_audit
ORDER BY 2 DESCHi,
user2269823 wrote:
Using the 'yyyy-mm-dd' format works pretty well when ordering by the string. It looks like when ordering by a string Oracle just looks at the characters sequentially.
For example:
2009-1-14
2008-12-31
2007-6-6Looks like you have changed the format slightly?
Consider this
SQL> select TO_CHAR(sysdate,'FMyyyy-mm-dd')
, TO_CHAR(sysdate, 'yyyy-mm-dd') from dual;
TO_CHAR(SY TO_CHAR(SY
2009-5-28 2009-05-28
SQL>Looks fine with me, as long as you don't have the FM format model modifer.
Regards
Peter -
Bug: Timestamp columns don't work in automatic row processing
It appears that automatic row processing doesn't work with timestamp columns. Here is the scenario:
- I have a view that contains a timestamp column
- I create an automatic row processing process that reads a row from this view
- I create a hidden item with a source type of "Database Column" and set its source value to the name of the timestamp column.
- The value of the hidden input is empty, i.e. value=""
I found that, as a workaround, if a change the view to convert the timestamp to a string (e.g. SELECT TO_CHAR(LAST_MODIFIED) LAST_MODIFIED rather than SELECT LAST_MODIFIED), it works correctly.
Adding a format mask or doing the conversion in a "post calculation computation" (e.g. TO_CHAR(:P34_LAST_MODIFIED)) doesn't work.Later on in my exploration I found that some of the text boxes on the Keynote inspector were not accepting text, and so I couldn't even change the transition time for a slide. That prompted a restart of the program and that also seems to have solved the problem where the inspector wasn't accepting input for the columns and gutter. It's working now. So watch out for that. No idea what was at the root of it, which is annoying.
-
Partitioning on timestamp column
Has anybody ever used a range partition on a timestamp column.
For data columns my parition looks like this:
PARTITION P_2011_02_15 VALUES LESS THAN (TO_DATE(' 2011-02-16 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
can somebody provide the syntax for the followig Timestamp , Timestamp with time zone , timestamp with local time zone
Thankssb92075 wrote:
Has anybody ever used a range partition on a timestamp column.no, because it is just plain silly.
Most (sane & reasonable) folks partition down to DAY.Smallest partitions we have (in terms of time range), is hourly. Up to 50 million rows in such a single hourly partition...
But I agree - in principle. Finer grain range partitions down to minutes or even seconds...? That is very unlikely.
Unless the question is whether the partition range (for a daily partitioned table for example) can be on a column that is not a DATE data type, but a TIMESTAMP data type. In which case the answer is yes - the data type in this case does not prevent a partition range definition. -
SSDT tries to alter timestamp column in TFS build
We're trying to perform an upgrade test against a copy (backup/restore) of our customer database as target. There are some tables with timestamp column in the database. The way we do this is by having a database project with a publish profile targeting
that copy of customer database and then with TFS build server is used to build the database but only to generate a publish script (/p:UpdateDatabase=False) set in the build definition - msbuild argument.
Example of table definition:
CREATE TABLE dbo.CodeTable1
(ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY
,Code CHAR(6)
,[Timestamp] TIMESTAMP NULL);
We would like to have the "Code" column to have CHAR(7), so in the project we modify the table definition:
CREATE TABLE dbo.CodeTable1
(ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY
,Code CHAR(7)
,[Timestamp] TIMESTAMP NULL);
Expecting SSDT build will generate alter script:
ALTER TABLE dbo.CodeTable1 ALTER COLUMN Code CHAR(7);
To our surprise the generated script was:
ALTER TABLE dbo.CodeTable1 ALTER COLUMN Code CHAR(7);
ALTER TABLE dbo.CodeTable1 ALTER COLUMN [Timestamp] TIMESTAMP NULL;
Which will cause error when the script is executed: "Cannot alter column 'TIMESTAMP' to be data type timestamp."
Why is SSDT generating the change script for that timestamp column??
We then try a local build in VS, the issue is not happening, SSDT correctly generates alter script only for the "Code" column to CHAR(7);
Both local machine and TFS Build server are having VS 2013 Update 4- SSDT 12.0.50318.0 installed.
As we tried to troubleshoot further, we found out that it seems it only happens on a restored database from a backup copy of our customer database. It doesn't happen for databases created by SSDT build from scratch or that we manually created. We've tried make
sure all database properties are the same as the database that correctly built. But still if the target database is the one we restored from a customer's copy, SSDT always tries to alter timestamp column (on server build).
Anyone have same experience?
I have posted a bug in ms connect: https://connect.microsoft.com/SQLServer/feedback/details/1266051
Thanks!Thanks Paul!
However, it doesn't happen when I build the database project locally or if the target database was created by SSDT (or manually for that matter). The issue happens when I change the target database to the one we restored from a backup copy of our customer's
database and run the build through our TFS build server.
So I thought there must be something different with the restored database (which causes SSDT to alter timestamp column) as opposed to the one SSDT/manually created (which doesn't alter the timestamp column). Maybe there is difference on database property/settings?
Whatever it is, I just couldn't find it.
The only thing we will do now as workaround is to get db schema creation script from that of customer's database and run that script to re-create the database from scratch and use that as target database instead, as luck would have it, the issue would be
gone.
Still, why the heck SSDT tries to alter timestamp column in that specific case and not in other case as described above??
Elvin -
Add Minutes to a Timestamp column
Hello there,
I need to know how to add minutes to a timestamp column in APEX. I was looking for an answer on the internet but the DATEADD function doesn't work in APEX. Any ideas?
RubenDATEADD is a SQL Server function.
I think using [interval data types|http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/sql_elements001.htm#i78291] and the NUMTODSINTERVAL function produces the clearest code:
with ts_example as (
select ename, cast(hiredate as timestamp) hirets from emp)
select
ename
, hirets
, hirets + interval '90' minute as intlit
, hirets + numtodsinterval(90, 'minute') as numtodsint
from
ts_example
ENAME HIRETS INTLIT NUMTODSINT
SMITH 17-DEC-1980 00.00.00.00 17-DEC-1980 01.30.00.00 17-DEC-1980 01.30.00.00
ALLEN 20-FEB-1981 00.00.00.00 20-FEB-1981 01.30.00.00 20-FEB-1981 01.30.00.00
WARD 22-FEB-1981 00.00.00.00 22-FEB-1981 01.30.00.00 22-FEB-1981 01.30.00.00
JONES 02-APR-1981 00.00.00.00 02-APR-1981 01.30.00.00 02-APR-1981 01.30.00.00
MARTIN 28-SEP-1981 00.00.00.00 28-SEP-1981 01.30.00.00 28-SEP-1981 01.30.00.00
BLAKE 01-MAY-1981 00.00.00.00 01-MAY-1981 01.30.00.00 01-MAY-1981 01.30.00.00
CLARK 09-JUN-1981 00.00.00.00 09-JUN-1981 01.30.00.00 09-JUN-1981 01.30.00.00
SCOTT 19-APR-1987 00.00.00.00 19-APR-1987 01.30.00.00 19-APR-1987 01.30.00.00
KING 17-NOV-1981 00.00.00.00 17-NOV-1981 01.30.00.00 17-NOV-1981 01.30.00.00
TURNER 08-SEP-1981 00.00.00.00 08-SEP-1981 01.30.00.00 08-SEP-1981 01.30.00.00
ADAMS 23-MAY-1987 00.00.00.00 23-MAY-1987 01.30.00.00 23-MAY-1987 01.30.00.00
JAMES 03-DEC-1981 00.00.00.00 03-DEC-1981 01.30.00.00 03-DEC-1981 01.30.00.00
FORD 03-DEC-1981 00.00.00.00 03-DEC-1981 01.30.00.00 03-DEC-1981 01.30.00.00
MILLER 23-JAN-1982 00.00.00.00 23-JAN-1982 01.30.00.00 23-JAN-1982 01.30.00.00
14 rows selected -
Compare date datatype against timestamp column
Hi,
I have a table "test" with a TIMESTAMP column as "insert_timestamp".
I have an application with a query like
select * from test where insert_timestamp between i_start_date and i_end_date;i_start_date and i_end_date are DATE data type variables.
When I ran this query, it returned results:
select * from test where insert_timestamp between sysdate - 1 and sysdate;My question is if it is ok to compare against a TIMESTAMP column in table using DATE data type variables?.
I am just making sure the app doesn't break during execution due to this.
Thanks in advanceyes you can use...
But with timestamp you get precision till fraction of seconds but not in case of data type...
So if you have data which differ in fraction of seconds like
1.0001 sec,1.0003 sec,1.0004 sec,1.0005 sec,1.0006 sec...
then if i have to get data between 1.0003 and 1.0005 seconds you cannot use a date variable here...
Ravi Kumar -
I have 2 timestamp columns in a table
Columnname type
LoginTime Timestamp
LogoutTime TimeStamp
Need to find total hours... how to add 2 timestamp columns.. help me...Abi,
As pointed out by Olaf, you are looking for the DATETIME type and not TIMESTAMP. The latter is just a rowversion value that helps to identify the version of each row inserted. The DATETIME type helps you to store YYYY-MM-DD HH:MM:SS.xxx format values as
required.
If your requirement is to find out the DIFFERENCE numebr of hours between the login and logout then the below query 1 shud help.
(Im not sure what you mean by TOTAL hours - ADDING the two timestamp values.. If your looking at the total number of hours passed from day zero, then query might as well help. Pls let us know if otherwise)
create table #temp
LoginTime datetime,
Logouttime datetime
insert #temp select getdate(),'2014-03-18 23:04:42.790'
insert #temp select getdate()-0.5,'2014-03-18 18:04:42.790'
insert #temp select getdate(),'2014-03-18 20:04:42.790'
--QUERY1:Finding the difference between the Login and logout times
select
Logintime,
Logouttime,
datediff(hour,LoginTime,Logouttime) as diff_hours
from #temp
--QUERY2:To find the SUM of hours of Login and logout
select
Logintime,
Logouttime,
datediff(hour,0,Logouttime) + datediff(hour,0,Logintime) as SUM_hours
from #temp
--cleanup
drop table #temp
Thanks,
Jay
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'> -
ODBC errors while retrieving timestamp column
Hi,
I created 2 views selecting timestamp column of table ULTBPM_CCHK.CC_APPINFO:
CREATE OR REPLACE FORCE VIEW "ULTBPM_CCHK"."ERKANDENE_V" ("CCAI_RECORDDATETIME") AS select TO_DATE(TO_CHAR(CCAI_RECORDDATETIME,'DD/MM/YYYY hh24:mi:ss'),'DD/MM/YYY
Y hh24:mi:ss') CCAI_RECORDDATETIME from ULTBPM_CCHK.CC_APPINFO;
CREATE OR REPLACE VIEW "ULTBPM_CCHK"."ERKANDENE_V2"
"CCAI_RECORDDATETIME") AS select CCAI_RECORDDATETIME from ULTBPM_CCHK.CC_APPINFO;
While i can query "ULTBPM_CCHK"."ERKANDENE_V" without any problem, following errror occurs for "ULTBPM_CCHK"."ERKANDENE_V2":
SELECT AL1.CCAI_RECORDDATETIME FROM ULTBPM_CCHK.ERKANDENE_V2 AL1
ODBC Error: SQL API: [SQLBindCol], SQL RETURN: [-1], SQL STATE: [HY003], SQL NATIVE ERROR: [0], SQL MESSAGE: [[Microsoft][ODBC Driver Manager] Program type out of range]
I want to select timestamp colum, Any sugestions?
Hyperion Reporting Studio 9.3.1
Oracle 9i clent
Oracle 10g (10.2.0.4) database
Regards,
Erkan SakaHi,
This time it gives "ORA-03106: fatal two-task communication protocol error". I searched metalink and fould that this may be caused by incompatible SqlNet libraries or NLS settings between cklient and server. I checked NLS settings but did not solved the problem. In dbgprint file i saw that hyperion identified timestamp column (B) as ColType 0. Is it normal for timestamp column? Because when i look at the column properties in Reporting Studio, i see nothing in Item Type.
SELECT DISTINCT COLUMN_NAME, '*', COLUMN_ID, DATA_TYPE, DATA_LENGTH,
DATA_SCALE, DATA_PRECISION, NULLABLE, '*' FROM SYS.ALL_TAB_COLUMNS
WHERE TABLE_NAME = 'ERKAN_DENE' AND OWNER = 'DISBANK' ORDER BY
COLUMN_ID
Server Column Information
ColName ColNum ColType Length Places Digits Nulls
======= ====== ======== ====== ====== ====== =====
A 1 NUMBER 22 0 10 0
B 2 TIMESTAMP(6) 11 6 10 1
End Select
DaMgr DMTable Column Information
ColName ColNum ColType Length Places
======= ====== ====== ====== ======
A 0 4 22 0
B 1 0 11 6
Begin Executing Document OnPreProcess Script.
End Executing Document OnPreProcess Script.
Begin Select
(0 0 )
Sending SQL to the Server:
SELECT AL1.B FROM DISBANK.ERKAN_DENE AL1
Oracle error -1 3106: ORA-03106: fatal two-task communication protocol error
Exception thrown in v1_bi_code\bl\da\dasnet_l.cpp, line 959: Oracle Error -1: ORA-03106: fatal two-task communication protocol error
DaSession::CancelOk()
Regards,
Erkan -
Internal error with timestamp columns
Hi
i have a table in which there's a TIMESTAMP column whenever i try to create a form on this table i cannot choose the columns in form builder data block wizard.
Or even when i try to modify a form which was created before the columns were added.
it generates this error.
FRM - 10095: Assertion Failed in iewbdbc_oracle_to_id, at C:myade\608\src\ie\iewbdb.c:703
i dont even have that directory on my machine!!!!
i tried this with forms9i & forms6i, same thing with both.
is it impossible to develope forms on a table having a timestamp column??? or is there another way?
Any help is REALLY apreciated.
Thanks in Advance
Regards
Tony G.No the with timestamp types are not supported. Forms does supplort multiple timezones, but uses normal datatime fields mapping to dates in the DB. The Forms server then takes care of mapping the Client Time to the Database time and visa versa.
See: http://www.oracle.com/technology/products/forms/pdf/9inewfeatures.pdf
Section 10 -
Data loading: formatting data for timestamp column
Hi All,
I have a table with a timestamp column named as created_date. I want to upload data to that table using data loading page. but there is one problem while uploading data, I have a csv file in which the created_date column data in two different format as follows ,
09/03/2013 03:33am
09/02/2013 03:24pm
the above data throws an error ORA-01821: date format not recognized.
In Data / Table Mapping page, I tried with MM/DD/YYYY HH12:MI:SS AM. What format should i use for am and pm??
Please help me to solve....
Thanks in advance
LakshmiI solved by using the format MM/DD/YYYY HH:MIAM.
Thanks
Lakshmi
Maybe you are looking for
-
How many times can I reinstall Leopard on a same mac?
Hi, I have the Leopard Family Edition and we had to reinstall in two computers, and I want to know if the licenses are not affected by this. And where are they, by the way? Thanks
-
Cannot drag music into playlists or move them in playlists
So I just downloaded a cd from itunes and i went to make a playlist, but when i tried to drag the songs into the playlist, it wouldn't let me. So I went to some other playlists I had and tried to move the songs around in there, but it wouldn't let me
-
Outgoing Payment Previous & Next Entry
Dear All , if i searching the Transaction in Outgoing Payment Screen frequently using next and previous button , SAP getting struck and closed automatically. How to solve this problem Thanks & Regards Madhu
-
Looking to Put Inspire 5.1 5300 Back In Service
The situation is like this: I have the Creative Inspire 5.1 5300 speaker system: however, it has a wired remote that doesn't work. (That is literally the only problem; however, with the wired remote unusable, the speaker system itself is useless.) Cr
-
WS-Security in EJB3.0 annotation WebService
Does anyone know how to enable username token WS-Security in EJB3.0 annotation WebService in oc4j 10.1.3.3.0? I set something like the below in oracle-webservices.xml, but it doesn't work. <webservice-description name="SessionEJBBeanWSService"> <port