Invokin SQL*Loader from a stored procedure
I try to invoke SQL*LOADER from within a database package by using external C procedure (the procedure calls the system() C function) but the loader generates the following error in its log file :
SQL*Loader -523: error -2 writing to file (STDERR)
and no data is uploaded.
I have tried to use system() from within database procedures to execute OS commands and it works. Does anyone know what is the problem with using system() to execute "sqlldr <parameters>"? Is there some other way to call the loader from within a stored PL/SQL procedure?
Thank you very much for your help.
Aneta Valova
null
Hi
What is your task and why you are trying to invoke SQL*Loader from strorage procedure or package? Maybe the redirecting of stderr will resolve your problem but thik is it the best way to do your job.
I am not sure, that invoking other executables from Oracle instance is good idea.
Regards
null
Similar Messages
-
Extraction SQL statement from oracle stored procedure stored in file
Hi,
I am newbie to oracle stored procedure. I need to extract the list of sqls present in oracle stored procedure. Besides that I also want to parse these sql statements to get the list of tables and columns used. Is there any tool which can help me in doing thats.
thanks,
govindwhy don't check on user_dependencies table instead?
select referenced_name,referenced_type
from user_dependencies
where name='<your stored procedure name in upper case>'
and referenced_type = 'TABLE'HTH,
Prazy -
Launch the SQL*Loader From Stored Procedure???
Is it possible to aaunch the SQL*Loader from a stored procedure? Please help!
Try the documentation on external procedures
-
Hello,
I am trying to execute a SSIS package from SQL Server 2008 R2 stored procedure but getting error code 1 (as per my knowledge, error code description is as below:
0 The package executed successfully.
1 The package failed.
3 The package was canceled by the user.
4 The utility was unable to locate the requested package. The package could not be found.
5 The utility was unable to load the requested package. The package could not be loaded.
6 The utility encountered an internal error of syntactic or semantic errors in the command line.
Details:
I have a stored procedure named "Execute_SSIS_Package" (see below sp) which executes 'Import_EMS_Response' SSIS package (when I execute this package directly from SQL Server BID it works fine it means package itself is correct) and calling
it from SQL as:- EXEC Execute_SSIS_Package 'Import_EMS_Response'.
Here I receives error code 1.
Can anyone help me to resolve this issue please?
Thanks in advance!
CREATE PROCEDURE [dbo].[Execute_SSIS_Package]
@strPackage nvarchar(100)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @cmd VARCHAR(8000)
DECLARE @Result int
DECLARE @Environment VARCHAR(100)
SELECT @Environment = Waarde
FROM Sys_Settings
WHERE Optie = 'Omgeving'
--print @Environment
SET @strPackage = '"\W2250_NGSQLSERVER\BVT\' + @Environment + '\' + @strPackage + '"'
SET @cmd = 'dtexec /SQL ' + @strPackage + ' /SERVER "w2250\NGSQLSERVER" /Decrypt "BVT_SSIS" /CHECKPOINTING OFF /REPORTING E'
--print @cmd
EXECUTE @Result = master..xp_cmdshell @cmd, NO_OUTPUT
--print @Result
ENDIt has something to do with the security.
E.g. cmdshell is not enabled or the caller has not rights over the package.
There could be a syntax error, too.
I suggest you make the package runnable off a SQL Agent job then trigger the job from the stored proc with
sp_start_job <job name>
Arthur
MyBlog
Twitter -
Hi,
How do I return two values from a
stored procedure into an "Execute SQL Task" please? Each of these two values need to be populated into an SSIS variable for later processing, e.g. StartDate and EndDate.
Thinking about stored procedure output parameters for example. Is there anything special I need to bear in mind to ensure that the SSIS variables are populated with the updated stored procedure output parameter values?
Something like ?
CREATE PROCEDURE [etl].[ConvertPeriodToStartAndEndDate]
@intPeriod INT,
@strPeriod_Length NVARCHAR(1),
@dtStart NVARCHAR(8) OUTPUT,
@dtEnd NVARCHAR(8) OUTPUT
AS
then within the SSIS component; -
Kind Regards,
Kieran.
Kieran Patrick Wood http://www.innovativebusinessintelligence.com http://uk.linkedin.com/in/kieranpatrickwood http://kieranwood.wordpress.com/Below execute statement should work along the parameter mapping which you have provided. Also try specifying the parameter size property as default.
Exec [etl].[ConvertPeriodToStartAndEndDate] ?,?,? output, ? output
Add a script task to check ssis variables values using,
Msgbox(Dts.Variables("User::strExtractStartDate").Value)
Do not forget to add the property "readOnlyVariables" as strExtractStartDate variable to check for only one variable.
Regards, RSingh -
Invoke SQL Loader from PL/SQL Procedure
hi
Is there any way to invoke sqlloader from a PL/SQL Procedure ?
Thanks
Ashish'HOST' is not a PL/SQL command, it's a SQL*Plus command.
If you think about it for a moment, being able to run an O.S. command, such as SQL*Loader, from within the database is pretty dangerous. I suspect this is why Oracle has no way of doing it. Otherwise, a you'd be able to execute an O.S. command as the user 'oracle' (on UNIX - probably 'SYSTEM' on NT, which is even worse!!!).
All it takes is to change this :
execute '/usr/oracle/bin/sqlldr user/password@DB file=input.txt' ;
to this :
execute 'rm -rf /usr/oracle' ;
and you can start checking the job adverts... -
Calling OLE API from Oracle Stored Procedure
An application that I need to intergate with exposes only the OLE API. How can I invoke these OLE APIs from Oracle stored procedure? Do I need any special/ additional Oracle components? Can you please help. Any links to examples would be very helpful. Thanks.
If what you mean by Oracle stored procedures is pl/sql then yes.
You can create a "wrapper" this way:
CREATE OR REPLACE FUNCTION xmlXform
in_mapUrl IN VARCHAR2,
in_inputUrl IN VARCHAR2
RETURN VARCHAR2
AS
LANGUAGE JAVA NAME
'com.yourcompany.xml2any.xform(java.lang.String,java.lang.String)
RETURN java.lang.String';
Then load the java as:
loadjava -user youruser/youruserpasswd -resolve -verbose lib/xmlparserv2.jar classes/com/yourcompany/xform.class classes/com/yourcompany/xml2any.class
The java, given the correct permissions, can do anything java can do including communicate with outside applications.
Is this the "best" way... depends on what you are trying to accomplish. -
Get variable values from a stored procedure
I am using SQL 2008R2 and I want to replace a view inside a stored procedure with a new stored procedure to return multiple variable values. Currently I am using the code below to get values for 4 different variables. I would rather get the 4 variables
from a stored procedure (which returns all of these 4 values and more) but not sure how to do so. Below is the code for getting the 4 variable values in my current sp.
DECLARE @TotalCarb real;
DECLARE @TotalPro real;
DECLARE @TotalFat real;
DECLARE @TotalLiquid real;
SELECT @TotalCarb = ISNULL(TotCarb,0),
@TotalPro = ISNULL(TotPro,0),
@TotalFat = ISNULL(TotFat,0),
@TotalLiquid = ISNULL(TotLiq,0)
FROM dbo.vw_ActualFoodTotals
WHERE (MealID = @MealID);You can replace the view with inline table valued user-defined function:
http://www.sqlusa.com/bestpractices/training/scripts/userdefinedfunction/
See example: SQL create INLINE table-valued function like a parametrized view
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
How to get an updatable ADODB Recordset from a Stored Procedure?
In VB6 I have this code to get a disconnected ADODB Recordset from a Oracle 9i database (the Oracle Client is 10g):
Dim conSQL As ADODB.Connection
Dim comSQL As ADODB.Command
Dim recSQL As ADODB.Recordset
Set conSQL = New ADODB.Connection
With conSQL
.ConnectionString = "Provider=OraOLEDB.Oracle;Password=<pwd>;Persist Security Info=True;User ID=<uid>;Data Source=<dsn>"
.CursorLocation = adUseClientBatch
.Open
End With
Set comSQL = New ADODB.Command
With comSQL
.ActiveConnection = conSQL
.CommandType = adCmdStoredProc
.CommandText = "P_PARAM.GETALLPARAM"
.Properties("PLSQLRSet").Value = True
End With
Set recSQL = New ADODB.Recordset
With recSQL
Set .Source = comSQL
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
.Open
.ActiveConnection = Nothing
End With
The PL/SQL Procedure is returning a REF CURSOR like this:
PROCEDURE GetAllParam(op_PARAMRecCur IN OUT P_PARAM.PARAMRecCur)
IS
BEGIN
OPEN op_PARAMRecCur FOR
SELECT *
FROM PARAM
ORDER BY ANNPARAM DESC;
END GetAllParam;
When I try to update some values in the ADODB Recordset (still disconnected), I get the following error:
Err.Description: Multiple-step operation generated errors. Check each status value.
Err.Number: -2147217887 (80040E21)
Err.Source: Microsoft Cursor Engine
The following properties on the Command object doesn't change anything:
.Properties("IRowsetChange") = True
.Properties("Updatability") = 7
How can I get an updatable ADODB Recordset from a Stored Procedure?4 years later...
I was having then same problem.
Finally, I've found how to "touch" the requierd bits.
Obviously, it's hardcore, but since some stupid at microsoft cannot understand the use of a disconnected recordset in the real world, there is no other choice.
Reference: http://download.microsoft.com/downlo...MS-ADTG%5D.pdf
http://msdn.microsoft.com/en-us/library/cc221950.aspx
http://www.xtremevbtalk.com/showthread.php?t=165799
Solution (VB6):
<pre>
Dim Rst As Recordset
Rst.Open "select 1 as C1, '5CHARS' as C5, sysdate as C6, NVL(null,15) as C7, null as C8 from DUAL", yourconnection, adOpenKeyset, adLockBatchOptimistic
Set Rst.ActiveConnection = Nothing
Dim S As New ADODB.Stream
Rst.Save S, adPersistADTG
Rst.Close
Set Rst = Nothing
With S
'Debug.Print .Size
Dim Bytes() As Byte
Dim WordVal As Integer
Dim LongVal As Long
Bytes = .Read(2)
If Bytes(0) <> 1 Then Err.Raise 5, , "ADTG byte 0, se esperaba: 1 (header)"
.Position = 2 + Bytes(1)
Bytes = .Read(3)
If Bytes(0) <> 2 Then Err.Raise 5, , "ADTG byte 9, se esperaba: 2 (handler)"
LongVal = Bytes(1) + Bytes(2) * 256 ' handler size
.Position = .Position + LongVal
Bytes = .Read(3)
If Bytes(0) <> 3 Then Err.Raise 5, , "ADTG, se esperaba: 3 (result descriptor)"
LongVal = Bytes(1) + Bytes(2) * 256 ' result descriptor size
.Position = .Position + LongVal
Bytes = .Read(3)
If Bytes(0) <> 16 Then Err.Raise 5, , "ADTG, se esperaba: 16 (adtgRecordSetContext)"
LongVal = Bytes(1) + Bytes(2) * 256 ' token size
.Position = .Position + LongVal
Bytes = .Read(3)
If Bytes(0) <> 5 Then Err.Raise 5, , "ADTG, se esperaba: 5 (adtgTableDescriptor)"
LongVal = Bytes(1) + Bytes(2) * 256 ' token size
.Position = .Position + LongVal
Bytes = .Read(1)
If Bytes(0) <> 6 Then Err.Raise 5, , "ADTG, se esperaba: 6 (adtgTokenColumnDescriptor)"
Do ' For each Field
Bytes = .Read(2)
LongVal = Bytes(0) + Bytes(1) * 256 ' token size
Dim NextTokenPos As Long
NextTokenPos = .Position + LongVal
Dim PresenceMap As Long
Bytes = .Read(3)
PresenceMap = Val("&H" & Right$("0" & Hex$(Bytes(0)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(2)), 2))
Bytes = .Read(2) 'ColumnOrdinal
'WordVal = Val("&H" & Right$("0" & Hex$(Bytes(0)), 2) & Right$("0" & Hex$(bytes(1)), 2))
'Aca pueden venir: friendly_columnname, basetable_ordinal,basetab_column_ordinal,basetab_colname
If PresenceMap And &H800000 Then 'friendly_columnname
Bytes = .Read(2) 'Size
LongVal = Bytes(0) + Bytes(1) * 256 ' Size
.Position = .Position + LongVal * 2 '*2 debido a UNICODE
End If
If PresenceMap And &H400000 Then 'basetable_ordinal
.Position = .Position + 2 ' 2 bytes
End If
If PresenceMap And &H200000 Then 'basetab_column_ordinal
.Position = .Position + 2 ' 2 bytes
End If
If PresenceMap And &H100000 Then 'basetab_colname
Bytes = .Read(2) 'Size
LongVal = Bytes(0) + Bytes(1) * 256 ' Size
.Position = .Position + LongVal * 2 '*2 debido a UNICODE
End If
Bytes = .Read(2) 'adtgColumnDBType
'WordVal = Val("&H" & Right$("0" & Hex$(Bytes(0)), 2) & Right$("0" & Hex$(bytes(1)), 2))
Bytes = .Read(4) 'adtgColumnMaxLength
'LongVal = Val("&H" & Right$("0" & Hex$(Bytes(3)), 2) & Right$("0" & Hex$(Bytes(2)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(0)), 2))
Bytes = .Read(4) 'Precision
'LongVal = Val("&H" & Right$("0" & Hex$(Bytes(3)), 2) & Right$("0" & Hex$(Bytes(2)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(0)), 2))
Bytes = .Read(4) 'Scale
'LongVal = Val("&H" & Right$("0" & Hex$(Bytes(3)), 2) & Right$("0" & Hex$(Bytes(2)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(0)), 2))
Dim ColumnFlags() As Byte, NewFlag0 As Byte
ColumnFlags = .Read(1) 'DBCOLUMNFLAGS, First Byte only (DBCOLUMNFLAGS=4 bytes total)
NewFlag0 = ColumnFlags(0)
If (NewFlag0 And &H4) = 0 Then 'DBCOLUMNFLAGS_WRITE (bit 2) esta OFF
'Lo pongo en ON, ya que quiero escribir esta columna LOCALMENTE en el rst DESCONECTADO
NewFlag0 = (NewFlag0 Or &H4)
End If
If (NewFlag0 And &H8) <> 0 Then 'DBCOLUMNFLAGS_WRITEUNKNOWN (bit 3) esta ON
'Lo pongo en OFF, ya que no me importa si NO sabes si se puede updatear no, yo lo se, no te preocupes
'ya que quiero escribir esta columna LOCALMENTE en el rst DESCONECTADO
NewFlag0 = (NewFlag0 And Not &H8)
End If
If (NewFlag0 And &H20) <> 0 Then 'DBCOLUMNFLAGS_ISNULLABLE (bit 5) esta OFF
'Lo pongo en ON, ya que siendo un RST DESCONECTADO, si le quiero poner NULL, le pongo y listo
NewFlag0 = (NewFlag0 Or &H20)
End If
If NewFlag0 <> ColumnFlags(0) Then
ColumnFlags(0) = NewFlag0
.Position = .Position - 1
.Write ColumnFlags
End If
.Position = NextTokenPos
Bytes = .Read(1)
Loop While Bytes(0) = 6
'Reconstruyo el Rst desde el stream
S.Position = 0
Set Rst = New Recordset
Rst.Open S
End With
'TEST IT
On Error Resume Next
Rst!C1 = 15
Rst!C5 = "MUCHOS CHARS"
Rst!C7 = 23423
If Err.Number = 0 Then
MsgBox "OK"
Else
MsgBox Err.Description
End If
</pre> -
Resultset from a Stored Procedure
Hello Everyone,
Is it possible to return a resultset from a stored procedure? I need to do display set of rows which are resulted by joining few tables.
Is it possible?
Please help..
TIA
Regards,
Rao Santapur.
null<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Raymond Tang ([email protected]):
You can use 'REF CURSOR'<HR></BLOCKQUOTE>
I have created a stored procedure with a ref cursor- what parameters do i need to pass via Sql*Plus to get results?
[email protected]
null -
Retruring Multiple rows from a Stored Procedure
The Oracle JDBC documentation shows how to return a cursor pointer through the parameter list of a stored procedure allowing a Java program to use the cursor like a normal result set. I've tried it (using the thin driver) and it works fine - however, I'm having trouble getting this to work running the program under a Weblogic server (using their own JDBC implementation). So, I have two questions:
1) Has anyone had this problem before and solved it ??
2) Are there any other techniques for getting multiple rows back from the database without having to fire "raw" sql at it ?Hi
You could return not resultset but array, for example:
PACKAGE TEST:
type string_table is table of varchar2(80)
index by binary_integer;
function get_something (
something1 out string_table,
arraylength in number
) return number;
PACKAGE'S BODY:
function get_something (
something1 out string_table,
arraylength in number /** length of the array **/
) return number as
cursor C is
select something1, ...
from test_table;
pos number := 1;
begin
for position in C loop
exit when (pos > arraylength);
something1(pos) := position.something1;
pos := pos + 1;
end loop;
return (pos - 1);
end;
Of course in this example you need to know length of your array
(arraylength parameter), but you can avoid such problem, for
example, by using DBMS_SQL package (or dynamic SQL feature in
the Oracle8i).
Andrew
Mladen Gogala (guest) wrote:
: Phil Hildebrand (guest) wrote:
: : Is there a way that I can return multiple rows from a stored
: : procedure for function ?
: : Something like:
: : CREATE FUNCTION sp_get_children (my_nip IN port.nip_num%
TYPE)
: : RETURN my_nip
: : IS
: : CURSOR child_cur IS
: : SELECT nip_num
: : FROM logical_port
: : WHERE port_num = my_nip;
: : child_rec child_cur%rowtype;
: : BEGIN
: : FOR child_rec IN child_cur
: : LOOP
: : RETURN my_nip;
: : END LOOP;
: : END tmp_sp_get_children;
: : I know how to do it in Informix ( RETURN WITH RESUME ), but
: I'm
: : not running Informix ;)
: : Thanks,
: : Phil
: In contrast with Informix, SQL Server and Sybase, Oracle
: can not return a result set. the only workaround is to
: return the cursor variable as such.
null -
Calling stored procedure from a stored procedure
I have a stored procedure that accepts a customer prefix like "abc" and returns a customer document number like "abc-0021". (Thanks V Garcia)
This sp works when I call it from SQL Plus Worksheet.
But I need to call it from another stored procedure and store it in a local variable so that I can insert it into a table with the rest of the information.
This is what I have tried so far:
CREATE OR REPLACE PROCEDURE "SCHEMANAME"."SP_XXTESTXX" ( seq_name in
varchar2)
AS
id_out varchar(10);
BEGIN
execute SP_GET_NEXT_DOC_NUMBER(seq_name,:id_out);
print id_out;
END;but this will not compile. I get this error:
Line # = 8 Column # = 12 Error Text = PLS-00103: Encountered the symbol "SP_GET_NEXT_DOC_NUMBER" when expecting one of the following: := . ( @ % ; immediate The symbol ":=" was substituted for "SP_GET_NEXT_DOC_NUMBER" to continue.
Line # = 8 Column # = 41 Error Text = PLS-00049: bad bind variable 'ID_OUT'
Line # = 10 Column # = 10 Error Text = PLS-00103: Encountered the symbol "ID_OUT" when expecting one of the following: := . ( @ % ; The symbol ":=" was substituted for "ID_OUT" to continue.I think I got it.
CREATE OR REPLACE PROCEDURE "SCHEMANAME"."SP_XXTESTXX" ( seq_name in
varchar2)
AS
id_out varchar(10);
BEGIN
SP_GET_NEXT_DOC_NUMBER(seq_name,id_out);
dbms_output.put_line(id_out);
END;This works like I wanted it to do. -
Call a Vbscript from a stored procedure
Hi,
I wonder is it possible to call a Vbscript from a stored procedure, any good reference for this.
thanksWell here is quick and dirty example I just created.
Step 1. Create a test_batch.bat file that creates a folder "c:\test_dir" and copy "c:emp.lst" into it.
C:\oracle102\examples\test_batch.bat
md c:\test_dir
copy c:\emp.lst c:\test_dir
Step2. From SQLPLUS, spool scott.emp into c:\emp.lst and call the batch from the dbms_scheduler that kicks off right away,
set echo off
set feedback off
spool c:\emp.lst;
select * from scott.emp;
spool off;
begin
dbms_scheduler.create_job(job_name => 'run_batch',
job_type => 'EXECUTABLE',
job_action => 'C:\oracle102\examples\test_batch.bat',
start_date => sysdate,
enabled => true,
comments => 'Run VB Script');
end;
Check if the directory is created and if the file is copied over. Task is to kick off the executable and test is the VBscript within the batch. Challenge is how long the script runs before the next statement in the PL/SQL runs. May be you have to introduce sleep in between.
Note: You must have at least "CREATE JOB" privilege.
Happy coding!
Prakash
Message was edited by:
Prakash Rai -
Executing Unix scripts from a stored procedure
From the sql*plus windows, I am able to execute the host command and '!sh' commands; but I need to ececute Unix scripts from a stored procedure. Hoe can I do this? Where can I get good documentation on this? Any help would be greatly appreciated!
Thanks..Hi,
U can use external procedure ( newly added feature in 8.0.3 onwards) and call any shared library. From shared library u can execute it.
One sql command is there HOST(' '). U can run a OS command. But u can not use it in PL/SQL.
U can call pls sql from shell !!!!!..
Thanks...
Boby Jose -
Get a return value from a stored procedure.
hi all ,
i need to know where i am going wrong with the below code. I am trying to get a value from a stored procedure. the return type is int. The stored procedure works fine as i've debugged it. The variable have been declared correctly.
int n = 0;
proc = conn.prepareCall("{ ? = call SP_GETITEMCURRENTSOH(?,?) }");
proc.registerOutParameter(1, java.sql.Types.INTEGER);
proc.setString(1, locationCode);
proc.setString(2, itemCode);
proc.execute();
n = proc.getInt(1);thanksHi ayub_a,
According the [ *setString*|http://java.sun.com/javase/6/docs/api/java/sql/CallableStatement.html#setString(java.lang.String,%20java.lang.String)] method of the [*CallableStatement*|http://java.sun.com/javase/6/docs/api/java/sql/CallableStatement.html] interface, the first parameter must be a parameter name and not an ordinal position index !!!
Edit : I've just found out the solution, it must be :
int n = 0;
proc = conn.prepareCall("{ ? = call SP_GETITEMCURRENTSOH(?,?) }");
proc.registerOutParameter(1, java.sql.Types.INTEGER);
proc.setString(2, locationCode);
proc.setString(3, itemCode);
proc.execute();
n = proc.getInt(1);Edited by: Chicon on Jul 5, 2009 7:48 PM
Maybe you are looking for
-
Won't show up on itunes or on ipod updater("ipod service error")
Every time i plug my ipod (4g w/ click wheel) it says on itunes software not installed correctly, it shows up as a drive but i can't see it on itunes, i have tried to reinstall itunes more than 5 times and nothing works. Also, when I try to restore m
-
I'm getting an error message when trying to open itunes on my desk top
I'm getting a Run time error when trying to open itunes on my desktop
-
Problem viewing graph in Crystal reports using VB6
I have a report created in Crystal RDC Version 9 and it has a pie chart. The chart comes out fine in Crystal but when I view it using Report-viewer OCX embedded in a VB6 application there are blank spaces where the graph ought to be. Database used is
-
Does anyone know of a way, how you can make it so that when you click on one of the tabs that it links to a different page? I have a bunch of tabs with content, but some other content would require drilling down deeper into a form which has different
-
EM dbconsole silent configuration
Somebody knows the sentence to execute emca in silent mode ? is for include it in a shell script. Regards.