BookmarkSubscribeRSS Feed
R_Chung
Quartz | Level 8

Hello everyone,

 

I am trying to insert something to different oracle database from my SAS dataset.

As usual, the syntax of selecting table from other database is

select * from otherowner.tablename; 

Let say I have a SAS dataset aaa.

 

proc sql noprint;    
		connect to oracle 
			(user=xxx password=xxx path=xxx);    
			execute (insert into otherowner.tablename select * from work.aaa) by oracle;
			disconnect from oracle; 
quit;

It seems that SAS seek "otherowner" as libname to operate the above statement.

 

Meanwhile, I have tried to add preserve_comments, i.e,

proc sql noprint; 
        connect to oracle (user=xxx password=xxx path=xxx preserve_comments=YES); 
        execute (insert into /*otherowner.tablename */ select * from work.aaa) by oracle; 
        disconnect from oracle; 
quit; 

However, this is also not working.

 

Could any expert advise how to implement what I want to execute. Many thanks.

4 REPLIES 4
Tom
Super User Tom
Super User

You cannot use code pushed to Oracle to access data in SAS datasets (the oracle code will have no idea what WORK.SAS is).

You need to run SAS code to push SAS datasets into Oracle.

Easiest thing it is make a libref that points to ORACLE.

libname myora oracle ..... ;
proc append base=myora.tablename data=work.sas;
run;

If for some reason you need to insert into a table that is in a different Oracle schema than the one you connect to the libref to try using the SCHEMA= dataset option.

libname myora oracle ..... ;
proc append base=myora.tablename(schema='otherowner') data=work.sas;
run;

 

R_Chung
Quartz | Level 8

Hi Tom,

For option one, I usually using this for inserting data into table.

However, if I need to insert into other database I need to especially specify other username in my libname statement.

libname myora oracle ..... user=otheruser pw="";other user password="";

 This may lead to a concern that everyone will know the password.

 

I have tried the second option but there is still an error.

ERROR: The ORACLE table <table_name> has been opened for OUTPUT. This table already exists, 
or there is a name conflict with an existing object. This table will not be replaced. This engine does not support the REPLACE option.

 I have read the support post: https://support.sas.com/kb/32/461.html

But they suggest to omit the schema=

 

Could you advise again?

I think the second option is the closest solution for my case.

Thank you.

ricric
Calcite | Level 5

Actually, specifying schema is already enough for your case.

 

If adding schema in your proc append is not working.

 

Try adding it in your library statement.

libname myora oracle <your connection string> schema=otherowner ;

See if this works.

Patrick
Opal | Level 21

@R_Chung As for your concern with credential: Look-up what authentication domains could do for you.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 504 views
  • 0 likes
  • 4 in conversation