3

I have problem that not solved for many days, i've been searching and follow answer in many question, it seems like the structure data for the datetime in my database so strange. i've read this post : Select from table by knowing only date without time (ORACLE) but it's not work on me. Okay let's start for the problem,

Im using ODBC connect to fetch data in ORACLE Database for Remedy Client.

When I select with simple query like this :

select Create_Date from HPD_Help_Desk_SLA 

it result :

Create_Date
2014-07-01 05:27:02.000
2014-07-02 05:27:02.000

but when i try this query :

select Create_Date from HPD_Help_Desk_SLA where Create_Date >= TO_DATE('2014-05-03', 'YYYY-MM-DD') AND Create_Date <  TO_DATE('2014-08-04', 'YYYY-MM-DD')

it result :

Warning: odbc_exec(): SQL error: [AR System ODBC Driver]Column not found: ., SQL state S0000 in SQLExecDirect in....

and I try for this simple query :

select Create_Date from HPD_Help_Desk_SLA where Create_Date <= '2014-08-04'

and

select Create_Date from HPD_Help_Desk_SLA where Create_Date like '2014-07-01%`'

and this not showing anything

Any ideas for this? Thanks

Community
  • 1
  • 1
Koyix
  • 181
  • 1
  • 3
  • 17
  • 2
    Which ODBC driver are you using? It might be the ODBC driver that complains about not understanding TO_DATE. – Kim Berg Hansen Oct 28 '14 at 07:45
  • 2
    I agree. It looks like ODBC thinks it is connected to another dbms, not Oracle. – Thorsten Kettner Oct 28 '14 at 07:51
  • 1
    Yes maybe that's the problem, have any idea for this? cz I want to show the data that filtered by date. actually i cant go to the table database and see what is the structure of the database, I just using client to select the data, but my boss say it is oracle database – Koyix Oct 28 '14 at 07:55
  • 1
    You're using an ODBC datasource. Check that datasource and see which driver it is using. Is it Oracle ODBC driver? Is it Microsoft driver for Oracle? Is it a third driver? My guess is the solution would be to install Oracle ODBC driver (if it is not already) and create an ODBC datasource connecting to your database using the Oracle ODBC driver. That should ensure that you can use all Oracle syntax in the SQL you write (rather than now where the driver does not understand the syntax you are trying to use.) – Kim Berg Hansen Oct 28 '14 at 10:30
  • 1
    Actually, your error message shows you are using: `[AR System ODBC Driver]`. You are using an ODBC datasource that connects to your AR System and not directly to the Oracle database. Which would mean that the syntax of the query would have to be whichever syntax AR System allows (even though Oracle database runs "underneath" AR System.) If you switch to an Oracle ODBC driver and datasource, you probably need different connection credentials as you would be bypassing your AR System and going to the database directly. I think you should ask someone with AR System knowledge, not Oracle. – Kim Berg Hansen Oct 28 '14 at 11:08
  • @Kim You should definitively post that as an answer. – Sylvain Leroux Oct 28 '14 at 11:12

2 Answers2

1

My comment "upgraded" to a proper answer upon request:

Your error message shows you are using: [AR System ODBC Driver].

You are using an ODBC datasource that connects to your AR System and not directly to the Oracle database. Which would mean that the syntax of the query would have to be whichever syntax AR System allows (even though Oracle database runs "underneath" AR System.) Therefore you get error using TO_DATE.

You either need to figure out proper syntax for date queries in AR System.

Or you can switch to an Oracle ODBC driver and datasource, but then you probably need different connection credentials as you would be bypassing your AR System and going to the database directly. That may be a security issue in your setup.

I think you should ask someone with AR System knowledge, not so much Oracle knowledge.

EDIT:

Google for "AR System" "Oracle" gives this reference as first hit:

http://www.unc.edu/remedy/clients/7.0.1/BMC%20Remedy%20AR%20System%20Server%207-0-01/Database-Ref-700.pdf

That reference manual shows how the AR System can run on several different relational databases, Oracle being one of them. Page 23 shows that an AR System "timestamp" is saved in Oracle as a number. I am almost sure that this means that when you use the AR System ODBC driver, you need to write the SQL in the ODBC call in AR System syntax. Then the AR System ODBC driver rewrites this to the syntax needed in whatever relational database the AR System is installed upon.

So it reinforces my suggestion to ask AR System developers rather than Oracle developers.

Kim Berg Hansen
  • 1,979
  • 12
  • 12
  • Thank you for your response, yes I've thinking that is the problem why the date ignore for my query. But until now it is hard to find the best query to filter by date, i've been trying check for both integer and datetime format and still doesnt work – Koyix Oct 29 '14 at 02:59
0

You are comparing date with literal. Use to_date to convert the literal to date.

where Create_Date = to_date( '2014-08-04', 'YYYY-MM-DD')

trunc will truncate the time portion. The query would return all the rows for that date. For the date range, if you are concerned for the time portion, remove trunc.

If the issue is related to ODBC, then even if it is fixed, you would get an error related to datetime format(ii the data type is DATE). It depends on your NLS_DATE_FORMAT.

For example,

SQL> SELECT empno, ename, hiredate FROM emp WHERE hiredate <='20/02/1981';
SELECT empno, ename, hiredate FROM emp WHERE hiredate <='20/02/1981'
                                                        *
ERROR at line 1:
ORA-01843: not a valid month


SQL>

But, with an implicit conversion, the next query would execute.

SQL> SELECT empno, ename, hiredate FROM emp WHERE hiredate <='20-FEB-1981';

     EMPNO ENAME      HIREDATE
---------- ---------- ---------
      7369 SMITH      17-DEC-80
      7499 ALLEN      20-FEB-81

SQL>

So, to be safe,

SQL> SELECT empno, ename, hiredate FROM emp WHERE hiredate <=to_date('20-FEB-1981','DD-MON-YYYY');

     EMPNO ENAME      HIREDATE
---------- ---------- ---------
      7369 SMITH      17-DEC-80
      7499 ALLEN      20-FEB-81

SQL>

Update I didn't see OP already used TO_DATE and thus the issue doesn't seem to be date format.

When using TO_DATE, there is an error thrown. It is highly likely that the database is not Oracle, and thus the TO_DATE function is not recognized in the particular database.

Check if select * from v$version works for you.

Lalit Kumar B
  • 47,486
  • 13
  • 97
  • 124
  • It still gives an error: Warning: odbc_exec(): SQL error: [AR System ODBC Driver]Column not found.. – Koyix Oct 28 '14 at 07:52
  • This doesn't seem to be related to the problem the OP is actually having. It doesn't address the error with `to_date`, they're already searching for a range, and trunc'ing the column might stop an index being used? – Alex Poole Oct 28 '14 at 08:11
  • Seems like issue is different. But my take is, when OP says there are no rows returned, I though it is simply because of the literal. If the ODBC connection is the issue then the issue is entirely different to my solution. – Lalit Kumar B Oct 28 '14 at 08:13
  • They're already using `to_date` with a format model in the original query that gets the error the question is about. The other two queries seem to be trying o isolate the problem but fixing those doesn't help with the underlying issue. – Alex Poole Oct 28 '14 at 08:26
  • Ah, you are correct. I was focusing on the last two queries of OP. My bad. – Lalit Kumar B Oct 28 '14 at 08:28
  • @Rezaakhmadg, can you please verify if the database is `Oracle`? – Lalit Kumar B Oct 28 '14 at 08:31
  • @LalitKumarB I'm not so sure, because my boss said it is Oracle Database, but it seems different database. I cant access the database, i just using client named by AR System to connect to the database – Koyix Oct 29 '14 at 02:57
  • `select * from v$version` Can you execute this? – Lalit Kumar B Oct 29 '14 at 03:04
  • I can't, it show : ODBC driver does not support the requested properties . I'm using Database portable software for the query – Koyix Oct 29 '14 at 03:35
  • Then till this to your boss, and insist that the database doesn't seem to be Oracle. – Lalit Kumar B Oct 29 '14 at 04:14
  • @LalitKumarB It is Oracle Database but I'm using ODBC Ar System for the client to access the data , other query works fine. but when using where cluase in datetime only showing the error – Koyix Oct 29 '14 at 04:30