Solved

Connecting to another server from ksh script

Posted on 2013-06-21
4
622 Views
Last Modified: 2013-06-27
On one UNIX server I have a ksh script and from my script I need to connect to another UNIX server to an Oracle database and insert some data.

So far I got:

sqlplus 'username/pwd@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myHostname)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=myDB)))' >> output.log

to connect to the server but how do I run an insert statement?
0
Comment
Question by:YZlat
  • 2
  • 2
4 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 39267216
Assuming you have a list of values you can embed in the script, try the code below.  It is called a HERE document.

sqlplus 'username/pwd@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myHostname)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=myDB)))' << EOF >> output.log
insert into some_table values('hello','world');
commit;
exit
EOF


If you have something else, please explain.
0
 
LVL 35

Author Comment

by:YZlat
ID: 39281196
slightwv, are there any advantages to put the entry into tnsnames.ora and just use an alias, over listing the whole tns entry in the script?
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39281210
There are pro's and con's.

If everything is in the tnsnames.ora file and all apps/scripts use it then you can easily change database servers and/or database names and no app/script needs to change.

The counter-point:
You need to rely on another configuration file for your apps/scripts to work.
0
 
LVL 35

Author Comment

by:YZlat
ID: 39281506
Thanks!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
custome paging in C# & oracle using inline queries. 12 37
JDeveloper 12c for 32 bit 4 35
unix in java example 9 42
Oracle Syntax 8 41
Utilizing an array to gracefully append to a list of EmailAddresses
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to recover a database from a user managed backup
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now