Solved

Connecting from sqlplus / Unix

Posted on 2013-12-14
7
443 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 38

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

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!

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
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…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

635 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