Import oracle dump file into Oracle using cx_Oracle

3.8k views Asked by At

I am trying to import dump file into Oracle using cx_Oracle. I am able to execute command by command. Can any one suggest how to do this?

I'm currently using:

imp servicely/tiger@ubuntu file=/home/hemalatha/hemalatha_data/test_data/oracle/schema_only.sql full=y. 

But, I'm getting the error: IMP-00037: Character set marker unknown

1

There are 1 answers

4
Luke Woodward On

I think you are confused about what you actually have.

You say

I am able to execute command by command

and also your supposed import file has a .sql extension. I think you have a script full of SQL statements. You do not have an export file, which is a binary file generated by exp or expdp. imp and impdp are used to import the files generated by exp and expdp respectively. They will act confused if you give them a SQL script to run.

If you have a SQL script to run against the database, use SQL*Plus. Here's a simple SQL*Plus script which doesn't do much:

PROMPT Hello, we are in SQL*Plus

SELECT * FROM DUAL;

Here's a simple Python script to run this script in SQL*Plus and display the output:

import subprocess

script = subprocess.Popen(["sqlplus", "-L", "user/password", "@script.sql"],
                          stderr=subprocess.STDOUT, stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE)
script.stdin.close()  # Force SQL*Plus to exit after reading script.
for line in script.stdout:
    print line.rstrip()

Note that we need to connect to SQL*Plus's input and close it, as otherwise SQL*Plus will not exit and the script will hang.

When I run this, I get the following output:

SQL*Plus: Release 11.2.0.2.0 Production on Mon May 26 14:22:34 2014

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production

Hello, we are in SQL*Plus

D
-
X

SQL> Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production