I have 2 tables, 1 table has a date column, 1 table has a time column. I want to have date and time works seperatedly. This is what i use :
ALTER SESSION SET nls_date_format='dd/mm/yyyy';
I use this for the 1st table and then use this for the 2nd table :
ALTER SESSION SET nls_date_format='hh24:mi';
But it doesn't work right. When i do the select * from it all changes back to hh24:mi type. How can i have date and time seperatedly ?
As noted Oracle always has a date and time. If you want to see and use just the date or just the time you could use, for example to only work with the time, TO_CHAR(ColumnA, 'HH24:MI:SS')
Related
I have a table with a column called ThisDayOfTherapy which is of datatype DATE in SQL Server.
Later, I have an aggregate query using Min(ThisDayOftherapy). This query populates a #temp table with the result of Min(ThisDayOfTherapy) as column name StartDate_Min
In a 3rd location I am finally doing something with StartDate_Min. When I hold my mouse over StartDate_Min, it says the datatype is INT.
Shouldn't it simply be DATE? Will it still work as if it were a date for all practical purposes?
I see the same behavior, but I think you will be fine. SQL Server would not execute any date functions if it was not a valid date. Adding one day to my MinDate column from my temp table is working as expected.
I have a problem with data in Oracle database:
I want to get created time of some record in table. I can get ora_rowscn of the record, but I cannot run to change this ora_rowscn to timestamp by query SELECT SCN_TO_TIMESTAMP(ora_rowscn) because SCN_TO_TIMESTAMP() may not be available for older data (my data was inserted about 1 month ago).
Anyone have solution to resolve this problem for me to get created time?
Perhaps the best thing to do here, assuming you have a long term need for this requirement, would be to alter your current table and add a bona-fide timestamp column. You could give this timestamp column a default value of the current timestamp, e.g.
CREATE TABLE yourTable (
...
created_time TIMESTAMP(6) default CURRENT_TIMESTAMP
);
Then, when inserting a new record, omit mention of the created_time column, letting Oracle back fill it with the current timestamp.
I need a column to be dynamic as such that a column DaysToExpiration is calculated based on the number of days between now and a date column Expiration Date.
My plan was to add a trigger that fires on a SELECTstatement of the table.
Is this possible? How?
Is there a better way to go about this?
You say "My plan was to add a Trigger that Fires on a SELECT statement of the table."
In that case why have a column at all, why not just select it in your final query?
Select DateDiff(day,getdate(),ExpirationDate) AS [DaysToExpiration]
If it must be persisted and stored in a column then you can make it a computed column as suggested in the comments. Or you could have the table trigger on UPDATE/INSERT so when the ExpirationDate is inserted or updated it sets the DaysToExpiration column to the result of the provided code.
No there is no provision of having trigger on SELECT operation. You can use stored procedure which takes parameters that are fetched from SELECT query and call this procedure after desired SELECT query.
I am trying to migrate a column in Postgres from Timestamp without time zone to a timestamp with time zone. I want to do it for German time, so I used the following query :
alter table table_name alter column uploaddate type TIMESTAMP WITH TIME ZONE USING uploaddate at time zone 'UTC+01:30';
Unfortunately it's not working, it's adding 2015-06-30 07:30:48.785+05:30. I am currently in India, which is +5.30. How can I specify to the query to do it with German time zone. Thank you.
What is the timezone of the timestamps stored in the table? That is, if there is a value such as 2016-09-22 07:30 in the table, in what timezone is 07:30? This is the timezone that you want to use, not your current local timezone. So e.g. if all timestamps are expressed in german timezone you should do something like:
alter table table_name
alter column uploaddate type TIMESTAMP WITH TIME ZONE
USING uploaddate at time zone 'Europe/Berlin';
Don't forget that you can run the above inside a transaction so that you can inspect the results before you commit them (of course this will lock the entire table and block all other concurrent queries for that table).
Say I have a table on an Informix DB:
create table password_audit (
username CHAR(20),
old_password CHAR(20),
new_password CHAR(20),
update_date DATETIME YEAR TO FRACTION));
I need the update_date field to be in milliseconds (or seconds maybe - same question applies) because there will be multiple updates of the password on the same day.
Say, I have a nightly batch job that wants to retrieve all records from the password_audit table for today.
To increase performance, I want to put an index on the update_date column. If I do this:
CREATE INDEX pw_idx ON password_audit(update_date);
and run this SQL:
SELECT *
FROM password_audit
WHERE DATE(update_date) = mdy(?,?,?)
(where ?, ?, ? are the month, day and year passed in by my batch job)
then I don't think my index will be used - is that right?
I think I need to create an index something like this:
CREATE INDEX pw_idx ON password_audit(DATE(update_date));
- is that right?
Because you are forcing the server to convert two values to DATE, not DATETIME, then it probably won't use an index.
You would do best to generate the SQL as:
SELECT *
FROM password_audit
WHERE update_date
BETWEEN DATETIME(2010-08-02 00:00:00.00000) YEAR TO FRACTION(5)
AND DATETIME(2010-08-02 23:59:59.99999) YEAR TO FRACTION(5)
That's rather verbose. Alternatively, and maybe slightly more easily:
SELECT *
FROM password_audit
WHERE update_date >= DATETIME(2010-08-02 00:00:00.00000) YEAR TO FRACTION(5)
AND update_date < DATETIME(2010-08-03 00:00:00.00000) YEAR TO FRACTION(5)
Both of these should be able to use the index on the update_date column. You can experiment with dropping some of the trailing zeroes from the literals, but I don't think you'll be able to remove them all - but see what the SET EXPLAIN ON output tells you.
Depending on your server version, you might need to run UPDATE STATISTICS after creating the index before the optimizer uses it at all; that is more of a problem on older (say 10.00 and earlier) versions of Informix than on the current (11.10 and later) versions.
I Didn't see 'date_to_accounts_ni' defined in your password_audit table.
What datatype/length is it?
Your first index on password_audit.update_date is adequate, why would you want to index
(DATE(update_table))?