How do I change the path of file from oracle - oracle

I have ubuntu 14.04 and oracle XE 11
if to execute a file sql from Oracle i do :
SQL > # /........./Desktop/file.sql
how change the a path of oracle , Means I create file in Desktop
and i do :
SQL > # file .sql

You can set the $SQLPATH environment variable before running SQL*Plus. From the documentation:
SQLPATH - Environment variable or Windows registry entry to specify the location of SQL scripts. SQL*Plus searches for SQL scripts, including login.sql, in the current directory and then in the directories specified by SQLPATH, and in the subdirectories of SQLPATH directories. SQLPATH is a colon separated list of directories. There is no default value set in UNIX installations.
So:
export SQLPATH=/........./Desktop
sqlplus
Alternatively, just cd to the Desktop directory before launching SQL*Plus, as it will look for scripts in the current directory first anyway.

#alex poole for the win!
A small additional thought; just like the unix PATH variable, you can have several paths defined in the SQLPATH variable, so sqlplus can look in several locations to find the referenced script.

Related

How to use the absolute path of a file on another hard drive with Oracle (sqlplus)?

I am surprised I did not find anything about this anywhere, but how do I execute a file with sqlplus with the absolute path of the file? In the internet it says
sqlplus databaseURL #sqlFile
This works if I use it as relative File and have the SQL File in the same directory. But using a path after the "#" just doesn't work and it says "file does not exist" when I run the command. The file surely is in the specified path and I am on Windows.
How do I make this work?
EDIT: Example of relative path:
sqlplus -l user/pw#localhost:1521/service #test.sql;
Example of absolute path
sqlplus -l user/pw#localhost:1521/service #D:/folder/test.sql;
There is another possibility: to set the SQLPATH environment variable to specify where SQL*Plus should look for SQL files:
Doc. says
The SQLPATH registry entry specifies the location of SQL scripts.
SQL*Plus searches for SQL scripts in the current directory and then in
the directories specified by the SQLPATH registry entry, and in the
subdirectories of SQLPATH directories.
The HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOME0 registry subkey (or the HOMEn directory for the associated ORACLE_HOME) contains the
SQLPATH registry entry. SQLPATH is created with a default value of
ORACLE_HOME\DBS. You can specify any directories on any drive as valid
values for SQLPATH.
When setting the SQLPATH registry entry, you can concatenate directories with a semicolon (;). For example:
c:\oracle\ora12\database;c:\oracle\ora12\dbs
See the Registry Editor's help system for instructions on how to edit the SQLPATH registry entry.
So to clarify what the problem for me was, it was actually just in the file itself.. I used "\" instead of "/" at the end of the SQL File. After I changed that, it worked for me. My command looked like this in the end:
sqlplus -l user/pw#localhost:1521/service #D:\folder\test.sql;

Unable to MKDIR using %userprofile% from within SQL*plus

On Windows I'm spooling the results of a PL/SQL loop to a .csv file from within SQL*Plus, executed from a batch file. Prior to spooling the .csv file, I want to create a windows directory to contain the file in a user's documents folder using %USERPROFILE%\documents variable.
Running the MKDIR in isolation from command line like so:
MKDIR -p "%USERPROFILE%\Documents\my-dir\my-sub-dir"
Creates the folder I would like i.e. C:\Users\christofflam\Documents\my-dir\my-sub-dir, but calling that code from within SQL*Plus creates a literal parent directory called %USERPROFILE% in whichever directory cmd.exe is running from.
The following code is being called from within the SQL*Plus command file:
HOST MKDIR -p "%USERPROFILE%\Documents\my-dir\my-sub-dir"
Which results in the creation of literal directory C:\my-cmdexe-dir\%USERPROFILE%\Documents\my-dir\my-sub-dir
How do I create the desired directory in %USERPROFILE% from within SQL*Plus command file?

How to export files from Oracle Apex workspace using command line?

One simpler way is:
Go to https://apex.oraclecorp.com then login into the workspace using credentials.After that click on SQL scripts and proceed to download or export the SQL's.
But is there any way by which we can directly export/download all the sql files via command line ?
You can quickly export Apex applications through the command line, avoiding the Apex UI completely. To do this, Oracle has provided two java classes, which are included in the Apex download:
APEXExport.class
APEXExportSplitter.class
These classes are located in the apex/utilities/oracle/apex directory.
Before using these classes, you have to make sure that the following environment variables are set up correctly:
ORACLE_HOME should point to just that. Something like:
/u01/app/oracle11g/product/11.2.0/db1
APEX_HOME should point to the directory where you unzipped the Apex download. For example
/u01/downloads/apex
PATH needs to include $ORACLE_HOME/jdk/bin
CLASSPATH needs to include:
$ORACLE_HOME/jdbc/lib/ojdbc5.jar
$APEX_HOME/utilities
Note: You may also have to include the . path.
APEXExport
To execute the export use
$ java oracle.apex.APEXExport
You can get a list of the available arguments by executing the above command without arguments. For a basic application export use:
$ java oracle.apex.APEXExport -db localhost:1521:db1 -user scott -password tiger -applicationid 100
You’ll get a message saying: Exporting application 100.
Once the export is done you’ll see an *sql file in your current directory (e.g. f100.sql).
APEXExportSplitter
You can now take the export file and split it up into its various components. This is handy if, for example, you want to examine the SQL of an application page or two.
$ java oracle.apex.APEXExportSplitter f100.sql
This program creates a directory named after your application (e.g. f100) and multiple sub directories which contain the various components of the application.

What to do about "no ocijdbc11 in java.library.path" SQL Developer error

I am trying to get create a TNS connection in SQL Developer on my mac laptop (OS X 10.9.5).
I get this error no ocijdbc11 in java.library.path I googled around and found out that I need to
install oracle's instant client. I found the instance client files here :
http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
The files are just zip files that you need to download and extract somewhere.
Then I found the instructions that actually tell you what to do with the zip files here:
https://docs.oracle.com/cd/E11882_01/install.112/e38228/inst_task.htm#BABHEBIG
The instructions say that :
Set the DYLD_LIBRARY_PATH and the NLS_LANG environment variables
to the full path of the instantclient_11_2 directory. For example,
if you unzipped the Instant Client zip file in the /bin/oracle
directory, then set the DYLD_LIBRARY_PATH environment variable to
/bin/oracle/instantclient_11_2.
What the instructions do not tell me is HOW to set environment variables permanently and how to make the environment variables accessible to GUI tools like SQL developer.
Has anyone gotten SQL Developer to work with instantclient?
Based on the answer of #Alex Poole: In El Capitan when SIP is enabled, this doesn't seem to work, because the DYLD_LIBRARY_PATH environment variable doesn't get transferred to the environment that bash ./sqldeveloper starts (last line of the SQLDeveloper.app/Contents/MacOS/sqldeveloper.sh) .
Solution: instead of editing the file SQLDeveloper.app/Contents/MacOS/sqldeveloper.sh I edited the file SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/bin/sqldeveloper and added the export DYLD_LIBRARY_PATH=/path/to/instantclient line there.
#!/bin/bash
export DYLD_LIBRARY_PATH=/path/to/instantclient
#=============================================================================
# Launcher for Oracle SQL Developer
# Copyright (c) 2005, Oracle. All rights reserved.
#=============================================================================
...
If you're comfortable editing files, you can set the library path in the internal startup script. I edited this through Terminal.app and vim, by going to:
cd <wherever SQL Developer was installed/unzipped>
cd SQLDeveloper.app/Contents/MacOS
cp -p sqldeveloper.sh sqldeveloper.sh.backup
chmod o+w sqldeveloper.sh
vim sqldeveloper.sh
The file is protected by default, so I'm changing it to be writable (and making a backup first, just in case). If you skip that step, with vim you can save it with :w! to save it anyway.
Alternatively find the SQLDeveloper application in Finder, right click, and choose 'Show Package Contents', then drill down to Contents->MacOS, right-click the sqldeveloper.sh file and choose 'Open With' and your favourite text editor - TextEdit will do. As the file is locked you will be prompted to unlock it at some point - maybe on open or first edit, but TextEdit will ask you if you want to unlock it when you save.
However you get into the file, you can then specify add a line to set/export DYLD_LIBRARY_PATH:
#!/bin/bash
# Next line added for TNS connections
export DYLD_LIBRARY_PATH=/path/to/instantclient
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
here="${0%/*}"
cd "${here}"
cd ../Resources/sqldeveloper/sqldeveloper/bin
bash ./sqldeveloper -clean >>/dev/null
... where /path/to/instantclient is your unzipped directory; in the quoted example above, that would be /bin/oracle/instantclient_11_2. Also note that this needs to be the 64-bit instant client; it will complain about the wrong architecture if you try to use the 32-bit version.
One the modified file has been saved, relaunch SQL Developer and your TNS connection should now work. If you want to be able to use a TNS alias you can also set/export a TNS_ADMIN variable that points to a directory containing a tnsnames.ora file.

Is it possible to update svn using a windows environmental variable folder?

I have tortoiseSVN installed alongside subversion for windows (not using TortoiseSVN command client tools because of restrictive purposes).
I have a batch file that runs an svn update on certain folders which are used as environmental variables in Windows. Is it possible to svn update a folder using just the folder name?
e.g. from this:
cd C:\foo\johnsmith\testing\
svn update
to something like this?
cd testing\
svn update
I should add that environmental variables are new to me...
With regards to Alrocs comment, the path C:\foo\johnsmith\testing\ is in the system environmental variable "Path".
You can't cd to directory, which is part of your $PATH$. But you can use environment variable, which explicitly contain needed path only (after all - variable is just string)
c:\TEMP>echo "%USERPROFILE%"
"C:\Documents and Settings\Badger"
c:\TEMP>cd "%USERPROFILE%"
C:\Documents and Settings\Badger>
Never assume anything about environment variables that you haven't set via your batch file. Just because it's there today/on your computer doesn't necessarily mean it'll be there tomorrow or on another computer.
But you aren't using an environment variable in your script in the first place.
If you need to update a specific path, be explicit and update that path by specifying the whole path. Don't assume that your testing directory will be an immediate child of the directory you're running the batch file in unless you can control everything else - the whole subdirectory structure, where the batch file executes from, and how it executes.

Resources