I have a .ksh file from which I connect to Oracle DB at various environments using sqlplus as below
sqlplus -s $O_USER/$O_PASS#$O_DATABASE <<-EOF
Now, I need to read a properties(.txt) file from sqlplus for dynamically creating a url parameter and this file is located at client side. Is there any way to do this ? I'm ok with reading this via shell script and passing to sqlplus. I'm able to access some string variables in shell script from sqlplus, but is there a way to pass a hash map kind of object from shell script to sql plus ?
A few notes below :
I can't use UTL_FILE because the properties file should be located at client side only. Because I'm developing a monitoring tool for an application which is connected to the application in various environments and I don't want to or I don't have enough permission to put this properties file in each of those environments. So I want to store this properties file at a single place (client side)
I can't use TEXT_IO because I'm not using Oracle forms.
I don't want to put all these properties hard coded in the .ksh file (which will actually work) because there are more than 150 key-value pairs
I'm an accidental DBA. We have oracle database running on windows server.
I created an oracle directory object named 'Result' and mapped it one of the local drives (C:\appResult) on the database server. The front end application creates a report and writes the file to 'Result' and a file thus gets written to C:\appResult. Now, we want to change the file path 'C:\appResult' to some other server in the network (another server in the network). What is the best way to achieve this?
Use the CREATE OR REPLACE DIRECTORY... variant of this command:
CREATE OR REPLACE DIRECTORY RESULT AS '\\ServerName\ShareName\SomeOtherDir'
Share and enjoy.
I have a problem in oracle database. I am having a database on which a service is hosted and hence I am not able to see the drives or folders of oracle database. Hence, the procedures using utl_file have stopped working as directory path is invalid now.
How will I read and write on OS file system ? I need to pull out reports from joining 2-3 tables of oracle and pull data out in flat file. where as external tables, and utl_file cannot work as directory path cannot be defined due to hosting layer the oracle OS layer is invisible.
Also, mounting of database is also not permitted and privileges to create directory is also not given.
Could you pleas , please help me. Thanks.
If you have sysdba privileges on the box, do something along the following lines:
SQL> CREATE DIRECTORY log_dir AS '/appl/gl/log';
SQL> GRANT READ ON DIRECTORY log_dir TO DBA;
SQL> GRANT WRITE ON DIRECTORY log_dir TO DBA;
If you do not have these privileges, then ask the hosting company to do it. In addition you can always write a report file with sqlplus on your local drive.
I have downloaded the "Precompiled Binaries for windows" for the "SQLite" from here. I opened the command-line-shell and followed this, creating one table named "tbl1".
now I am looking at my desk trying to find the database file which contains tbl1, but I can't find it anywhere.
my question is: after creating a database in the SQLite, where the database file is stored ? i.e.: what is the path of my created-database ?
I am using windows7 and have basic knowledge about SQL and database
By default (if no additional path is specified), the database is created in the current working directory.
That is, sqlite.exe ex1 creates the "ex1" database in the current directory. (Use cd from the same command shell to see what what the current working directory is.)
On the other hand, sqlite.exe C:\databases\ex1 would create the "ex1" database in the "C:\databases" directory.
To create the database on the desktop for the current user, something sqlite.exe "%USERPROFILE%\Desktop\ex1" should work. (This uses an environment variable called USERPROFILE which is expanded and used as part of the path.)
The same principle holds for any SQLite connection - the path to the database file is first resolved; either relative (as in the first case) or absolute (as in the second and third).
It creates the DB file in the given file path else by default it will create the file in your current working directory. If you can't find it then just search for the .db file inside your current project directory.
Where is the SQLite database stored i.e. directory path on windows 7 when created ?
A SQLite database is a regular file. It is created in your script current directory.
.databases
If you run this command inside SQLite
.databases
it lists the path of all currently connected databases. Sample output:
seq name file
--- --------------- ----------------------------------------------------------
0 main /home/me/a.db
There is no "standard place" for a sqlite database. The file's location is specified to the library, and may be in your home directory, in the invoking program's folder, or any other place.
If it helps, sqlite databases are, by convention, named with a .db file extension.
If you are running Rails (its the default db in Rails) check the {RAILS_ROOT}/config/database.yml file and you will see something like:
database: db/development.sqlite3
This means that it will be in the {RAILS_ROOT}/db directory.
When you call sqlite3_open() you specify the filepath the database is opened from/saved to, if it is not an absolute path it is specified relative to your current working directory.
It depends on how you initialized the database. If you used the command line shell for SQLite (e.g. sqlite3 ex1) to create the database, it'll be a path from the root of your local machine. If you used a Python script to create the database, it'll be a path from your project.
To check the former, run the command line shell:
sqlite3
sqlite> .databases
To check the path in your project, you can print the path in the connection. For example:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DATABASE = 'db'
def get_db_connection():
print(os.path.join(BASE_DIR, DATABASE, "database.db"))
conn = sqlite3.connect(os.path.join(BASE_DIR, DATABASE, "database.db"))
conn.row_factory = sqlite3.Row
return conn
In my case I think it was an access issue. I saved the SQLite files to "C:/Program Files (x86)/sqlite". I CD'd there, ran sqlite3, and created a database called test.db:
As you can see, I ran .database, which told me the .db file was created in the same directory, so I went to confirm in File Explorer, and it wasn't there:
Curiously the database was working correctly in spite of this.
It was only through trial-and-error that I discovered that I could save in some locations, but not others. It appears to me that SQLite can't save to locations that require elevation. In my case, moving from Program Files to My Documents made the issue go away.
I find it quite irritating that SQLite doesn't just tell me "access denied" instead of trying to be clever and saving to some location that I can't even find.
In Windows machines (Windows 2010), by default, the new SQLite database files will be stored in the same folder where Sqlite3.EXE application is stored in your machine. However , we can create a new folder in Windows and within sqlite> prompt, you may use the .cd to change to the new working directory.
It is a good idea to give a .db file extension to the new database files that you create (even though it is not mandatory to have any file extension)
The SQLite command, .databases will show the default database "main" or currently created or currently opened database or all "attached" database files with file path. The .attach is useful to attach more than one database file to the current connection when we want to work with tables belonging to different databases.
Regards,
Biju Joseph N.,
Houston TX, USA (January 12, 2023)
the database path will be displayed, when using .databases
SQLite is created in your python directory where you installed the python.
SQLit Database is simply a file where your local data is stored on your local machine
In Windows 10 if in the prompt command the path where you start sqlite is
C:\users\USER_NAME
You can find it in the user home folder.
The .db file is stored where you start the sqlite command.
I hope this solve the issue