Checking correct data format using sql query
1) I got column date of joining which accepts date in below format
DD-MON-YYYY
DD-MON-YY
MON-DD-YYYY
MON-DD-YY
Month DD,YYYY
Question:- how do i check whether all dates in Date of joining column are in above format or not using sql query?
2) I got one more date column which accepts date in below format
MMDDYYYY
YYYYMMDD
MM/DD/YYYY
MM/DD/YY
YYYY/DD/MM
Question:- how do i check whether all dates in date column are in above format or not using sql query?
sorry if it is a very simple question since I am new to sql and trying to learn ......Thanks for the answers from the group............
In short, NO, it's not possible. If you store dates correctly in the database as DATE datatype then you don't have this problem. If you store them as VARCHAR2 you have a problem.
So, you get a date of 20092012
Is that 20th September 2012? or is it 20th December 2009?
What about...
11-Jan-12
Is that 11th January 2012 or 12th January 2011?
Dates should never be stored on the database as strings. That is why Oracle gives you a DATE datatype so you can store them properly.
Also, when dates are passed from an application to the database, the application should be passing them as DATE datatype, and the application interface should be designed to accept dates from the user in a format specific to their country/locality and it would then know what that format is and automatically convert it to a DATE datatype before it gets anywhere near the database or any SQL.
Similar Messages
-
Multiple date formats using sql developer
Hello!
i have 2 date fields in a table.. one is populated using trunc(<date1>) and the other is to_date(<date2>,'YYYYMMDD HH24MISS'). We want <date1> to display as MM/DD/YYYY and <date2> to display as MM/DD/YYYY HH:MI:SS AMPM. When we set the date format under Preference -> Database -> NLS parameter in SQL Developer with a time format it adds 12:00:00 to <date1>, if we take it out, it drops the time in <date2>. What can we do?
thanks!I think what the original poster wanted was to display the two date columns using different formats in the table "Data" tab and AFAIK that is not possible. Setting a date format in the Preferences accomplishes the same thing as the statement
ALTER SESSION SET NLS_DATE_FORMAT='<some format>';
in command-line SQL*Plus. To do what the OP wants they'll need to create a view that has a SELECT something like this:
SELECT TO_CHAR( date1, 'YYYY-MM-DD' ) date1
, TO_CHAR( date2, 'YYYY-MM-DD HH24:MI:SS') date2
FROM some_table;
One thing the OP needs to keep in mind is that the DATE datatype stores both date and time together. If they insert a date alone, the time defaults to midnight. (This is stated in the Oracle SQL Reference.)
Ed. H. -
How to convert milliseconds to date format in sql query
Hi All,
The following code is in java.
String yourmilliseconds = "1316673707162";**
Date resultdate = new Date(Long.parseLong(yourmilliseconds));
could you plese tell me how to convert milliseconds into date format in query and comparing with another date like(sysdate-3)Hello,
http://stackoverflow.com/questions/3820179/convert-epoch-to-date-in-sqlplus-oracle
Regards -
hi,
plz need hpl for this
i have this query :
q = "select count(*) from logs where dateLog=current_date";i have a logs in this current date but i havn't any data output ?Show us more of your code, please--especiall the spot where you read data from the ResultSet.
-
Hi All,
I'm trying generate xml data using data template approach. For this do i need to use XSQL to generate xml data?
Can some one please tell me what is this XSQL and how it works?
Thanks in advance,Hi Srini,
Thank you very much for the link, its elucidates the xml data generation process using data template.
One more question: is this method called (uses) XSQL anywhere??
Thanks, -
How to display last 10 minutes data only using sql query
Hi,
Presently, I'm using version is,
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
PL/SQL Release 11.1.0.6.0 - Production
CORE 11.1.0.6.0 Production
TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
NLSRTL Version 11.1.0.6.0 - Production
So, please consider SCOTT Schema to resolve my issue,
I want to display only last 10 minutes what records are inserted or updated or deleted.
Please provide in many ways!!
ThankQ!!Hi,
See below:
select
from
emp
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected
select
from
emp
minus
select
from
emp
as of timestamp (systimestamp - interval '10' minute)
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
0 rows selected
update
emp
set
ename = ename || ' x'
where
empno = 7934
--1 rows updated.
select
from
emp
minus
select
from
emp
as of timestamp (systimestamp - interval '10' minute)
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7934 MILLER x CLERK 7782 23-JAN-82 1300 10
*/For changes, deletes and inserts compair the two result (emp and emp as of timestamp (systimestamp - interval '10' minute) ) with each other.
Regards,
Peter -
Date formats for SQL statements used by recordset object
Hi,
Date formatting appears to be quite problematic for Business One. I did a forum search for date issues and I don't think I saw any of them with an "answered" status. I have an issue with formatting a date for the creation of an SQL statement that the DI sends to SQL Server 2005. I need to format a date so that the localization parameters don't matter for either the client machine or SQL Server's machine. We don't have a problem as long as our machines are localized as USA.
I have PL 22 and I have a form - ours - where I use the Today() function to fill a date field. So this is a date that is not entered by the user. The result of this function is consistent with the localization parameters on my machine. We have two other date fields on the form where the user must type in the date.
As a test, I changed my machine to the UK parameters. I then set up the language parameters of Business One for English(United Kingdom). I changed the date format specifications in Business One so that its format is dd/mm/yy. I then brought up the form and the field that is formatted by the above function arrived in the form's field as dd/mm/yy. I then typed in the two other dates in the same format and added the record to the database. The form's table is user-defined.
I dismissed the form then brought it back up loaded with the new record. The date that was entered by the function appeared in USA format (mm/dd/yy). The dates that were typed in appeared in the Business One format (dd/mm/yy). This of course is not consistent.
When I looked at what got into the database, the formats were the opposite. Weird! To make matters really confusing, I run an SQL statement within SQL Server Mgt Studio, and use the WHERE clause to filter on the date that was based on the function. It didnt matter what format I used for the WHERE clause, the record came up. Does anyone have any idea about how I can ensure that I always use the correct date format for SQL statements passed by Business One to SQL Server regardless of where in the world the application is being run?
Thanks,
MikeIan,
Here's what I'm concerned about: Im using the date in a WHERE clause.
Assume the date is Aug 3, 2007.
"SELECT * FROM Table WHERE StartDate > 8/3/2007"
OR
"SELECT * FROM Table WHERE StartDate > 3/8/2007"
If the client machine is set up as USA, the today function will provide the date as formatted in the first query. If the database server is setup as lets say the UK, I believe that SQL Server query parser will interpret the date as Mar 8, 2007.
If the client machine is set up as UK, the today function will provide the date as formatted in the second query. If the database server is setup as lets say USA, I believe that SQL Server query parser will also interpret the date as Mar 8, 2007.
In both cases it would be wrong.
I know I could use the DATEPART function to get the three parts and this will make the code indifferent to the localization specs of the client machine. I need to then be able to concatenate those date parts for the WHERE clause so that the localization specifications of the database server dont matter.
Thanks,
Mike -
Help Required -- Can we use SQL Query to READ data from SAP MDM Tables
Hi All,
Please help.........
Can we use SQL Query to READ(No Creation/Updation/Deletion just Read) Data from SAP MDM tables directly, without using MDM Syndicator.
Or direct SQL access to SAP MDM tables is not possible. Only through MDM Syndicator can we export data.
Thanks in Advance
RegardsAll the tables you create in Repository comes under A2i_CM_Tables in Database named as your repository name. So the tables names are fields of table A2i_CM_Tables. Now i tried it but cant make it.
Now, I dont think its possible to extract all fields in tables and there values using select query. May be pure sql guy can do that or not.
But there is no relation of data extraction and syndicator. Data is viewed in Data Manager. and you can also store data in a file from DM also.
BR,
Alok -
How to retrive the blob data from a table using sql query
Hi gurus,
I have a table which has " BLOB "content in a column .I want to view the data From BLOB column using sql query .It would be helpfull If some one share their idea.
Regards,
vardhani.You can use data templates.
See this: http://blogs.oracle.com/xmlpublisher/entry/blob_clob_raw_and_looooong
http://blogs.oracle.com/xmlpublisher/entry/inserting_blobs_into_your_repo
Thanks,
Bipuser -
Failing to import data using SQL query
I am trying to import data from a sql query to analysis service in SSDT. i went to model > import from data source >Microsoft SQL Server and i chose from query. I typed my query which works fin in SSMS and when i press import if gives me a error. what
is going on please help here is the error
DirectQuery error: All tables used when querying in DirectQuery Mode must be from a single relational Data Source.
here is my query:
USE AdventureWorks2012;
SELECT SalesPersonID, [29484] Brian, [29485] Peter, [29486] Frank, [29518] Sarah, [29519] Janet, [29520] Alice, [29608] Martin, [29609] Patrick, [29610] Wasu, [29780] Samanyika, [29781] Vladmire
FROM
SELECT SalesOrderID, SalesPersonID, CustomerID
FROM Sales.SalesOrderHeader
WHERE SalesPersonID IS NOT NULL
As P PIVOT
COUNT (SalesOrderID) FOR CustomerID IN ([29484], [29485], [29486], [29518], [29519], [29520], [29608], [29609], [29610], [29780], [29781])
AS PVT
ORDER BY SalesPersonID ASC;Hi,
When importing data from relational data source, the steps are:
In SQL Server Data Tools (SSDT), click the Model menu, and then click Import
from Data Source.
On the Connect to a Data Source page, select the type of database to connect to, and then click Next.
Follow the steps in the Table Import Wizard. On subsequent pages, you will be able to select specific tables and views or apply filters by using the Select
Tables and Views page or by creating a SQL query on Specify a SQL Query page.
As we can see on the steps, we need to select one database, so we needn't to write "USE AdventureWorks2012" on the query.
Reference:Import from a Relational Data Source
Regards,
Charlie Liao
TechNet Community Support -
Date formats in BI Query designer
Hi gurus
We have enhanced our cube 0sd_co3 where we have taken a number of dates such as Railway Receipt date, Actual Goods Issue date, LFdat, thses are only few examples. Now our reporting scenerio demands reporting based on thses dates as given in our time dimensions such as
YYYYMM Qty
but not based on the date mapped in the time dimension in the cube. but based on these dates
in oracle we have the to_char function through which we change the format of date while writing sql query
so if there is any option of changing date format in query without changing the modelling
Pl suggest
Thanks
ShivaniHi,
You can create new characteristic of char number 6 . Include it in the data target. Populate it via a update rule ( Routine).
Use input as standard date (Railway Receipt date) and then pass the value to the new char in the required format (YYYYMM). Follow same thing for other dates also.
Let me know if you have doubt.
Regards,
Viren -
HI Thanks for the reply.
IF I want to format the OPP_VALUE column How do I do format using sql
Do I have to do it when I create the table? I loaded these data using spread sheet.
I tried
SELECT distinct tab.CUSTOMER, tab.SC, tab.HOURS,tab.OPP_VALUE, tab.opp_val_rank
FROM
(SELECT CUSTOMER, SC, HOURS, column OPP_VALUE format 999,999 OPP_VALUE, DENSE_RANK() OVER (order by OPP_VALUE DESC) opp_val_rank
FROM FMW_ANALY) tab
WHERE opp_val_rank<=10;
I'm getting error ORA-00936: missing expressionHi I'm getting the following Result when I run the query
SELECT distinct tab.CUSTOMER, tab.SC, tab.HOURS,tab.OPP_VALUE, tab.opp_val_rank
FROM
(SELECT CUSTOMER, SC, HOURS, to_char(OPP_VALUE,'999,999') OPP_VALUE, DENSE_RANK() OVER (order by OPP_VALUE DESC) opp_val_rank
FROM FMW_ANALY) tab
WHERE opp_val_rank<=10;
CUSTOMER SC HOURS OPP_VALUE OPP_VAL_RANK
Education and Training darryn 1 ######## 1
Bank Limited matthew 40 ######## 3
Bank Limited matthew 16 ######## 3
Vicky -
How to get tax break up of TDS using SQL query ?
Hi all,
We are developing a TDS report using SQL query
Report will contain VendorCode,Date(ap inv date),Vendor name,
Bill value,TDS Amount,
Bill Value 100.000,
TDS (2%) - 2.000,
TDS Surcharge(10% on TDS) - 0.2,
TDS Cess(2%(TDS+TDS Surcharge)) - 0.044,
TDS HeCess(1%(TDS+TDS Surcharge)) - 0.022.
We have developed this report which displays upto
VendorCode,Date(ap inv date),Vendor name,
Bill value,TDS Amount.
How to show tax break up of TDS in SQL query ?
Thanks,
With regards,
Jeyakanthan.Hi gauraw,
Thank for your reply.
I modified the query , pasted the query
as below in query generator,
Select T0.DocNum,T0.DocDate,T0.CardCode as 'Ledger',T1.TaxbleAmnt As 'Bill value',T1.WTAmnt as 'TDSAmt',(TDSAmt * 0.1) as 'TDS_Surch',
(((TDSAmt0.1) + TDSAmt)0.02) as 'TDSCess',
(((TDSAmt0.1) + TDSAmt)0.01) as 'TDSHCess'
FROM OPCH T0 INNER JOIN PCH5 T1 ON T0.DocEntry = T1.AbsEntry
WHERE (T0.DocDate >= '[%0]' and T0.DocDate <= '[%1]')
on clicking execute its showing error message invalid column
name 'TDSAmt'.
With regards,
Jeyakanthan -
Hi there !
Please, can anyone help me find out what is going on with date format in my SQL Statements ?
While in development, the date format in SQL statements were:
SELECT DATA_FIELD FROM TABLE WHERE DATE_COL = '10-DEC-2004'
And works fine.
After deploy to production server, we get ORACLE error: not a valid month
So we change the format to
SELECT DATA_FIELD FROM TABLE WHERE DATE_COL = '10/12/2004'
And it gets to works again.
Yesterday, the net administrator updated the JAVAC / JSDK run-time with Java update tool, and AGAIN we get ORACLE error: not a valid month
So we change the format AGAIN to
SELECT DATA_FIELD FROM TABLE WHERE DATE_COL = '10-DEZ-2004'
And it gets to works again.
What is going on ?
JAVAC running on Windows2003.
The application access the ORACLE DB directly through JDBC.
There is no APPLICATION SERVER, like TOMCAT.
The regedit (windows registry) ALWAYS was and are now :
NLS_DATE_FORMAT = DD-MON-YYYY
NLS_LANG = AMERICAN_AMERICA.WE8ISO8859P1
Versions:
DB Oracle 9.2.0.5.0
JavaC 1.4.2.05
Thanks.
JulianoSomewhere, I'm willing to wager your NLS_DATE_FORMAT was/ is being changed. This is a client-side setting. Are you sure that the setting is the same on every client machine.
This is one of the reasons that it is considered bad form to rely on implicit conversion. If you wrap your string literal in a TO_DATE, use the JDBC escape sequence {d }, or use a Date bind variable, you don't have this problem. The bind variable approach will also play much more nicely with your database's shared pool.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Update date format in SQL developer
I need to convert date format in SQL developer , it's varchar2 format now
The current format is yyyy/mm/dd-hh:mm:ss:sss and I need to convert it to yyyy-mm-dd hh:mm:ss CST
I don't really know SQL but did some research and found that I can use instr to find the string and replace it, however, no matter what I try,there is always something off :(
Could anyone here help me with it? thanks in advance.create table xo_custom_date_format (mydateAsChar varchar2(100));
table XO_CUSTOM_DATE_FORMAT created.
insert into xo_custom_date_format
values ('2012/03/23-09:52:24:123')
+1 rows inserted.+
select mydateasChar from xo_custom_date_format
mydateaschar
+2012/03/23-09:52:24:123+
select to_timestamp(mydateaschar, 'YYYY/MM/DD-HH24:MI:SS:FF3') mydateAsTimestamp from xo_custom_date_format
-- We must convert to timestamp data type, rather than date data type as you have fractions of seconds
mydateAsTimestamp
+23-MAR-12 09:52:24.123000000 --<-- This will probably appear differently, depending on your database NLS_ settings (i.e. what country you are in)+
select to_char( to_timestamp(mydateaschar, 'YYYY/MM/DD-HH24:MI:SS:FF3') , 'YYYY-MM-DD HH24:MM:SS')||' CST' as myDateReformatted
from xo_custom_date_format
mydateReformatted
+2012-03-23 09:03:24 CST+
Maybe you are looking for
-
Assign users to multiple books
Hi experts, we want to assign many books to one user. Am I right, that there is no child-object for books on users? When I want to determine to which books a users belong, do I have to iterate to all books? Thanks in advance Michael
-
SunONE 7 update 1: bug 2
I reported this bug for the original version 7. But it is still in update 1. This bug is for Solaris only, not for Widnows. It looks like the server was loading a native library, but could not found: Exception in thread "Thread-7" java.lang.Unsatisfi
-
Help Needed With Basic Client/Server App
I was wondering if anyone can help with a simple blackjack client/server application i've been writting (basically its a moddified chat application). The problem i'm having seems to lie within the connection management i've written. What i'm trying t
-
How to access lotus notes?
I am in a new job, and my new employer uses Lotus Notes. Can I use either apple mail standard app or outlook to get it? how?
-
IView from portal application in SAP Portal 7.3
Hi, I´m starting with SAP Portal 7.3 and I have developed a hello word JSPDynpage with NWDI 7.3. I have successfully deployed it to the server and I can see my application under Portal applications, and do a success preview. But I´m not able to creat