Export .sql dump - sql

I have to make a dump file with the extension .sql, what is the correct way to do this? I am using Oracle database Express Edition 10g. Would this work fine if I enter it in the cmd?
expdp system/system_password full=Y EXCLUDE=SCHEMA:\"LIKE \'APEX_%\'\",SCHEMA:\"LIKE \'FLOWS_%\'\" directory=DUMP_DIR dumpfile=DB1.sql logfile=expdpDB10G.log

expdp creates a dump file, which can only be used by impdp and cannot be run as a SQL script, so it doesn't make sense to name it with the .sql extension.
I prefer to name it with something like .dmp so that it's clearer what it contains.

Related

Is there an alternative way to import data into Postgres than using psql?

I am under strict corporate environment and don't have access to Postgres' psql. Therefore I can't do what's shown e.g. in the SO Convert SQLITE SQL dump file to POSTGRESQL. However, I can generate the sqlite dump file .sql. The resulting dump.sql file is 1.3gb big.
What would be the best way to import this data into Postgres? I also have DBeaver and can connect to both databases simultaneously but unfortunately can't do INSERT from SELECT.
I think the term for that is 'absurd', not 'strict'.
DBeaver has an 'execute script' feature. But who knows, maybe it will be blocked.
EnterpriseDB offers binary downloads. If you unzip those to a local drive you might be able to execute psql from the bin subdirectory.
If you can install psycopg2 or pg8000 for python, you should be able to connect to the database and then loop over the dump file sending each line to the database with cur.execute(line) . It might take some fiddling if the dump file has any multi-line commands, but the example you linked to doesn't show any of those.

How to import external sql scripts from a sql script in PostgreSQL?

I was wondering if it is possible/how to include one .sql file in another .sql file, as is done in other programming languages like C or Java?
I am asking because I wanted to organize my sql scripts into support library files and application scripts, and so on. I searched around, and solutions seem to be about loading .sql files from the psql client (see e.g. postgreSQL - psql \i : how to execute script in a given path). What I am interested in is to load a library .sql script from inside a sql script.
P.S. I am using PL/pgSQL (PostgreSQL 9.3).
Based on the answer It is possible to reference another SQL file from SQL script, on PostgreSQL, you can include another SQL's files just using the \i syntax. I just tested and is working good on PostgreSQL 9.6:
\i other_script.sql
SELECT * FROM table_1;
SELECT * FROM table_2;

How do I transfer an Postgres SQL Function from a 9.3 DB to another computer with same version?

I have a working function that was created and want to just transfer it to another newly installed Postgres DB.
I have checked around and seeing command line options which seems kinda of dry for a common task?
Is there a module import / export option?
I have exported the function into a .sql file from the database, so just looking for an import option.
I know very little about Postgres :)
How did you export it? If it exported as sql into a file named file_name.sql, you would just do:
psql -f file_name.sql
With whatever additional parameters are needed to connect to the correct server and database.

Importing .sql file into IBM DB2 Express-C

Hello I' new to IBM DB2 Express-C
I have a exported a database to .sql file (Original database stored in SQLite3 - used SQLite SQLite Manager for exporting the the database to a .sql file)
Can anyone please tell a way to import a this .sql file into DB2. Thank you
If you want to execute a set of sentences in a file in DB2, you issue in the command line (db2clp):
db2 -tvf <filename>
For exmpale, for your file
db2 -tvf myfile.sql
However, the content of that file could not be compliant with DB2, and you have to modify it, in order to run correctly in DB2.
Basic Create tables, and DML (insert, delete, update) are SQL 92 standard accross many database. But if you have create bufferpool, tablespaces, and other kind of objects, you have tomodify the file a lot.

Mysql: How to call sql script file from other sql script file?

Suppose I have wrote script Table_ABC.sql which creates table ABC. I have created many such scripts for each of required tables. Now i want to write a script that call all of these script files in a sequence so basically I want another script file createTables.sql. Mysql provides option to execute a script file from "mysql" shell application but could find some command like exec c:/myscripts/mytable.sql. Please tell me if there is any command that can be written in sql script itself to call other one in latest mysql versions or alternative for same.
Thanks
You can use source command. So your script will be something like:
use your_db;
source script/s1.sql;
source script/s2.sql;
-- so on, so forth