BookmarkSubscribeRSS Feed
sanjay1
Obsidian | Level 7

Hi Experts,

 

I am trying to get the date value form a table using sql query. But I am getting  the following error.

 


ERROR: ORACLE prepare error: ORA-00923: FROM keyword not found where expected. SQL
statement: SELECT ACCT.number as Acct_id,datepart(ACCT.DATE) AS DT format date9.,ACCT.Num,
Client.Name FROM ACCT,Client

 

 

Here is my code: 


proc sql;
connect to ORACLE (user="xxxx" password="xxxx" buffsize=5000 path=test);
CREATE TABLE sample AS
SELECT * FROM CONNECTION TO ORACLE
(
SELECT
ACCT.number as Acct_id,
datepart(ACCT.DATE) AS DT format date9.,
ACCT.Num,
Client.Name


FROM
ACCT,
Client

);
quit;

 

Please suggest if I am doing anything wrong.

 

Thanks,

 

 

2 REPLIES 2
Kurt_Bremser
Super User

The Oracle DATEPART() function works differently than the SAS DATEPART(): https://docs.oracle.com/cd/E57185_01/ESBTR/mdx_datepart.html 

Similarly, Oracle will (most likely) not understand DATE9.

 

Before using explicit passthrough to database system X, you need to have sufficient knowledge of the peculiarities of DBMS X. If in doubt, ask your local Oracle admins.

dcmacedo
Obsidian | Level 7

Your code has syntax errors. You are using the "Pass-Through" feature. "Format's" are exclusive features of SAS, they will not work inside the "Pass-Through" block.

See "Pass-Through"
In addition, oracle has no data type "date", only "date-time", but if your SAS is configured correctly, the SAS itself does the necessary conversions.

 

Try this code:

proc sql;
connect to ORACLE (user="xxxx" password="xxxx" buffsize=5000 path=test);
CREATE TABLE sample AS
SELECT 
 Acct_id, 
datepart(DATE) as DT format date9., 
Num,
Name
 FROM CONNECTION TO ORACLE
(
SELECT
ACCT.number as Acct_id, ACCT.DATE, ACCT.Num, Client.Name
FROM ACCT, Client
);
quit;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 592 views
  • 2 likes
  • 3 in conversation