Sponsored Content
Top Forums Shell Programming and Scripting Connecting to Oracle DB using sqlplus Post 302418556 by durden_tyler on Tuesday 4th of May 2010 05:39:50 PM
Old 05-04-2010
Actually, it is possible to connect to the Oracle database by specifying the connect descriptor from the tnsnames.ora file. But it's not a secure way of connecting since all important pieces of information (server name, port etc.) are exposed in the process list when connecting this way.

@OP - find out the net_service_name that corresponds to this connect descriptor. It may be "PHYGD1" or something else - depends on what your Oracle DBA set it to during installation, so you may want to talk to him/her.
Once it is known, you can connect as "username/password@net_service_name". Or better, set the ORACLE_SID variable to that value and connect as "username/password".

In my case, I've set my ORACLE_SID to "ora11g", which is the net_service_name in my tnsnames.ora for my local database. So I can connect as "test/test".

Have a look at the script below; it should give you some idea -

Code:
$ 
$ 
$ # First, let's check what we have in the table "T" of schema "TEST" of my local database
$ (echo "select * from t;") | sqlplus -s test/test

     X
----------
       100

$ 
$ # So, there's just one column "X" and one row and the one value in the table is 100
$ # Now show the contents of the shell script that connects to this database and
$ # fetches this value
$ 
$ cat -n fetch_value.sh
     1    #!/bin/bash
     2    
     3    #Connect to the database using sqlplus
     4    x=`sqlplus -s /nolog <<EOF
     5    connect test/test
     6    set pages 0 
     7    select x from t;
     8    exit
     9    EOF`
    10    
    11    # print the value of x fetched from the database
    12    echo "Value fetched from database, x = $x"
    13    
    14    # check if this value equals 100
    15    if [ $x == 100 ]; then
    16      echo "Yes, the value of x is 100"
    17    else
    18      echo "No, the value of x is $x"
    19      return 1
    20    fi
    21    return 0
    22    
$ 
$ # Now run the script
$ . fetch_value.sh
Value fetched from database, x =        100
Yes, the value of x is 100
$ 
$

The SQL syntax of your script looks suspicious:

Code:
...
from table(dbdev.db_inv_dtl_hdr)
...

If "dbdev.db_inv_dtl_hdr" is a regular (heap) table i.e. one that has been created using the "create table dbdev.db_inv_dtl_hdr (blah...);" syntax then your syntax should be -

Code:
...
from dbdev.db_inv_dtl_hdr
...

As a matter of fact, there is a "table()" operator in Oracle that casts a nested table to a regular table. However, that type of syntax is typically used by advanced Oracle programmers and somehow I believe that's not the case here.

HTH,
tyler_durden
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

error connecting to sqlplus

Hi, I wrote a shell script to call oracle procedure. But when i am trying to connet sqlplus with the fallowing statement It is giving me error " callproce.sh : sqlplus: not found". What could be the problem. sqlplus -s $CONNECT_STRING >$LOGFILE <<!! thank u all papachi (2 Replies)
Discussion started by: papachi
2 Replies

2. Shell Programming and Scripting

Showing errors when connecting to sqlplus in shell script

hi, I am trying to automate the compilation of procedures stored in .sql files in Unix. Is there any way in which we can sho err if there errors are raised in the compilation? I am using the following code to connect to the sqlplus sqlplus ${SQL_USER}/${SQL_PASSWORD} (5 Replies)
Discussion started by: silas.john
5 Replies

3. Shell Programming and Scripting

connecting through sqlplus

I am trying to connect to one of the oracle sever using uni through sqlplus command: sqlplus -s BOXI_ALPH_AUDITOR,Q078_audit$@Q047 But its not getting connected. I tried using some different server using same syntax its working. What differene i found is the password is having no special... (2 Replies)
Discussion started by: gander_ss
2 Replies

4. Shell Programming and Scripting

Formatting Oracle sqlplus output

a job extracts orcle data into unix as flat file. a single record breaks into two record in unix flat file. This is the case only for 6 records out of 60 lack records. (its not single record in two line. but its single record into record. ie., \n come into picture) can you tell me what... (6 Replies)
Discussion started by: Gopal_Engg
6 Replies

5. UNIX for Dummies Questions & Answers

Connecting to Oracle DB using sqlplus

Hi, I am very new to shell scripting and trying to write a simple shell script in which i am trying to achieve the following: 1. Connect to oracle database hosted on a different server 2. fire a query on the oracle db 3. store the output in a variable 4. use this variable for further logic... (1 Reply)
Discussion started by: shrutihardas
1 Replies

6. UNIX for Advanced & Expert Users

Connecting once using sqlplus and doing multiple queries

Hello everyone, It's my first week using unix and shell scripting. I tried creating a script that has a function that execute SQL query. my script looks something like this: ---------------------------------------------------- #!/bin/sh tableName="myTable" secondTable="secondTable"... (2 Replies)
Discussion started by: edlin_r
2 Replies

7. Red Hat

TNS Timeout Error when connecting to SQLPLUS through scripts only

Hi, I am facing a strange issue when connecting to SQLPLUS via a shell scripts. I am using Linux 2.6.18-274.18.1 and gbash shell. When I connect to SQLPLUS through scripts then it throws TNS Time Out error ""sometimes"" and connects successfully other times.This is only happening when... (9 Replies)
Discussion started by: aashish.sharma8
9 Replies

8. Shell Programming and Scripting

Connect to Oracle using sqlplus

I have logged into oracle using SQLPLUS. When I type any kind of query, there is only 1 answer - '2'. What is wrong with it? (1 Reply)
Discussion started by: Subhasis
1 Replies

9. Shell Programming and Scripting

Connecting sqlplus from UNIX with multiple select statement

hi, i have a requirement where i need to connect sqlplus from unix and i am able to do so by following command: cust_count=`sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF set pagesize 0 set feedback off set verify off ... (1 Reply)
Discussion started by: lovelysethii
1 Replies

10. Shell Programming and Scripting

Sqlplus not connecting the 2nd time in for loop

Hi, I am trying to get the rows(First step is to get the poolid's and then second step run a loop to get the output based on each pool id and third connection is to get the member id and pool id based on a different condition) where based of certain conditions and storing it in a file. I wrote the... (6 Replies)
Discussion started by: ajayakunuri
6 Replies
VACUUMDB(1)						  PostgreSQL Client Applications					       VACUUMDB(1)

NAME
vacuumdb - garbage-collect and analyze a PostgreSQL database SYNOPSIS
vacuumdb [ connection-options... ] [ --full | -f ] [ --verbose | -v ] [ --analyze | -z ] [ --table | -t 'table [ ( column [,...] ) ]' ] [ dbname ] vacuumdb [ connection-options... ] [ --all | -a ] [ --full | -f ] [ --verbose | -v ] [ --analyze | -z ] DESCRIPTION
vacuumdb is a utility for cleaning a PostgreSQL database. vacuumdb will also generate internal statistics used by the PostgreSQL query optimizer. vacuumdb is a shell script wrapper around the backend command VACUUM [vacuum(7)] via the PostgreSQL interactive terminal psql(1). There is no effective difference between vacuuming databases via this or other methods. psql must be found by the script and a database server must be running at the targeted host. Also, any default settings and environment variables available to psql and the libpq front-end library do apply. vacuumdb might need to connect several times to the PostgreSQL server, asking for a password each time. It is convenient to have a $HOME/.pgpass file in such cases. OPTIONS
vacuumdb accepts the following command-line arguments: [-d] dbname [--dbname] dbname Specifies the name of the database to be cleaned or analyzed. If this is not specified and -a (or --all) is not used, the database name is read from the environment variable PGDATABASE. If that is not set, the user name specified for the connection is used. -a --all Vacuum all databases. -e --echo Echo the commands that vacuumdb generates and sends to the server. -f --full Perform ``full'' vacuuming. -q --quiet Do not display a response. -t table [ (column [,...]) ] --table table [ (column [,...]) ] Clean or analyze table only. Column names may be specified only in conjunction with the --analyze option. Tip: If you specify columns to vacuum, you probably have to escape the parentheses from the shell. -v --verbose Print detailed information during processing. -z --analyze Calculate statistics for use by the optimizer. vacuumdb also accepts the following command-line arguments for connection parameters: -h host --host host Specifies the host name of the machine on which the server is running. If host begins with a slash, it is used as the directory for the Unix domain socket. -p port --port port Specifies the Internet TCP/IP port or local Unix domain socket file extension on which the server is listening for connections. -U username --username username User name to connect as -W --password Force password prompt. DIAGNOSTICS
VACUUM Everything went well. vacuumdb: Vacuum failed. Something went wrong. vacuumdb is only a wrapper script. See VACUUM [vacuum(7)] and psql(1) for a detailed discussion of error mes- sages and potential problems. ENVIRONMENT
PGDATABASE PGHOST PGPORT PGUSER Default connection parameters. EXAMPLES
To clean the database test: $ vacuumdb test To clean and analyze for the optimizer a database named bigdb: $ vacuumdb --analyze bigdb To clean a single table foo in a database named xyzzy, and analyze a single column bar of the table for the optimizer: $ vacuumdb --analyze --verbose --table 'foo(bar)' xyzzy SEE ALSO
VACUUM [vacuum(7)] Application 2002-11-22 VACUUMDB(1)
All times are GMT -4. The time now is 12:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy