Error creating Stored procedure
Hello All,
I am logged in as “system” user and trying to run the below script.
create or replace procedure verify_job_not_running (my_job_name IN varchar2)
AS
my_job_count NUMBER;
BEGIN
select count(*) into my_job_count from dba_datapump_jobs where job_name = my_job_name;
IF my_job_count > 0 THEN
raise_application_error(-20010, 'data pump job already running');
END IF;
END verify_job_not_running;
The above procedure is created with compilation errors. Please see the error message below.
SQL> show errors;
Errors for PROCEDURE VERIFY_JOB_NOT_RUNNING:
LINE/COL ERROR
5/3 PL/SQL: SQL Statement ignored
5/42 PL/SQL: ORA-00942: table or view does not exist
FYI - I am able to query “dba_datapump_jobs” table as “system”.
Any help will be appreciated.
Thank you,
Hi,
user504183 wrote:
Hello All,
I am logged in as “system” user and trying to run the below script.Very, very bad idea.
Never create objects in Oracle-supplied schemas like SYSTEM, SYS, even HR.
Create your own schema (you can call it my_system) for your own SYSTEM-like objects.
create or replace procedure verify_job_not_running (my_job_name IN varchar2)
AS
my_job_count NUMBER;
BEGIN
select count(*) into my_job_count from dba_datapump_jobs where job_name = my_job_name;
IF my_job_count > 0 THEN
raise_application_error(-20010, 'data pump job already running');
END IF;
END verify_job_not_running;
The above procedure is created with compilation errors. Please see the error message below.
SQL> show errors;
Errors for PROCEDURE VERIFY_JOB_NOT_RUNNING:
LINE/COL ERROR
5/3 PL/SQL: SQL Statement ignored
5/42 PL/SQL: ORA-00942: table or view does not exist
FYI - I am able to query “dba_datapump_jobs” table as “system”.Roles don't count in stored procedures. SYSTEM probably has privileges on dba_datapubp_jobs only because it has the role SELECT_CATALOG_ROLE.
Log in as SYS and give the necessary privilges directly to the procedure owner (whcih, once again, should NOT be SYSTEM);
GRANT SELECT ON dba_datapump_jobs TO my_system;
Similar Messages
-
Error creating stored procedure using Apex
Hello,
I have worked with Access, SQL Server, and Firebird before, but am new to Oracle. I am trying to create a stored procedure to return the count of multiple hash values in a table. I want to know the number of rows that contain hash values that are duplicates somewhere else in the table. So if my table has 10 rows containing hash values: a, b, a, b, c, d, e, a, b, a, my return value should be 7. Here is my create procedure statement:
CREATE OR REPLACE PROCEDURE CommonHashValuesCount (dupThreshold in number, totalCount out number)
IS
BEGIN
totalCount := 0;
FOR h IN
(SELECT DISTINCT xf.MD5_HASH, COUNT(xf.MD5_HASH) as "HashCount"
FROM XFILE xf
GROUP BY xf.MD5_HASH)
LOOP
IF h.HashCount > dupThreshold THEN
totalCount := totalCount + h.HashCount;
END IF;
END LOOP;
END;
I get the following error when I try and run it:
ERROR at line 12: PL/SQL: Statement ignored
1. CREATE OR REPLACE PROCEDURE CommonHashValuesCount (dupThreshold in number, totalCount out number)
2. IS
3. BEGIN
Can anyone tell me what is wrong with my create statement? Or if anyone knows how to accomplish what I want in a single sql statement, I'd love to hear it!
TIA,
TheresaWhy not do it in a SQL statement so you can test it in the APEX SQL command window?
SELECT Sum(HashCount)
FROM (SELECT DISTINCT xf.MD5_HASH
, COUNT(xf.MD5_HASH) HashCount
FROM XFILE xf
GROUP BY xf.MD5_HASH
WHERE HashCount > <testvalue>
not tested
and then simply put that into your stored procedure/package:
SELECT Sum(HashCount)
INTO totalCount
FROM (SELECT DISTINCT xf.MD5_HASH
, COUNT(xf.MD5_HASH) HashCount
FROM XFILE xf
GROUP BY xf.MD5_HASH
WHERE HashCount > dubThreshold
also not tested
C. -
How can i create stored procedures dynamically?
I have tried to create a stored procedure building a string with the PL/SQL code needed to create the procedure. If i run the code using SQL+ works fine, but using the following code:
Public Sub CreateStoredProcedure()
Dim strSql As String
strSql = "CREATE OR REPLACE PACKAGE OPSPRUEBAS AS " & vbCrLf
strSql = strSql & vbTab & "PROCEDURE consulta (resultado OUT VARCHAR2); " & vbCrLf
strSql = strSql & "END OPSPRUEBAS; " & vbCrLf
strSql = strSql & "/ " & vbCrLf
strSql = strSql & ". " & vbCrLf
strSql = strSql & "CREATE OR REPLACE PACKAGE BODY OPSPRUEBAS AS " & vbCrLf
strSql = strSql & "PROCEDURE consulta (resultado OUT VARCHAR2) IS " & vbCrLf
strSql = strSql & "oc_ref" & vbTab & vbTab & "REF Content_Ontology; " & vbCrLf
strSql = strSql & "oc" & vbTab & vbTab & "Content_Ontology; " & vbCrLf
strSql = strSql & "ori" & vbTab & vbTab & "role_def; " & vbCrLf
strSql = strSql & "ori_ref" & vbTab & vbTab & "ref role_def; " & vbCrLf
strSql = strSql & "conce" & vbTab & vbTab & "concept; " & vbCrLf
strSql = strSql & "conce_ref" & vbTab & "REF concept; " & vbCrLf
strSql = strSql & "b" & vbTab & vbTab & "boolean; " & vbCrLf
strSql = strSql & "BEGIN " & vbCrLf
strSql = strSql & "b:=false; " & vbCrLf
strSql = strSql & "select REF(oi) into ori_ref from rol_table oi where oi.name='Playing'; " & vbCrLf
strSql = strSql & "select deref(ori_ref) into ori from dual; " & vbCrLf
strSql = strSql & "select REF(oi) into oc_ref from c_ontologies oi where oi.web_source_prop=websource('FilmContentOntology'); " & vbCrLf
strSql = strSql & "select deref(oc_ref) into oc from dual; " & vbCrLf
strSql = strSql & "if oc.if_has_co_class('Film')='TRUE' AND " & vbCrLf
strSql = strSql & "oc.if_has_co_class('theater')='TRUE' AND " & vbCrLf
strSql = strSql & "oc.if_has_co_relationship('is_scheduled')='TRUE' AND " & vbCrLf
strSql = strSql & "oc.if_has_co_attributes('Film', lista('is_scheduled', 'title', 'actor'))='TRUE' AND " & vbCrLf
strSql = strSql & "oc.if_has_co_attributes('theater', lista('theatername', 'address', 'email'))='TRUE' " & vbCrLf
strSql = strSql & "then resultado:='FilmContentOntology'; " & vbCrLf
strSql = strSql & "else resultado:='No Existe'; " & vbCrLf
strSql = strSql & "end if; " & vbCrLf
strSql = strSql & "END consulta; " & vbCrLf
strSql = strSql & "END OPSPRUEBAS; " & vbCrLf
strSql = strSql & "/ " & vbCrLf
strSql = strSql & ". " & vbCrLf
strSql = strSql & "COMMIT;" & vbCrLf
TextBox2.Text = strSql
'Dim myConnectionString As String = "User Id=system;Password=daniel;Data Source=websogo;"
'Dim oraConn As Oracle.DataAccess.Client.OracleConnection = New Oracle.DataAccess.Client.OracleConnection(myConnectionString)
Dim myCmd As New System.Data.OleDb.OleDbCommand()
Dim MyConnection As New System.Data.OleDb.OleDbConnection()
MyConnection.ConnectionString = "Provider=MSDAORA;Data Source=websogo;password=daniel;User ID=system"
MyConnection.Open()
'oraConn.Open()
myCmd.Connection = MyConnection
myCmd.CommandType = CommandType.Text
myCmd.CommandText = strSql
myCmd.ExecuteNonQuery()
'Dim e As Oracle.DataAccess.Client.OracleException
'Try
' myCmd.ExecuteNonQuery()
'Catch e
' Dim error1 As Oracle.DataAccess.Client.OracleError
' error1 = e.Errors.Item(0)
' Textbox3.Text = error1.Source & " " & error1.Message
'End Try
MyConnection.Close()
End Sub
I've tried using Microsoft ODP, OLEDB and Oracle's ODP.NET
Also tried to catch any error but there are no errors!
Has anybody achived a successful dynamically stored procedure creation using .net?
thanks in advance
DanI'm trying to create Stored Procedures via .NET and able to do so but when I look in Oracle Enterprise Manager Console, the Stored Procedures are marked as INVALID... If I edit the Stored Procedure (i.e. delete a space or something minor) and SAVE then it compiles fine.....
Any ideas ????
will be using this against 9i & 10g db -
Creating Stored Procedure in Java
Hi All,
I would like to ask how to create a stored procedure in Java.
My project now is to create a program that will open a DB2 SQL File (Creating Table and Stored Procedure) and then Execute it.
Executing the CREATE TABLE command is not that difficult since I can break the execution down by statement (divide by ";" in the SQL file).
The logic I applied here are:
1. Open the SQL file and store the contents into a String object.
2. Call the executeUpdate(string_sql_fileContent) method of Statement Object.
Example: SQL File contect to be executed.
===========================================================
CREATE TABLE MDMTEST.sample
(firstname CHARACTER(40),
middlename CHARACTER(40),
lastname CHARACTER(40),
idNo SMALLINT NOT NULL
DATA CAPTURE NONE;
#SYNC 10;
ALTER TABLE MDMTEST.sample
LOCKSIZE ROW
APPEND OFF
NOT VOLATILE;
#SYNC 20;
ALTER TABLE MDMTEST.sample
ADD PRIMARY KEY
(idNo
#SYNC 30;
RUNSTATS ON TABLE MDMTEST.sample
AND INDEXES ALL
SHRLEVEL REFERENCE;
===========================================================
I can divide this by ";" and execute them by statement.
But my problem is when creating Stored Procedure... Since in stored procedure there are so many stub-statements...
Example: Content of SQL File for creating stored procedure.
===========================================================
CREATE PROCEDURE MDMTEST.DROP_ALL_OBJECTS ( )
SPECIFIC MDMTEST.SQL051109115453000
LANGUAGE SQL
NOT DETERMINISTIC
CALLED ON NULL INPUT
MODIFIES SQL DATA
INHERIT SPECIAL REGISTERS
BEGIN
Delete Statement;
Insert Statement;
Update Statement;
END;
===========================================================
Take note there are three statements inside the CREATE..BEGIN.. and END.. (namely Delete, Insert, and Update Statements).
How can I execute the command for creating the procedure in Java? I believe that creating stored procedures in other databases are almost the same...
So... anyboby who have tried creating stored procedure in Java?
Please help me in this... I wanna pass the subject hehe..I have used these files as a sample:
Java Program:
import java.io.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import my.db.components.*;
public class ProcedureUploader {
private MyDBConnection dbConn=new MyDBConnection();
private Statement statement;
public ProcedureUploader() {
try{
dbConn.connectDB ("206.206.206.206","12345","DEV","mdmtest","mdmtest");
this.statement=dbConn.getStatement ();
}catch(SQLException sqle){
sqle.printStackTrace();
public String getContents(String fileName) throws IOException{
File inputFile = new File(fileName);
FileReader in = new FileReader(inputFile);
int c; String contents="";
while ((c = in.read()) != -1) contents+=(char) c;
in.close();
return contents;
public void executeSQLCommand(String file) throws IOException{
String command="";
try{
command=getContents(file);
statement.executeUpdate(command);
System.out.println("Command Execution Successful.");
}catch(Exception ex){
System.out.println("There is a problem executing the command. Please check the SQL file and re-execute again.");
ex.printStackTrace();
public static void main(String args[]) throws IOException{
ProcedureUploader uploader=new ProcedureUploader();
uploader.executeSQLCommand("C:\\I2\\Development\\ProcedureUploader\\sample.sql");
SQL File:
CREATE PROCEDURE MDMTEST.sampleProc ( )
SPECIFIC MDMTEST.sampleProc
LANGUAGE SQL
NOT DETERMINISTIC
CALLED ON NULL INPUT
MODIFIES SQL DATA
INHERIT SPECIAL REGISTERS
delete from SAMPLE;
commit;
select * from SAMPLE;;
#SYNC 10;
===========================================================
The problem is that ... there will be an error:
===========================================================
There is a problem executing the command. Please check the SQL file and re-execute again.
com.ibm.db2.jcc.c.SqlException: DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, SQLERRMC: delete from SAMPLE;;PECIAL REGISTERS
;<psm_repeat>
at com.ibm.db2.jcc.c.fg.e(fg.java:1596)
at com.ibm.db2.jcc.c.fg.b(fg.java:1160)
at com.ibm.db2.jcc.b.gb.h(gb.java:217)
at com.ibm.db2.jcc.b.gb.b(gb.java:46)
at com.ibm.db2.jcc.b.w.b(w.java:40)
at com.ibm.db2.jcc.b.vb.f(vb.java:118)
at com.ibm.db2.jcc.c.fg.m(fg.java:1155)
at com.ibm.db2.jcc.c.fg.a(fg.java:1865)
at com.ibm.db2.jcc.c.fg.c(fg.java:517)
at com.ibm.db2.jcc.c.fg.executeUpdate(fg.java:501)
at ProcedureUploader.executeSQLCommand(ProcedureUploader.java:44)
at ProcedureUploader.main(ProcedureUploader.java:54)
===========================================================
But still the procedure will be created but until the first ";" only... OR.. creates a stored procedure having the following lines only.
===========================================================
CREATE PROCEDURE MDMTEST.sampleProc ( )
SPECIFIC MDMTEST.sampleProc
LANGUAGE SQL
NOT DETERMINISTIC
CALLED ON NULL INPUT
MODIFIES SQL DATA
INHERIT SPECIAL REGISTERS
delete from SAMPLE;
=========================================================== -
I'd like to learn how to create stored procedures in Oracle 10g. I'm proficient at this with MS SQL but I can't get to first base with Oracle.
I am not using SQL *Plus and really I don't want to use it. I'd rather use a DB access program like Aqua Data Studio. When I attempt to create a procedure I get a "Compiled with errors" message. I don't know how to see the errors because I can't do a "Show Errors" message.
Is there a way to create stored procedures using standard SQL and staying away from SQL *Plus?The two best free tools I know of are:
http://sourceforge.net/projects/tora/
and
http://www.oracle.com/technology/products/database/sql_developer/
TOra is more a database system tool, and SQL Developer is more of a development tool, but see if either of those will be to your liking ;)
~Jer -
How can I create stored procedure?
I am new in this field, I was reading in this web site on how to create stored procedure,and this is what I did :
SQL> CREATE PROCEDURE test.proc1 (n IN NUMBER)
2 AS BEGIN
3 select * from districts
4 where doe = n;
5 END;
6
Please direct me. I don't know if I am wrong or right, test is the name of the database, and proc1 is the stored procedure that I want to create, why when I hit Enter after END; I got the number 6.
How can I call this stored procedure, if it works.
Thanks in advance
nullSome reading and training might prove useful. Even if you are using Linux, this forum is no place for a question like that.
-
HOW TO CREATE STORED PROCEDURE IN DATA INTEGRATOR
Hi to every one,
Can any one help in giving me a solution for creating stored procedure in Data Integrator.
I m new to this fieldHi nath,
Firstly are you using MYSQL or Oracle as the database,if its oracle database then follow this
http://obiee101.blogspot.com/2008/01/obiee-using-oracle-stored-procedure-to.html
http://oraclebizint.wordpress.com/2008/02/20/oracle-bi-ee-101332-executing-stored-proceduresfunctions-before-reports-before-report-triggers-and-global-temporary-tables/
EXEC [DATABASE_NAME].[SCHEMA_NAME].[PROCEDURE_NAME][DATABASE_NAME] --> is the database name your creating your procedure
[SCHEMA_NAME]-->is the user with which your creating
[PROCEDURE_NAME] --> the name given to procedure
You dont know how to get those run this SQL in TOAD and see select sys_context('userenv','db_name'), sys_context('userenv','session_user') from dual
(OR) open you connection pool properties window in RPD,you will get the DB name and the user name as the schema name
hope answered your question.
CHeers,
KK -
I have created stored procedure with %rowtype as IN OUT parameter.I want to
i have created stored procedure with %rowtype as IN OUT parameter.I want to call it in java program
Hi Avi,
I have the same problem as the person asking before me, so I'll try and clarify:
I have a Java client and a PL/SQL database procedure that looks something along the lines of:
Create of Replace procedure myProc(myRow IN myTable%Rowtype)
It's very easy to pass a parameter into this procedure from another procedure within the database because creating another myTable%Rowtype is not a problem.
However, Java doesnt know what "Rowtype" is.
I was wondering how I would pass a "rowtype" from Java.
I was thinking along the lines of creating an object in the DB like that:
Create Type myObj AS myTable%Rowtype (<-- is that even allowed?)
And then create a procedure in the DB with the header:
Create of Replace procedure myProc(myRow IN myObj)
And then, in my Java,just create a STRUCT of my DB object and pass it to the DB:
myCallableStatement.setObject(1, myStruct);
Would that work?
Is there a better way?
Thanks,
Dan -
Cannot create stored procedure in Azure SQL database
When I try to create a stored procedure using Management Studio
(Snippet follows
use
PPSC_Sky_Data
go
/****** Object: StoredProcedure [dbo].[sp_RegisterProd] Script Date: 17-02-2015 17:52:50 ******/
SET
ANSI_NULLS
ON
GO
SET
QUOTED_IDENTIFIER
ON
GO
CREATE
proc [dbo].[sp_RegisterProd]
@inputMachid nvarchar(50),@inputDomainname
nvarchar(255),@inputwsid
nvarchar(255),@inputipv4
nvarchar(50),
@custno
as
nvarchar(50),@email
as
nvarchar(50),@telephone
as
nvarchar(50),@RegType
as
int
(end of snippet)
It fails with message 40508 - (not allowed to switch between databases) then tells me I am not authorized to create an SP in the Master db.
So....
How can I create a procedure in AZURE Sql?
Thanks
Murray
M WhippsHi 9gwcycn,
Creating stored procedures is not allowed in Master Database. You have to switch to Database
PPSC_Sky_Data manually, use statement is not supported. After that could you please confirm again? As Creating and altering Stored procedures work fine from my SSMS.
If you have any feedback on our support, please click
here.
Eric Zhang
TechNet Community Support -
How to create stored procedure directely in RPD
Hi Gurus,
I am trying to create stored procedure directly in physical table in rpd level in OBIEE.for this one i have gone through below website.
http://obiee101.blogspot.com/2011/01/obiee-using-mssql-stored-procedure-as.html
in that blog they mentioned to write some query which is...........
EXEC [DATABASE_NAME].[SCHEMA_NAME].[PROCEDURE_NAME]
in above query i am not getting what is DATABASE_NAME,SCHEMA_NAME,PROCEDURE_NAME
can any one elobrate this oneHi nath,
Firstly are you using MYSQL or Oracle as the database,if its oracle database then follow this
http://obiee101.blogspot.com/2008/01/obiee-using-oracle-stored-procedure-to.html
http://oraclebizint.wordpress.com/2008/02/20/oracle-bi-ee-101332-executing-stored-proceduresfunctions-before-reports-before-report-triggers-and-global-temporary-tables/
EXEC [DATABASE_NAME].[SCHEMA_NAME].[PROCEDURE_NAME][DATABASE_NAME] --> is the database name your creating your procedure
[SCHEMA_NAME]-->is the user with which your creating
[PROCEDURE_NAME] --> the name given to procedure
You dont know how to get those run this SQL in TOAD and see select sys_context('userenv','db_name'), sys_context('userenv','session_user') from dual
(OR) open you connection pool properties window in RPD,you will get the DB name and the user name as the schema name
hope answered your question.
CHeers,
KK -
Hello,
I want to create stored procedure which will give output rows from "values that are passed as one parameter (comma seperated) to store procedure".
Suppose ,
Parameter value : person 1,person2,person3
table structure :
Project Name | officers 1 | officers 2
here, officers 1 or officers 2 may contain names of multiple people.
expected OUTPUT : distinct list(rows) of projects where person 1 or person 2 or person 3 is either officer1 or officer 2.
please explain or provide solution in detail
- ThanksHi Visakh,
Thanks for reply.
But the solution you provided giving me right output only if officer 1 or officer 2 contains single value , not with comma seperated value.
Your solution is working fine for following scenario :
Project
Officers 1
Officers 2
p1
of11
off21
p2
of12
off22
with parameter : of11,off22 : it will give expected output
And its not working in case of :
Project
Officers 1
Officers 2
p1
of11,of12
off21,off23
p2
of12,of13
off22,off24
with parameter : of11,off22 : it will not give any row in output
I need patten matching not exact match :)
ok
if thats the case use this modified logic
CREATE PROC GetProjectDetails
@PersonList varchar(5000)
AS
SELECT p.*
FROM ProjectTable p
INNER JOIN dbo.ParseValues(@PersonList,',')f
ON ',' + p.[officers 1] + ',' LIKE '%,' + f.val + ',%'
OR ',' + p.[officers 2] + ',' LIKE '%,' + f.val + ',%'
GO
Keep in mind that what you've done is a wrong design approach
You should not be storing multiples values like this as comma separated list in a single column. Learn about normalization . This is in violation of 1st Normal Form
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
How to create stored procedures automatically when creating new company
I need to create a method in our add-on Business One application that will create stored procedures at the time we install the add-on (when the new company is created). Where would I store the SQL scripts, and what SAP Business One commands do I need to use to build the stored procedures into the new company database? Can someone give me an example of how to do this? We are coding in C#, but an example in visual basic would also be helpful if no one out there in forum land uses C#
Thanks,
Nancy Walk
[email protected]Hi Nancy!
Of course are there people here that use C#
To solve your problem, create a routine in your add-on that checks at startup if the stored procedures are present. If they are not, create them. You can use the DI-API, or just add them directly to your database.
<i>Note: SAP does not like it when you play around directly in the SAP databases, and does not supply support for databases that are changed manually. You'd better use the DI-API...</i>
Hope it helps...
Grtz, Rowdy -
Got error when creating stored procedure
Hi,
I am a rookie in Oracle. I created a stored procedure:
create or replace procedure my_first_sp
as
begin
select cid from actions where rownum<3;
end;
And I got an error : "**** compilation error"
After I "show error" I got the description to see a "into" is expected.
But if I change the select statement to a insert statement, no error.
Please advice.
Thanks a lot.When you have a standalone SELECT statement in PL/SQL, you have to have an INTO clause if you want the results to be stored in a local variable.
In your case, it would appear that you want your query to return multiple rows. In that case, you'd want to create a cursor, i.e.
CREATE OR REPLACE my_first_sp
AS
BEGIN
FOR cursor_name IN (SELECT cid FROM actions WHERE rownum < 3)
LOOP
<<Do something>>
END LOOP;
END;I would also tend to suspect that your SELECT statement is wrong. This statement will return an arbitrary two cid values from the actions table, which is not likely what you want.
Justin -
Error in stored procedure while using dbms_datapump for transportable
Hi,
I'm facing following issue:
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Solaris: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
====================================================================================
I'm trying to do transportable tablespace through stored procedure with help of DBMS_DATAPUMP, Following is the code :
==================================================================================
create or replace
procedure sp_tts_export(v_tbs_name varchar2) as
idx NUMBER; -- Loop index
JobHandle NUMBER; -- Data Pump job handle
PctComplete NUMBER; -- Percentage of job complete
JobState VARCHAR2(30); -- To keep track of job state
LogEntry ku$_LogEntry; -- For WIP and error messages
JobStatus ku$_JobStatus; -- The job status from get_status
Status ku$_Status; -- The status object returned by get_status
dts varchar2(140):=to_char(sysdate,'YYYYMMDDHH24MISS');
exp_dump_file varchar2(500):=v_tbs_name||'_tts_export_'||dts||'.dmp';
exp_log_file varchar2(500):=v_tbs_name||'_tts_export_'||dts||'.log';
exp_job_name varchar2(500):=v_tbs_name||'_tts_export_'||dts;
dp_dir varchar2(500):='DATA_PUMP_DIR';
log_file UTL_FILE.FILE_TYPE;
log_filename varchar2(500):=exp_job_name||'_main'||'.log';
err_log_file UTL_FILE.FILE_TYPE;
v_db_name varchar2(1000);
v_username varchar2(30);
t_dir_name VARCHAR2(4000);
t_file_name VARCHAR2(4000);
t_sep_pos NUMBER;
t_dir varchar2(30):='temp_0123456789';
v_sqlerrm varchar2(4000);
stmt varchar2(4000);
FUNCTION get_file(filename VARCHAR2, dir VARCHAR2 := 'TEMP')
RETURN VARCHAR2 IS
contents VARCHAR2(32767);
file BFILE := BFILENAME(dir, filename);
BEGIN
DBMS_LOB.FILEOPEN(file, DBMS_LOB.FILE_READONLY);
contents := UTL_RAW.CAST_TO_VARCHAR2(
DBMS_LOB.SUBSTR(file));
DBMS_LOB.CLOSE(file);
RETURN contents;
END;
begin
--execute immediate ('drop tablespace test including contents and datafiles');
--execute immediate ('create tablespace test datafile ''/home/smishr02/test.dbf'' size 10m');
--execute immediate ('create table prestg.test_table (a number) tablespace test');
--execute immediate ('insert into prestg.test_table values (1)');
--commit;
--execute immediate ('alter tablespace test read only');
--dbms_output.put_line('11111111111111111111');
dbms_output.put_line(log_filename||'>>>>>>>>>>>>>>>>>>>>>>>>>>>'|| dp_dir);
log_file:=UTL_FILE.FOPEN (dp_dir, log_filename, 'w');
UTL_FILE.PUT_LINE(log_file,'#####################################################################');
UTL_FILE.PUT_LINE(log_file,'REPORT: GENERATED ON ' || SYSDATE);
UTL_FILE.PUT_LINE(log_file,'#####################################################################');
select global_name,user into v_db_name,v_username from global_name;
UTL_FILE.PUT_LINE(log_file,'Database:'||v_db_name);
UTL_FILE.PUT_LINE(log_file,'user running the job:'||v_username);
UTL_FILE.PUT_LINE(log_file,'for tablespace:'||v_tbs_name);
UTL_FILE.NEW_LINE (log_file);
stmt:='ALTER TABLESPACE '||v_tbs_name || ' read only';
dbms_output.put_line('11111111111111111111'||stmt);
execute immediate (stmt);
UTL_FILE.PUT_LINE(log_file,' '||v_tbs_name || ' altered to read only mode.');
UTL_FILE.NEW_LINE (log_file);
UTL_FILE.PUT_LINE(log_file,'#####################################################################');
UTL_FILE.NEW_LINE (log_file);
UTL_FILE.PUT_LINE(log_file,' Initiating the Datapump engine for TTS export..............');
UTL_FILE.NEW_LINE (log_file);
dbms_output.put_line('11111111111111111111');
JobHandle :=
DBMS_DATAPUMP.OPEN(
operation => 'EXPORT'
*,job_mode => 'TRANSPORTABLE'*
*,remote_link => NULL*
*,job_name => NULL*
--,job_name => exp_job_name
-- ,version => 'LATEST'
UTL_FILE.PUT_LINE(log_file,'Done');
UTL_FILE.NEW_LINE (log_file);
UTL_FILE.PUT_LINE(log_file,' Allocating dumpfile................');
DBMS_DATAPUMP.ADD_FILE(
handle => JobHandle
,filename => exp_dump_file
,directory => dp_dir
,filetype => DBMS_DATAPUMP.KU$_FILE_TYPE_DUMP_FILE
-- ,filesize => '100M'
UTL_FILE.PUT_LINE(log_file,'Done');
UTL_FILE.NEW_LINE (log_file);
UTL_FILE.PUT_LINE(log_file,' Allocating logfile................');
DBMS_DATAPUMP.ADD_FILE(
handle => JobHandle
,filename => exp_log_file
,directory => dp_dir
,filetype => DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE
UTL_FILE.PUT_LINE(log_file,'Done');
UTL_FILE.NEW_LINE (log_file);
UTL_FILE.PUT_LINE(log_file,' Setting attributes................');
DBMS_DATAPUMP.set_parameter(handle => JobHandle,
name=>'TTS_FULL_CHECK',
value=>1);
DBMS_DATAPUMP.METADATA_FILTER(
handle => JobHandle
,NAME => 'TABLESPACE_EXPR'
,VALUE => 'IN ('''||v_tbs_name||''')'
-- ,object_type => 'TABLE'
UTL_FILE.PUT_LINE(log_file,'Done');
UTL_FILE.NEW_LINE (log_file);
UTL_FILE.PUT_LINE(log_file,' Now starting datapump job................');
DBMS_DATAPUMP.START_JOB(JobHandle);
UTL_FILE.PUT_LINE(log_file,'Done');
UTL_FILE.NEW_LINE (log_file);
UTL_FILE.PUT_LINE(log_file,' Monitoring the job................');
--------------Monitor the job
PctComplete := 0;
JobState := 'UNDEFINED';
WHILE(JobState != 'COMPLETED') and (JobState != 'STOPPED')
LOOP
DBMS_DATAPUMP.GET_STATUS(
handle => JobHandle
,mask => 15 -- DBMS_DATAPUMP.ku$_status_job_error + DBMS_DATAPUMP.ku$_status_job_status + DBMS_DATAPUMP.ku$_status_wip
,timeout => NULL
,job_state => JobState
,status => Status
JobStatus := Status.job_status;
-- Whenever the PctComplete value has changed, display it
IF JobStatus.percent_done != PctComplete THEN
DBMS_OUTPUT.PUT_LINE('*** Job percent done = ' || TO_CHAR(JobStatus.percent_done));
PctComplete := JobStatus.percent_done;
END IF;
-- Whenever a work-in progress message or error message arises, display it
IF (BITAND(Status.mask,DBMS_DATAPUMP.ku$_status_wip) != 0) THEN
LogEntry := Status.wip;
ELSE
IF (BITAND(Status.mask,DBMS_DATAPUMP.ku$_status_job_error) != 0) THEN
LogEntry := Status.error;
ELSE
LogEntry := NULL;
END IF;
END IF;
IF LogEntry IS NOT NULL THEN
idx := LogEntry.FIRST;
WHILE idx IS NOT NULL
LOOP
DBMS_OUTPUT.PUT_LINE(LogEntry(idx).LogText);
idx := LogEntry.NEXT(idx);
END LOOP;
END IF;
END LOOP;
--copy the datafiles to data dump dir
UTL_FILE.PUT_LINE(log_file,'Done');
UTL_FILE.NEW_LINE (log_file);
UTL_FILE.PUT_LINE(log_file,' Copying datafiles to dump directory................');
-- grant select on dba_directories to prestg;
declare
cnt number;
begin
select count(*) into cnt from dba_directories
where directory_name=upper(t_dir);
if cnt=1 then
execute immediate('DROP DIRECTORY '||t_dir);
end if;
end;
FOR rec in (select file_name from sys.dba_data_files where tablespace_name=v_tbs_name)
LOOP
t_sep_pos:=instr(rec.file_name,'/',-1);
t_dir_name:=substr(rec.file_name,1,t_sep_pos-1);
t_file_name:=substr(rec.file_name,t_sep_pos+1,length(rec.file_name));
dbms_output.put_line(t_dir_name|| ' ' || t_dir);
dbms_output.put_line(t_file_name);
execute immediate('CREATE DIRECTORY '||t_dir||' AS '''||t_dir_name||'''');
UTL_FILE.PUT_LINE(log_file,' Copying '||rec.file_name||'................');
utl_file.fcopy(t_dir, t_file_name, dp_dir, t_file_name);
UTL_FILE.PUT(log_file,'Done');
execute immediate('DROP DIRECTORY '||t_dir);
END LOOP;
UTL_FILE.NEW_LINE (log_file);
UTL_FILE.PUT_LINE(log_file,' Altering tablespace to read write................');
execute immediate ('ALTER TABLESPACE '||v_tbs_name || ' read write');
UTL_FILE.PUT(log_file,' Done');
err_log_file:=utl_file.fopen(dp_dir, exp_log_file, 'r');
UTL_FILE.NEW_LINE (log_file);
UTL_FILE.PUT_LINE(log_file,' content of export logfile................');
loop
begin
utl_file.get_line(err_log_file,v_sqlerrm);
if v_sqlerrm is null then
exit;
end if;
UTL_FILE.PUT_LINE(log_file,v_sqlerrm);
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXIT;
END;
end loop;
utl_file.fclose(err_log_file);
utl_file.fclose(log_file);
END;
I'm getting following error when DBMS_DATAPUMP.OPEN is called in procedure:
SQL> exec sp_tts_export('TEST');
BEGIN sp_tts_export('TEST'); END;
ERROR at line 1:
ORA-31626: job does not exist
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 79
ORA-06512: at "SYS.DBMS_DATAPUMP", line 938
ORA-06512: at "SYS.DBMS_DATAPUMP", line 4566
ORA-06512: at "PRESTG.SP_TTS_EXPORT", line 78
ORA-06512: at line 1
==============================================================================================
This procedure is part of user ABC. I'm getting the above when I'm running this under ABC schema. However I have tested the same procedure under sys schema. When I'm creating same procedure in SYS schema it is running fine. I am clueless on this. Pls help
Thanks
Shailesh
Edited by: shaileshM on Jul 28, 2010 11:15 AMPrivileges acquired via ROLE do NOT apply within named PL/SQL procedures.
Explicit GRANT is required to resolve this issue. -
Error executing Stored Procedure that returns a recordset in Visual Basic 6
Hello, i tried to use the example in the link posted as a response to my question in a previous thread, and in Visual Basic 6, when i execute the Stored procedure it gives me the following error:
This is the package created as indicated in the example FAQ you posted.
package types
as
type cursorType is ref cursor;
end;
This is the procedure created as indicated in the example FAQ you posted.
PROCEDURE SP_TITUVALO(T_BR IN VARCHAR2,
P_Cursor OUT TYPES.cursorType )
AS
BEGIN
OPEN P_Cursor FOR
SELECT * FROM TASAS WHERE BR=T_BR AND TASA > 0;
END;
This is the code used to execute the Stored Procedure in VB6:
Dim objConn As New ADODB.Connection
Dim connString
Dim cmdStoredProc As New ADODB.Command
Dim param1 As New ADODB.Parameter
Dim RS As ADODB.Recordset
Set param1 = cmdStoredProc.CreateParameter("T_BR", adVarChar, adParamInput, 255, "97")
cmdStoredProc.Parameters.Append param1
objConn.Open strconex
Set cmdStoredProc.ActiveConnection = objConn
cmdStoredProc.CommandText = "SP_TITUVALO"
cmdStoredProc.CommandType = adCmdStoredProc
Set RS = cmdStoredProc.Execute
This is the error returned:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'SP_TITUVALO'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
****************************************************************Juan,
Not sure about FAQ you are referring to, but it seems that you need to set PLSQLRSet property of ADODB.Command to TRUE. Because if you fail to do so - errors with refcursors are likely to happen.
Consider:
Set objConn = CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=OraOLEDB.Oracle;Persist Security Info=False;Data Source=test9ora;User ID=max;Password=blabla"
objConn.Open
'Dim cmdStoredProc
Set cmdStoredProc = CreateObject("ADODB.Command")
Dim param1
Set param1 = cmdStoredProc.CreateParameter("T_BR", adVarChar, adParamInput, 255, "97")
param1.Value = "X"
cmdStoredProc.Parameters.Append param1
'Dim RS
Set cmdStoredProc.ActiveConnection = objConn
'The following line was missed out
cmdStoredProc.Properties("PLSQLRSet") = True
cmdStoredProc.CommandText = "SP_TITUVALO"
cmdStoredProc.CommandType = adCmdStoredProc
Set RS = cmdStoredProc.ExecuteThis works fine, at least for me.
Cheers.
Maybe you are looking for
-
BB app world is in my applications so it is downloaded but i cant actually open it be cause it is not in my downloads help
-
Help with importing pictures in Lightroom
I have Lightroom 3 I'm trying to add my pictures from my Sony when I import the pictures Lightroom comes up with "The following files were not imported because they could not be read" I have windows 7
-
How to create hyperlink for photo album to one of my pages?
i want to link my photo album to one of my page and im having trouble doing it. does anyone have idea how to do so? thanks.
-
Unable to view latest default trace in log viewer
Hello all, We have NW 7.0 J2EE production server. We have a CI and two application servers. Our SP level is SP18. The DB is oracle and the operating system in RHEL 4. I have a problem in viewing the default trace files in log viewer using the visual
-
DAG Kerberos Authentication Issue Exchange 2010 on 2008R2 Servers
I have 2 Exchange 2010 servers in a DAG. The witness server is in site A along with one the Exchange servers. The second Exchange server is in a DR site. The DAG has been functioning fine for 1.5 yrs. Last weekend after a scheduled reboot of all 3 se