Home > OS >  Run sql plus commands on Unix machine
Run sql plus commands on Unix machine

Time:03-25

I am working on a unix machine and the only way to execute oracle sql commands is through a unix script we grant access like this :

#! /user/bin/ksh

User = 'PATH' # I can't read the file in this path

sqlplus $user << word # I don't know what it is used for

And then i start writing sql commands then execute the script through cmd

My question is : Do I have any way to login to sqlplus directly through the info above through cmd

I tried to use this command to log in directly to sql plus : sqlplus $user << word # I don't know what it is used for But it prompted username : # which I don't know

CodePudding user response:

If your unix box is setup correctly the variable PATH should include /usr/local/bin you can test by typing in the command echo $PATH.

if its setup, the source in the oracle file oraenv like so

. oraenv

Note there should be a space between the period a the word oraenv. By doing this it should append the directories $ORACLE_HOME:$ORACLE_HOME/bin to the PATH variable. Since sqlplus is in $ORACLE_HOME/bin it should now be found.

I wouldn't recommend deviating from this standard. You should speak to your unix admin and Oracle dba to make sure this is setup correctly

CodePudding user response:

User = 'PATH' # I can't read the file in this path There is no file to read. You are assigning the string literal 'PATH' to the environment variable "User". You could just as well say "User = 'FUBAR'"

sqlplus $user << word # I don't know what it is used for

It is telling the OS to launch the executable 'sqlplus', pass it the value of the environment variable "$user", then redirect other input from the next lines of the script until it comes to the string literal 'word'. This is call 'input redirection, and the commands between this line and the line beginning with the word 'word' are sometimes referred to as "a 'here' document". Using the string literal 'word' to terminate it is wierd and misleading at best. Most people use some variation of 'EOF' for this purpose.

I don't know what it is expected to be used for either. In *nix, environment variables (as are file names) are case sensitive. So this variable , "user" is not the same variable, "User" as you set in the previous line.

And then i start writing sql commands then execute the script through cmd

I'm not sure what you mean by this. Are you saying that at this point, your script has sql commands intended to be processed by sqlplus? As indicated by your use of input redirection?

But it prompted username : # which I don't know

Well, in spite of all the other issues, if you don't know the username and password, you will never be able to connect to the database.

  • Related