Get the EXIT and the RETURN of a stored procedure parameters
I have a stored procedure (SQL Server 2008 R2 MS) as in the following example.
Thanks to the connectivity of database I get OUTPUT parameters, but I can't get the game DATA RECORDS and RETURN value.
Someone knows how to do this?
CREATE PROCEDURE [dbo]. [TS_Teste] (@T057_S_NOMEMAQUINA VARCHAR (20), @STATUS INT OUTPUT, OUTPUT OF NVARCHAR (500) OF @ERRO)
AS
BEGIN
DECLARE THE TABLE @TABLE (CODE INT, DESCRIPTION VARCHAR (30))
INSERT VALUES INTO @TABLE (51, 'A')
INSERT VALUES INTO @TABLE (52, 'B')
INSERT VALUES INTO @TABLE (53, 'C')
SELECT * FROM @TABLE
SET @STATUS = 1
SET @ERRO = "Nenhum erro!
RETURN 0
END
I finally found what was wrong... He had a line in the stored procedure only aditional. It should be like this:
CREATE PROCEDURE [dbo]. [TS_Teste] (@T057_S_NOMEMAQUINA VARCHAR (20), @STATUS INT OUTPUT, OUTPUT OF NVARCHAR (500) OF @ERRO)
AS
BEGIN
SET NOCOUNT ON; -NEW LINE!
DECLARE THE TABLE @TABLE (CODE INT, DESCRIPTION VARCHAR (30))
INSERT VALUES INTO @TABLE (51, 'A')
INSERT VALUES INTO @TABLE (52, 'B')
INSERT VALUES INTO @TABLE (53, 'C')
SELECT * FROM @TABLE
SET @STATUS = 1
SET @ERRO = "Nenhum erro!
RETURN 0
END
Tags: NI Software
Similar Questions
-
How to use the nocopy with java stored procedures parameters
-------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production PL/SQL Release 11.2.0.3.0 - Production CORE 11.2.0.3.0 Production TNS for Linux: Version 11.2.0.3.0 - Production NLSRTL Version 11.2.0.3.0 - Production
I'm a PL/SQL programmer, but not a Java programmer. I have the following java function that does what it's supposed to add a pdf at the end of another pdf document:
import oracle.sql.BLOB; import org.apache.pdfbox.util.PDFMergerUtility; import oracle.jdbc.OracleConnection; import oracle.jdbc.driver.OracleDriver; import java.io.OutputStream; public class PDFUtilities { public static BLOB appendPDF(BLOB pdfdoc1, BLOB pdfdoc2) throws Exception { //create a connection object to the current instance OracleConnection conn = (OracleConnection)new OracleDriver().defaultConnection(); //create the output blob using the connection BLOB outPDF = BLOB.createTemporary(conn, true ,BLOB.DURATION_SESSION); //create an output stream to the output blob OutputStream os = outPDF.setBinaryStream(0); //instantiate the pdf merger utility PDFMergerUtility mergerUtility = new PDFMergerUtility(); //connect the merger to the output stream mergerUtility.setDestinationStream(os); //stream from each input blob into the merger utility mergerUtility.addSource(pdfdoc1.getBinaryStream()); mergerUtility.addSource(pdfdoc2.getBinaryStream()); //merge the 2 input pdfs mergerUtility.mergeDocuments(); //do not close the output stream //return the blob return outPDF; } }
CREATE OR REPLACE package PDFTOOLS.pkg_pdf_utilities as function f_get_merged_pdf ( pi_pdf1 blob , pi_pdf2 blob ) return blob; end pkg_pdf_utilities; / CREATE OR REPLACE package body PDFTOOLS.pkg_pdf_utilities as function f_get_merged_pdf ( pi_pdf1 blob , pi_pdf2 blob ) return blob as language java name 'com.mycode.pdftools.PDFUtilities.appendPDF(oracle.sql.BLOB, oracle.sql.BLOB) return oracle.sql.BLOB'; end PDFTOOLS.pkg_pdf_utilities; /
It's very basic, but doesn't seem to work. However, I want to my function from PL/SQL to a procedure that looks like this:
CREATE OR REPLACE package PDFTOOLS.pkg_pdf_utilities as procedure sp_append_pdf ( pio_pdf2append2 IN OUT NOCOPY blob , pio_pdf2append IN OUT NOCOPY blob ) end pkg_pdf_utilities; /
What is important, what I'm trying to do is to NOCOPY the BLOBs. Otherwise, I have to read my PDF files into 2 BLOBs and create a 3rd blob as output. I prefer to be able to keep the pio_pdf2append2 as the final output. What I actually do call thing in a loop to gradually add a PDF file to a big. I'm not linking this in one operation because of concerns over the use of the system and because the pdfbox library java has would have been question after 850 in PDF format, which is not completely unrealistic in my approach.
How could I achieve this?
Post edited by: Pollocks01 only formatted code blocks because atlassian {code} tags didn't work.
Passage of an argument as input/OUTPUT requires the mapping to a Java array.
Simplified example that adds one FOR the other:
create or replace and compile java source named blob_appender_src as import oracle.sql.BLOB; import java.sql.SQLException; import java.io.OutputStream; import java.io.InputStream; import java.io.IOException; public class BLOBAppender { public static void run (BLOB[] p1, BLOB p2) throws SQLException, IOException { InputStream is = p2.getBinaryStream(); OutputStream os = p1[0].setBinaryStream(p1[0].length()+1); byte[] buffer = new byte[1024]; int len; while ((len = is.read(buffer)) != -1) { os.write(buffer, 0, len); } os.close(); is.close(); } }
create or replace procedure blob_append ( p_lob1 in out nocopy blob , p_lob2 in blob ) as language java name 'BLOBAppender.run(oracle.sql.BLOB[], oracle.sql.BLOB)' ; /
SQL> declare 2 p_lob1 blob := utl_raw.cast_to_raw('ABC'); 3 p_lob2 blob := utl_raw.cast_to_raw('DEF'); 4 begin 5 blob_append(p_lob1, p_lob2); 6 dbms_output.put_line(utl_raw.cast_to_varchar2(p_lob1)); 7 end; 8 / ABCDEF PL/SQL procedure successfully completed.
-
get the return value of a method of the application module in the workflow
Hello
I use jdeveloper 11.1.1.7.0
I defined a method (return type is useful java card) in the Module of the Application and add this method to the client interface.
also I have a workflow and in this TF firstly I should execute this method and put the return value for the pageFlowScope parameter. I know that to use this method as a methodCall and set it as an activity by default, but I don't know how to get the return value before entering the jsff page and set the pageFlowScope parameter.
Habib
Concerning
When you add the activity to the way to deal, there are 'Return value' property that you can set to #{pageFlowScope.yourVariable}
Dario
-
How to get the return value from Java runtime.getRuntime.exec?
I am running shell from a (GR 11, 2) Oracle database commands on aix.
But, I would get a return value of a shell comand... as you get with "echo $?"
I use a code like
but I do not get a return value... because I don't know how to get the return value...CREATE OR REPLACE JAVA SOURCE NAMED common."Host" AS import java.io.*; public class Host { public static int executeCommand(String command) { int retval=0; try { String[] finalCommand; finalCommand = new String[3]; finalCommand[0] = "/bin/sh"; finalCommand[1] = "-c"; finalCommand[2] = command; final Process pr = Runtime.getRuntime().exec(finalCommand); pr.waitFor(); } catch (Exception ex) { System.out.println(ex.getLocalizedMessage()); retval=-1; } return retval; }; /
Published by: user9158455 on 22-Sep-2010 07:33Hello
Your pr.exitValue () has tried?
I think you also need a finally block that destroys the sub-process
Concerning
Peter -
How to get the return in this example
Hi all,
In this simple example, is there an exception caused by the business logic. However, I would like to get the return value of 'p_dt' which will be stored in a table of newspaper, but when the exception occurs that the value is eliminated. How can I solve this? Thank you for your help.
SQL> select * from v$version where rownum = 1; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
Kind regardscreate table test as(select 1 id, to_date('01/01/2009','dd/mm/yyyy') dt from dual) / Create OR Replace Package Pkg_Test Is Procedure Prc_Call_Test; End Pkg_Test; / CREATE OR REPLACE Package Body Pkg_Test Is Procedure Prc_Test( p_id In Pls_Integer , p_dt OUT Date ) Is Begin SELECT DT INTO p_dt FROM TEST WHERE ID = p_id; If p_dt < Sysdate Then Raise_Application_Error(-20000, 'Anything'); End if; End Prc_Test; Procedure Prc_Call_Test Is v_dt Date; Begin Prc_Test(1, v_dt); Dbms_Output.put_line(v_dt); -- the return is null End Prc_Call_Test; End Pkg_Test; /
If you use NOCOPY in the parameter, then the value will be applied directly to the variable of output as it get set to so it will not be lost when the exception occurs. So, of course, to capture the exception or anything to access your dbms_output statement, but it is trivial...
SQL> ed Wrote file afiedt.buf 1 CREATE OR REPLACE Package Body Pkg_Test Is 2 Procedure Prc_Test( p_id In Pls_Integer 3 , p_dt OUT NOCOPY Date ) Is -- Note the use of NOCOPY on the parameter 4 Begin 5 SELECT DT 6 INTO p_dt 7 FROM TEST 8 WHERE ID = p_id; 9 If p_dt < Sysdate Then 10 Raise_Application_Error(-20000, 'Anything'); 11 End if; 12 End Prc_Test; 13 Procedure Prc_Call_Test 14 Is 15 v_dt Date; 16 Begin 17 BEGIN 18 Prc_Test(1, v_dt); 19 EXCEPTION 20 WHEN OTHERS THEN -- Capture the correct error here rather than OTHERS 21 dbms_output.put_line('Error occurred in prc_test'); 22 END; 23 Dbms_Output.put_line(v_dt); -- the return is null 24 End Prc_Call_Test; 25* End Pkg_Test; SQL> / Package body created. SQL> exec pkg_test.prc_call_test; Error occurred in prc_test 01/01/2009 00:00:00 PL/SQL procedure successfully completed. SQL>
-
How to do a select on the results of a stored procedure?
Hello
I am new to Oracle. I work with SQL Developer.
I'm doing a simple select on the results of a stored procedure call. I don't know how to do it. Here's what I have so far:
declare
type ref_cursor is ref cursor;
results ref_cursor;
Start
MyStoredProcedure (123 results);
Select * from results;
end;
/but he said to me:
Error from the 1 in the command line:
declare
type ref_cursor is ref cursor;
results ref_cursor;
Start
GET_TAX_TYPE_BY_TAX_ENTITY_KEY (60670100000000, results);
Select * from results;
end;
Error report:
ORA-06550: line 6, column 15:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 6, column 1:
PL/SQL: SQL statement ignored
06550 00000 - "line %s, column % s:\n%s".
* Cause: Usually a PL/SQL compilation error.
* Action:Obviously, select * results; is not the right way to do it. But what is?
Thanks for any advice forthcoming.
If a SQL cursor is built by a reporting system, a Java application, a c# program, or a PL/SQL call - the database doesn't care, because he doesn't know the difference. A Select SQL cursor created in PL/SQL through the ref cursor interface, won't be faster than the same SQL select in Eclipse. If the SQL source code is the same, the same cursor SQL program will be used by both.
What give you BIRT is the flexibility of the use of code Server (PL/SQL) to create the slider - this code doing business and technical decisions on how to design side than SQL, Select. Which is a good thing because it summarized the data model and the complexity BIRT server technique.
So my choice would be to use the procedural interface and return to the reporting system for the rendering of the ref Cursor.
The question of a slider running via the slider (selection of a cursor), is questionable. Yes, there are a set of specifications that allows to do this kind of thing. But it must be very firmly justified and careful design because it really is an exception. I personally (blame my DBA) would need a justification because it is much more of an exception. I have never seen it put in place in production in more than a decade of DBA'ing, despite the developers try to use such a hack - as it has always been much more powerful and the deployment of alternatives.
The concept for robust and efficient code for Oracle is: Maximise SQL. Minimize the PL/SQL (or Java / c# / etc.).
That means when it comes to database power, write an SQL program to do. Stop thinking of SQL as a language of data recovery a single simplistic statement. Think of it as a programming language. Extremely complex problems can be resolved with a single SQL, which requires easy code 100 + lines of PL/SQL, Java, or c#. Write SQL programs. Not SQL one-liners for a grinding program PL/SQL or Java data.
Why then PL/SQL? It is the best language to manage the creation of SQL, dealing with the process flow, conditional processing, and so on of exception handling. It is less than SQL (such as Java and c#) in the treatment of the data.
-
Passing the params in mysql stored procedure
Makes no mistake, but when I hard code the values in the stored procedure, I get results, I leave as params - if not.
Something must be a miss with how I said, but I can't understand that:
Can anyone help? details below:
: the stored procedure:
Create procedure keyword_getBySource (in sourceRecordName varchar (20), in sourceRecordId varchar (50))
Start
Select
tblkeyword.*
Of
tblkeyword,
tblrecordlink
where
tblrecordlink.sourceRecordName = @sourceRecordName
and
tblrecordlink.sourceRecordId = @sourceRecordId
and
tblrecordlink.linkRecordName = 'keyword'
and
tblkeyword.keywordId = tblrecordlink.linkRecordId
;
end
: cfm:
"< cfstoredproc procedure ="keyword_getBySource"datasource =" "username =" "password =" ">
< cfprocparam type = 'in' cfsqltype = "CF_SQL_VARCHAR" dbvarname = "sourceRecordName" value = "Log" / >
< cfprocparam type = 'in' cfsqltype = "CF_SQL_VARCHAR" dbvarname = "sourceRecordId" value = "0d8a6d3e-cf1e - 19(d) 5-2b9fc8ee1de01ad0" / >
< name cfprocresult = resultset "getBySource" = "1" / >
< / cfstoredproc >@... seems mysql does not use these to designate the params in a stored procedure
Take them out - it works.
-
Process the Message on a stored procedure
Hi all
How do I call and diplay APEX the message of a stored procedure?
Example of form on stored procedre.
Thank youHello
What do you mean by 'the message '? If you are referring to the 'success Message', then you can use the variable apex.
APEX_APPLICATION.G_PRINT_SUCCESS_MESSAGE := 'This is success message for page process';
Kind regards
Hari -
How to get the return parameter in sequence teststand ran by labview labview
Hello
Executes a test sequence of labview (essentially running "
\Examples\TestStand API\Executing sequences using API\LabVIEW\Execute with no Model.vi process") I need to get a parameter returned in 'Settings', after the sequence has run. My problem is that I get the value upon registration of the sequence and not the value after execution.
How?
Vagn
Vagn,
in order to obtain the values of the execution, you need access to execution. The following screenshot shows how to access.
Please note that this VI is lying will be called by TestStand. DO NOT USE THIS VI IN A CUSTOM USER INTERFACE!
Thank you
Norbert
EDIT: This dummy code shows how to read the string parameter 'Return '. Each parameter must be read separately with appropriate playback function.
-
How to get the return value of the activity of the method in the stubborn workflow
Hi all
I use Jdeveloper 11 g R2 (11.1.2.3) & Weblogic 10.3.5.0
I have a stubborn workflow, default activity is a call method than calling a method in the app module
This method returns an id
I need this code in my project to do something else
Is there a way I can access the return value of the method call activity?
Concerning
MohsenSet the value of return as #{{pageFlowScope.myBean.returnValue} pageFlowScope.myBean.returnValue} in the method, call the property inspector and get the value in your managed bean.
String returnParam = (String) JSFUtil.getFromPageFlow ("returnValue");
-
Hi all
I'm calling javascript from COM (c#) and it works fine. Passing parameters to javascript and playback by using the syntax of the [x] arguments also works very well.
What I can't seem to get to work is to know how to move something from javascript to the calling COM Summoner, in this case, c#. How and where should I place the return value in javascript?
Thanks in advance.
Rachiud
doScript() evaluates an expression, so just make sure that your Javascript is an expression.
For instance "(3 + 3)" 6 "
-
How to get the return value in sqlplus to index?
Hello
I am a PL/SQL Developer, and I have a problem with an existing batch.
Here's the situation:
I have a lot of unix, calling a first script sql with sqlplus (call script0.sql )
script0. SQL call other scripts sql with the command @ (script1.sql, script2.sql,... = > scriptx.sql )
My version of sqlplus is 9.2.
ScriptX.SQL modifies the data in table with insert or update and not commit or rollback anything (it is in charge of script0.sql ).
If there is an error produced in a clue all changes must be rollbacked.
Unfortunately when something fails, it returns only to script0.sql without any information on his breaks down, so continuous script0.sql and when he arrivals all changes are committed because the State of script0.sql is successful when the exit is made.
Is there an equivalent of the $? UNIX in sqlplus to obtain the return of a status @scriptx.sql?
-----
Here is the general syntax of the script0.sql :
WHENEVER SQLERROR EXIT 99;
WHENEVER OSERROR EXIT 98;
@script1.sql
@script2.sql
"exit";
-----
Here's a simple scriptx.sql file:
Insert into table values (x) (y);
-----
Published by: user10713865 on October 30, 2009 06:51Hello
You can use 'Whenever SQLERROR WHAT' options to build the logic.
Use: 'every time THAT SQLERROR EXIT DISMANTLING', if you want to there are a whole script error
OR "WHEN SQLERROR CONTINUE ROLLBACK", if you want to restore and continue to the next.
You might explore other options 'whenever SQLERROR WHAT' to suit your logic and add "COMMIT / ROLLBACK" to not relevant.See sample tests below:
SQL> create table t1 (col1 number primary key); Table created.
* 1. In script1 case fails, then restore and exit *.
kallo:f632736> cat 1.sql WHENEVER SQLERROR EXIT ROLLBACK insert into t1 values(1); insert into t1 values(1); kallo:f632736> cat 2.sql insert into t1 values(2); kallo:f632736> cat main.sql @1 @2 SQL> @main 1 row created. insert into t1 values(1) * ERROR at line 1: ORA-00001: unique constraint (ADMLHMGM.SYS_C0013874) violated Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> select * from t1; no rows selected
* 2. When script1 fails, then restore and continue to script2 *.
kallo:f632736> cat 1.sql WHENEVER SQLERROR CONTINUE ROLLBACK insert into t1 values(1); insert into t1 values(1); SQL> @main 1 row created. insert into t1 values(1) * ERROR at line 1: ORA-00001: unique constraint (ADMLHMGM.SYS_C0013874) violated Rollback complete. 1 row created. SQL> select * from t1; COL1 ---------- 2
-
How to get the return value of the method by calling the stored procedure in ApplModuleImpl
Hello
I use Jdev 10.1.3.4
JSF, and ADF business components
I created a service method in the implementing class of module request to execute the strored procedure in the database.
This breeding returns a string value.
now, I slipped the method of service of data control palette on my JSF page and chose ADF parameter form when I droped.
It works very well.
now, I want to display the string returned by the method of service after the execution on the JSF page as global messages.
How can I achieve this.
Help, please
Thanks in advance
Kind regards
Ajit AgarwalHello
You must run programmatically run the method binding. If I'm not wrong then the following code will allow you to access the return value
OperationBinding oper = bindings.get("MyPLSQLAccessMethodBinding") (OperationBinding);
String returnValue = oper.execute ((String));Once you have the string in a managed bean you can add it to the stack of messages JSF exposed by the FacesContext
Frank
-
Problem: getting the return code 7 downloading image
Hello everyone. I get the response from the server in the return Code: 7 when downloading images to my server. Can someone help me? What does this return code?
Thanks in advance.
I have it. Its because my memory server was full. Thank you.
-
Get the return parameters of the called method of VO to bean
Hello
I have a method in my bean that calls another method of my VO. This method should return a few settings, but I Don t know how to get these of the VO in the bean.
Method to call from VO:
public static Object invokeEL (String el) {}
Return invokeEL (el, new class [0], new Object [0]);
}
public static Object invokeEL (el String, class [] paramTypes, Object [] params) {}
FacesContext facesContext = FacesContext.getCurrentInstance ();
ELContext elContext = facesContext.getELContext ();
ExpressionFactory expressionFactory = facesContext.getApplication () .getExpressionFactory ();
MethodExpression exp = expressionFactory.createMethodExpression (elContext, el, Object.class, paramTypes);
Return exp.invoke (elContext, params);
}
My method in the bean:
{} public void startExport (ActionEvent actionEvent)
invokeEL("#{bindings.exportTEST.execute}");
}
My method in the original Version:
{} public void exportTEST (ActionEvent actionEvent)
Result of an integer = *;
}
So I want to get the value of the "entire result (VO)" in my bean to use it.
I m using JDeveloper 12 c.
I hope someone can help me with this problem
Thank you
DestinatioN
Hello
As Timo said, your method return type is void. Please fix this like this:
Method in the bean:
{} public void startExport (ActionEvent actionEvent)
String voString = (String) invokeEL("#{bindings.exportTEST.execute}");
use voString
}
Method in the original Version:
public String exportTEST (ActionEvent actionEvent) {}
Result of an integer = *;
return the result;
}
:
-Asha
Maybe you are looking for
-
Built-in webcam on Satellite P200 recently stopped working
My built-in webcam on my P200 recently stopped working. To resolve this problem, I thought I would updat the pilots of the site however do, installing these drivers fail to say that I need to contact the hardware vendor, which means that I can't use
-
Cannot turn Off / frozen screen - updated edition: solved
-
Factory setting removes viruses and malware on windows vista
What can I do? If I suspect that virus or malware on my computer.
-
How can I connect my bluetooth speakers
I have a laptop dell inspiron with windows vista. My laptop is not able to detect my bluetooth speakers, even if my smartphone is able to identify them. What could be the problem?
-
Microsoft office outlook error: "cannot open the outlook window.
Outlook office 7 will not open this am. It worked yesterday. The message is simply that it "cannot open the outlook window.