Solved

Connecting from sqlplus / Unix

Posted on 2013-12-14
7
432 Views
Last Modified: 2014-01-28
Below is a statement from Unix shell scripting.

DUMMY=`sqlplus <<ENDSQL
  ${MMS_ORA_USER}/${MMS_ORA_PASS}
  whenever sqlerror exit failure;
  whenever oserror exit failure;
  SET ECHO ON SERVEROUTPUT ON
  BEGIN ${PROC};
  END;
  /
  EXIT
  ENDSQL`

How can I achieve the same from CMD prompt/sql plus?
0
Comment
Question by:sakthikumar
7 Comments
 
LVL 29

Assisted Solution

by:MikeOM_DBA
MikeOM_DBA earned 250 total points
ID: 39720080
Try this:
# 1) You set the variables:
MMS_ORA_USER=SCOTT
MMS_ORA_PASS=tiger

cat - <<!  >PROC.sql
DECLARE cnt Number:=0;
BEGIN
  SELECT COUNT(*) INTO cnt
  FROM USER_OBJECTS;
  DBMS_OUTPUT.PUT_LINE(''Object count is:''||cnt);
END;'
/
!

#2) You execute sql plus:

dummy=`sqlplus  /nolog <<EOSQL
conn ${MMS_ORA_USER}/${MMS_ORA_PASS}
whenever sqlerror exit failure;
SET ECHO ON SERVEROUTPUT ON
@&&PROC
/
EXIT
EOSQL`

Open in new window

0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 39720083
From command prompt:
sqlplus /nolog
conn SCOTT/tiger
whenever sqlerror exit failure;
SET ECHO ON SERVEROUTPUT ON
@&&PROC
/
EXIT

Open in new window

0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39720559
>>How can I achieve the same from CMD prompt/sql plus?

Windows does not have 'here' scripts.

You cannot really do everything in the same script like you can to in Unix.

It's best to create the .sql file that has all the Oracle SQL commands then a CMD script that calls it.

For example:
q.sql contains:  select 'Hello' from dual;

q.cmd contains: sqlplus user/password @q.sql
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 39724129
why wouldn't you be able to do everything in 1 cmd script ?

create a cmd script which creates the sql on the fly and calls it

set oracle_sid=sid
set sqlfile=c:\scripts\test.sql
(
echo.spool test.txt
echo.select 'hello' from dual;
echo.spool off
echo.exit
) > %sqlfile%

sqlplus -L -S "/ as sysdba" @%sqlfile%

Open in new window


long live the penguin !
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 39724158
I posted a one script solution above at #39720080
0
 

Author Comment

by:sakthikumar
ID: 39800623
Hi all,

I am not able to understand, please tell me clearly.

I will have the command prompt like this

computer name\desktop>

what file type and what content I should create.

Please explain.
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 250 total points
ID: 39800675
If you go with the two file version I posted it in http:#a39720559

one file q.sql has:
select 'Hello' from dual;

The file called q.bat (or a CMD file) has:
sqlplus user/password @c:\pathTosql\q.sql

Then from your prompt:
c:\myscripts\q.bat
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

730 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