Sql script files to recreate SYS objects in Oracle 9i
Hello all.
I am working with a test Oracle database which is missing some SYS objects. (Oracle 9i).
I was wondering if Oracle has any scripts that I can run and recreate those?
Thank you,
Sonya
catalog.sql only creates the data dictionary views , not the underlying tables and indexes.
(sql.bsq is the "internal" script that is executed to create objects in the SYS schema when a CREATE DATABASE command is issued --- but Oracle will not support anyone attempting to use this script directly).
Hemant K Chitale
Similar Messages
-
Calling a sql script file from a function.
Hi,
I need to call a sql script file from a user defined function. Currently i am trying to do this in Oracle SQL Developer. i tried calling with
@ {filename}, EXECUTE IMMEDIATE etc, but nothing worked. I get the Compiler error.
Basically my need is to call catldap.sql file so that DBMS_LDAP package gets loaded and then I can call the API functions from this.
Please let me know if this is possible doing in a PL/SQL function.
thanks,
Nareshuser784520 wrote:
I need to call a sql script file from a user defined function. Not possible.. and it seems that you do not fully understand the client-server within the Oracle context.
All SQL and PL/SQL are parsed and executed by an Oracle server process. The SQL and PL/SQL engines each expects a single command block at a time. Neither of these can accept a series of separate commands as a single call and then execute each in turn. The SQL engine expects a single SQL statement at a time. The PL engine expects a single PL/SQL anonymous block at a time.
This server process also cannot break into the local file system to access script files. Nor can it hack across the network to access script files on the client.
In order for the server process to access local files, a directory object needs to be created and the current Oracle schema needs read and/or write access on that directory object. As sound security principles apply.
There's no PL/SQL command to execute a script. You must not mistake SQL*Plus commands (this client has a very limited vocabulary) with PL/SQL commands. SQL*Plus executes its own commands.. and send SQL and PL/SQL commands (a statement block a time) to the Oracle server process to be serviced and executed.
It is also a very bad idea to execute external script contents from inside an Oracle server process - as that script resides externally and thus outside Oracle's security mechanisms. This means that is is pretty easy for someone to access that script, compromise it, and then have you inject and execute the contents of that script into the database.
It is not sound security.
Last issue - it is even worse to have application PL/SQL code dynamically creating (or trying to create) portions of the Oracle data dictionary and PL/SQL call interface.
The database needs to be installed correctly - and this includes loading and executing the required rdbms/admin scripts during database installation. It does not make sense at all for application code to try and execute such scripts. It raises numerous issues, including having to allow that application code full and unrestricted SYS access to the database instance. A very serious security violation.
I do not agree at all with the approach you want to use. -
How can I run a SQL script file...
How can I run a SQL script file from a location on my computer without providing the whole path?
Is there some way I can set a "Working folder" in SQL Plus??
Thanks!
TomYou can create an environment variable called "SQLPATH" which is a list of directories that SQL*Plus will search for your .SQL
scripts.
I would like to use another directory than the oracle/bin...
How can I do this ??
Hello,
U can do this by this way:
Save odm_script.sql file to the default Oracle
directory i.e. Oracle-Home/bin and Run following command
through SQL Plus.
SQL>@Script_Name
I hope this will resolve ur problem.
Regards,
Omer Saeed Khan. -
Hi everyone,
I want to accomplish a task in TFS that I need to auto generate the database changes as SQL script file in drop folder for every build.
For ex.: If I add a table in a database and then check in the changes, I need to get that create table script in the drop folder as .sql file extension
I want to automate the build too for every check in. Help me out and guide me a step by step procedure because since I am new to TFS build in visual studio.
ThanksCheck out SSDT:
https://msdn.microsoft.com/en-us/data/tools.aspx
It can generate a DACPAC which can be used to update a SQL Database through the commandline. To ensure that the .sql file executed is compatible with the target database schema it contains a compiled version of teh schema and will generate the change script
on-the-fly.
If you want, you call SqlPackage,exe to generate a SQL script if you want to inspect it before executing.
https://msdn.microsoft.com/en-us/library/hh550080%28v=vs.103%29.aspx
My blog: blog.jessehouwing.nl -
Running sql script files to re create database
We have having around 10 sql script file that has sql statments inside it (example insert .... delete...update.... etc).Right now what we do is that in jdbc we open each script file, and read each line ,and then make jdbc call run jdbc for each sql statement inside the file.
Wondering if there is a better way to do this.
Right now the challenges are
1)The process goes wrong if there is an extra semi colon ...or extra space after a statments...etc...Basically I find this way of creating data odd...
2)it is slow because of the network traffic between application server and database server for every sql statements that gets executed.The solution for this issue is to do a batch update....But still I dont like this solution.
Can someone give me any better idea.
I am thinking to have all this sql script moved to a store procedure (rather than inside the sql script file) .JDBC then can pick this store procedure sql file ,and create this store procedure via jdbc, and then execute this store procedure.
This will be faster because all the sql will be running in the databsase.Only one trip to database to call this store procedure.
Is this a good idea ?
thx
mManjit wrote:
We have having around 10 sql script file that has sql statments inside it (example insert .... delete...update.... etc).Right now what we do is that in jdbc we open each script file, and read each line ,and then make jdbc call run jdbc for each sql statement inside the file.
Wondering if there is a better way to do this.
Right now the challenges are
1)The process goes wrong if there is an extra semi colon ...or extra space after a statments...etc...Basically I find this way of creating data odd...
2)it is slow because of the network traffic between application server and database server for every sql statements that gets executed.The solution for this issue is to do a batch update....But still I dont like this solution.
Can someone give me any better idea.
I am thinking to have all this sql script moved to a store procedure (rather than inside the sql script file) .JDBC then can pick this store procedure sql file ,and create this store procedure via jdbc, and then execute this store procedure.
This will be faster because all the sql will be running in the databsase.Only one trip to database to call this store procedure.
Is this a good idea ?
thx
mI'm not 100% sure i follow (it's Friday and i have a mild case of ADD).
Are you suggesting having the Java application create procedures in the database on the fly? If so i would say that's not a good idea.
Create the stored procedures in the database, have Java call them as needed to process data.
If you need to load copious amounts of data, look in to external tables, it's possible they could come in handy for what you are doing .... or not ... again, it's hard to say given i find your description of what's currently happening somewhat confusing. -
Not able to read sql script file in ADF mobile
hi,
i am trying to create some DB tables in SQLLite DB (similar to the HR sample app where it creates bunch of DB objects using hr.sql file in .adf/META-INF)..
but i am getting following error at runtime. i placed the file in .adf/META-INF directory in my application.
"sqllite returned: error code=14, msg = cannot open file at source...."
what am i missing here?
please help.
regards,
adThis how I have done it.
This is the start method from my Listener:
public void start()
String databaseName = "mydatabase";
File dbFile = new File(AdfmfJavaUtilities.getDirectoryPathRoot(AdfmfJavaUtilities.ApplicationDirectory)+"/"+databaseName+".db");
if(!dbFile.exists())
try {
this.initializeDatabase(databaseName);
} catch (Exception e) {
System.out.println(e.getMessage());
}And this is a custom method also in the listener class
private static void initializeDatabase(String databaseName) throws Exception
List stmts = null;
try {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
InputStream is = cl.getResourceAsStream(".adf/META-INF/"+databaseName+".sql");
if (is == null) {
// .sql script not found
BufferedReader bReader = new BufferedReader(new InputStreamReader(is));
stmts = new ArrayList();
String strstmt = "";
String ln = bReader.readLine();
while (ln != null) {
if (ln.startsWith("REM") || ln.startsWith("COMMIT")) {
ln = bReader.readLine();
continue;
strstmt = strstmt + ln;
if (strstmt.endsWith(";")) {
System.out.println(strstmt);
stmts.add(strstmt);
strstmt = "";
ln = bReader.readLine();
continue;
ln = bReader.readLine();
String Dir = AdfmfJavaUtilities.getDirectoryPathRoot(AdfmfJavaUtilities.ApplicationDirectory);
String connStr = "jdbc:sqlite:" + Dir + "/"+databaseName+".db";
Connection conn = null;
conn = new SQLite.JDBCDataSource(connStr).getConnection();
conn.setAutoCommit(false);
for (int i = 0; i < stmts.size(); i++)
Statement pStmt = conn.createStatement();
pStmt.executeUpdate((String)stmts.get(i));
conn.commit();
conn.close();
} catch (Exception ex)
ex.printStackTrace();
}My .sql scrip named "mydatabase.sql" located in the ADF META-INF folder.
See this picture :
http://upload.wiim.be/img/Screenshot%20at%20jan.%2019%2011-39-30.pngDon't forget the register your Listener class to the adfmf-application.xml file!
http://upload.wiim.be/img/Screenshot%20at%20jan.%2019%2011-42-24.png -
Using an SQL Script file to create database in Java? (monkeyDB.sql)
Hello!
I am a writing an SQL Script so that I can re-create my database on another server (im using my laptop to test it on first though).
I'm connecting to mySQL server using JDBC which works fine, but I was wondering
how can I run an entire script file, say myScript.sql from within a Java class??
(an SQL Script is simply a file containing the regular SQL commands and expressions that you might enter at an sql command line prompt)
example of an SQL Scritp: monkeyDB.sql>>
//#create new db
CREATE DATABASE sample_db;
//#set active db
USE sample_db;
//#set table paramaters
CREATE TABLE monkeys
(name CHAR(20),
age INT UNSIGNED,
sex ENUM('M','F')
//#create standard monkeys
INSERT INTO monkeys(name,age,sex) VALUES("Sammy",10,"M");
INSERT INTO monkeys(name,age,sex) VALUES("Muncht",12,"M");
INSERT INTO monkeys(name,age,sex) VALUES("Jill",8,"F");
//#get recordset
SELECT * FROM monkeys WHERE age < 50;Thanks for your help!thanks. :-)
I thought about that too but I didnt want to hard wire it into the code.
I guess it isnt possible to output the script file using some command from the sql library..? -
How to execute a .SQL script file?
Hi
I'm sure this question has been answered already, however I was unable to find an answer using the search tool.
Using c# I'd like to run a .sql file. The sql file contains multiple sql statements, some of which are broken over multiple lines. I tried reading in the file and tried executing the file using ODP.NET ... however I don't think ExecuteNonQuery is really designed to do this.
So I tried using sqlplus via spawning a process ... however unless I spawned the process with UseShellExecute set to true sqlplus would hang and never exit. Here's the code that DOESN'T WORK.
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "sqlplus";
p.StartInfo.Arguments = string.Format("xx/xx@{0} @{1}", in_database, s);
p.StartInfo.CreateNoWindow = true;
bool started = p.Start();
p.WaitForExit();
WaitForExit never returns .... Unless I set UseShellExecute to true. A side effect of UseShellExecute is that you can no capture the redirected output.
This must be such a common thing to do, I'm hoping someone has a solution to this.
Thanks
RichIf by "SQL script" you mean run a program that resides outside the database (a file of the format whatever.sql) then the answer is with difficulty. We can use extproc calls to run c libraries or embedded java to execute host-style commands but it's a lot of pfaffing about.
The easiest solution is to bring the SQL commands into the database as a stored procedure. If you still need to be able to run the script externally then rewrite that to call the same stored procedure. However, if the .SQL file includes OS calls then you will have to choose either Java or extproc, depending on what it is the script actuually does. If you want more focused advice you'll need to give us details.
Cheers, APC -
Executing .sql scripts file from command prompt
I had created the .sql scripts for
--Create Database
--Create tables
--Create Stored procedure
I am using SQL server 2008.
Now i want to deploy it into the target server using the command prompt.
How can I call to execute that script on the target server?with few errors as "Incorrect Syntax near "GO"".
Hello,
GO is a command, which is only known & interpretted by SSMS + SqlCmd.exe; SQL Server engine / data access components don't know this command, therefore you get an error.
See
Query Options Execution (General Page); for SSMS you can change it from GO to any other term.
Olaf Helper
[ Blog] [ Xing] [ MVP] -
Store file streams into dicom object in oracle 11g (BLOB construct)
The datastream is transfered from network and stored into oracle DB as a blob , then I use the Dicom construct to build the dicom object . The problem is , before I have the blob in the DB , I have to create an empty Blob object ,I use this this empty blob and do the datastream store .
Does somebody have the idea ,how to directly store the datastream into the DB BLOB ,or can I put this BLOB as the variable in JAVA .
my program like this :
stmt.executeUpdate("insert into blob_tbl(id,my_blob) values('" + in + "',empty_blob())");
ResultSet rs = stmt.executeQuery("select my_blob from blob_tbl where id='" + in + "' for update" );
if(rs.next())
Blob blob = rs.getBlob(1);
OutputStream out = ((oracle.sql.BLOB)blob).getBinaryOutputStream();
byte[] b = new byte[((oracle.sql.BLOB)blob).getBufferSize()];
InputStream fin = inStream;
int len = 0;
while( (len = fin.read(b)) != -1)
out.write(b,0,len);
fin.close();
out.close();
conn.commit();The datastream is transfered from network and stored into oracle DB as a blob , then I use the Dicom construct to build the dicom object . The problem is , before I have the blob in the DB , I have to create an empty Blob object ,I use this this empty blob and do the datastream store .
Does somebody have the idea ,how to directly store the datastream into the DB BLOB ,or can I put this BLOB as the variable in JAVA .
my program like this :
stmt.executeUpdate("insert into blob_tbl(id,my_blob) values('" + in + "',empty_blob())");
ResultSet rs = stmt.executeQuery("select my_blob from blob_tbl where id='" + in + "' for update" );
if(rs.next())
Blob blob = rs.getBlob(1);
OutputStream out = ((oracle.sql.BLOB)blob).getBinaryOutputStream();
byte[] b = new byte[((oracle.sql.BLOB)blob).getBufferSize()];
InputStream fin = inStream;
int len = 0;
while( (len = fin.read(b)) != -1)
out.write(b,0,len);
fin.close();
out.close();
conn.commit(); -
How to run SQL script file on Linux using Java ?
Hi,
I need to execute .sql file using java. I used following approach for this.
private void runScriptEvent(java.awt.event.ActionEvent evt) {
String sqlOutput = "";
String sqlPromptLines="";
String currentFunctionName = "";
if(con!=null){
String userName = jTextField4.getText();
String password = jPasswordField1.getText();
String databaseName = jTextField3.getText();
try {
String script_location = "";
ProcessBuilder processBuilder =null;
Process process = null;
//File file = new File("C:/ScriptFile");
File file = new File("./SQL_Script");
//File file = new File("E:\\install\\SQL_Script");
if(file.exists()){
File [] list_files= file.listFiles(new FileFilter() {
public boolean accept(File f) {
if (f.getName().toLowerCase().endsWith(".sql"))
return true;
return false;
int count = 0;
for (int i = 0; i<list_files.length;i++){
script_location = "@" + list_files.getAbsolutePath();//ORACLE
//currentFunctionName = list_files[i].getName();
StringTokenizer st = new StringTokenizer(list_files[i].getName(), ".");
while(st.hasMoreTokens()) {
currentFunctionName = st.nextToken();
String extention= st.nextToken();
System.out.println("Function Name = "+currentFunctionName + "\t Extention = " + extention);
processBuilder = new ProcessBuilder("sqlplus",userName+"/"+password+"@"+databaseName, script_location); //ORACLE
processBuilder.redirectErrorStream(true);
process = processBuilder.start();
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String currentLine = null;
while ((currentLine = in.readLine()) != null) {
sqlPromptLines = " "+sqlPromptLines + currentLine +"\n";
count ++;
System.out.println(count+" " + currentLine);
if(currentLine.equalsIgnoreCase("Function created.")){
sqlOutput = "\n" sqlOutput currentFunctionName + " " currentLine"\n" ;
break;
}// end while
in.close();
process.destroy();
}//end for
}//end if file exists
} catch (IOException e1) {
jTextArea1.setText(e1.getMessage());
System.out.println("Script Done");
jTextArea1.append(sqlOutput);
}// end id Connection is not null
Above code working appropriate on Windows but not on Linux.
is there any changes needed ?
Regards,
Ajay
Edited by: Ajay Sharma on Nov 21, 2012 6:43 PMHi gimbal2,
about code
jTextArea1.setText(e1.getMessage());I am using this code so that the user will be prompted with a message rather than stack trace.
About the issue I am getting on linux i believe its because of following statement.
processBuilder = new ProcessBuilder("sqlplus",userName+"/"+password+"@"+databaseName, script_location); //ORACLERegards,
Ajay
Edited by: Ajay Sharma on Nov 23, 2012 12:05 PM
Edited by: Ajay Sharma on Nov 23, 2012 12:06 PM -
Can i comment out lines of code in a .sql script file to be run in SQL PLUS
Hi All,
I have commented out part of the script, and when i ran the script (.sql) file in Sql*Plus
I am getting some errors like
SP2-0734: unknown command beginning
how to avoid these errors?
any help is appreciated
Thanks
R.R>
select * from dual; -- me too!Nope, not this one...
test@ORA10G>
test@ORA10G> host type c:\test.sql
select * from dual; -- me too!
test@ORA10G>
test@ORA10G> -- doesn't work
test@ORA10G>
test@ORA10G> @c:\test.sql
2
test@ORA10G>
test@ORA10G> @c:\test.sql
2 /
select * from dual; -- me too!
ERROR at line 1:
ORA-00911: invalid character
test@ORA10G>
test@ORA10G> -- now this works...
test@ORA10G> host type c:\test.sql
select * from dual -- me too!
test@ORA10G>
test@ORA10G> @c:\test.sql
D
X
test@ORA10G>
test@ORA10G> -- and so does this...
test@ORA10G> host type c:\test.sql
select * from dual -- me too!
test@ORA10G>
test@ORA10G> @c:\test.sql
D
X
test@ORA10G>
test@ORA10G>pratz -
Will invalid SYS objects cause Oracle 9.2.0.8 thread to crash?
Hi Experts
Here is a brief account of what happened...
1) In Toad, login as sys to modify a function in a user schema
2) Created this function in sys schema by mistake and it was invalid. Error PLS-00201: identifier 'LOT.LINECODE' must be declared and error PL/SQL: Compilation unit analysis terminated were encounterd in for this function in sys schema. No further action was taken here <--- root cause??
3) Proceed to modify the function in the correct user schema.
4) Ard hour later at 10:59am, i received a <SID>core.log, no details in alert.log or trace file was given. Winows scheduled jobs before and after this timing were able to complete successully.
5) Restarted db and server and operated as usual. (9i no more support from Oracle)
First, my question is, what are the chances of the invalid function in SYS schema causing me to receive a <SID>core.log or causing the db to experience weird performance issue?
Second, should i use sys credentials only for starting and stopping the database? And log in as the user schema for compilation?
Thanks for your help.SYS should only be used for DBA duties - not for developing and compiling user code.
No, creating a user object (even an invalid one) will not cause the Oracle instance to crash. The critical components in the SYS schema are the data dictionary - and a user object created in SYS would not "damage" the data dictionary, unless it replaces an existing data dictionary object. -
How does SQL*PLUS read script files
Hello!
well, it is possible to start sqlplus with an sql script file:
sqlplus user/pass@srv @my_script.sqlok, so what happens if I delete the file my_script.sql ?
My script here is about 1 GB big! sqlplus was half way done when I deleted the file.
Is the sqlplus going to stop with an error? Or just hang?
I copied the my_script.sql file now to the folder again and I think that sqlplus is still working fine. But can I be sure, that all statements in the script have been processed?
Thanks in advance!Results are OS dependent which you declined to share with us.
I suspect *NIX & not Windoze.
On Windoze, you can not delete open file.
On *NIX open file does not actually get deleted until fclose() is called.
All in all, you are OK. -
Hi,
I am working on a perl script to test if the sql script file prepared by the Dev team can be deployed to the DB without any issue or not. My intention is not to run the script but only to check if the script will run properly without any error at the time of actual deploy or not. Is there a way wherein I can mimic the execution of the script?
consider, I has a script file CreateTable.sql which contains CREATE TABLE statement. I dont want the table to be created by mimic actual run of this script against the database. How do I do that?
TIA
-Onkaronkar.nath wrote:
I am working on a perl script to test if the sql script file prepared by the Dev team can be deployed to the DB without any issue or not. My intention is not to run the script but only to check if the script will run properly without any error at the time of actual deploy or not. Is there a way wherein I can mimic the execution of the script?
consider, I has a script file CreateTable.sql which contains CREATE TABLE statement. I dont want the table to be created by mimic actual run of this script against the database. How do I do that?Do that by being creative? ;-)
Not possible using PL/SQL. PL/SQL has a a very flexible DBMS_SQL cursor interface - that amongst other things allow you to parse a statement into a cursor. However, a parse call also automatically executes if the parsed cursor is a DDL. With DML, you can parse and not execute.
The only other way that comes to mind is using the EXPLAIN PLAN command in the SQL language. E.g.
SQL> explain plan
2 set statement_id = 'ddl.parse.1'
3 for create table testtab2 nologging as select * from user_objects;
Explained.
SQL> --//object not created
SQL> desc testtab2
ERROR:
ORA-04043: object testtab2 does not existThere could perhaps be a method using the OCI (Oracle Call Interface) to parse a DDL without executing it. Are you using Perl-DBI? In that case you may want to look at the OCI and how Perl-DBI exposes that - and whether a DDL can be parsed as cursor without executing it.
Maybe you are looking for
-
A couple of days ago my iPad died, so I plugged it in to charge. It went into a rebooting loop, and when I looked up how to fix this, I saw that I can put my iPad into DFU mode to fix certain things like this. I did, not thinking much about it becaus
-
I was using my Kyocera 1320 d just fine. Now, I went to print a document, and the computer won't connect to the printer. In the system preferences, it won't even appear. I restarted it, deleted the old printer, reinstalled the drivers. I can't ev
-
Hello Community If you have a clustered Sharepoint 2013 Server farm running RAID 10, on a clustered WS2012 R2 server that has 10 hard drive slots: (4) drives being part of the Sharepoint 2013 Server farm (1) drive for the Web App
-
Back up from iPhone 4 to iPhone 5 not working
Hi Guys, I have been using an iPhone 4, doing regular backups. My son bought me a iPhone 5 and I did a restore from iTunes as I need the text messages from the iPhone 4. I have now done a complete restore on the iPhone 5 as every time I restore a bac
-
Validating an XML document using external DTD?
Hi, I want to validate an XML file using external DTD with SAX parser. How can I validate an XML file with external DTD. Thanks in Advance, Mahendra