How to pass an array as a parameter to a stored procedure
Hi allI want to pass the name of a table as a parameter in a stored procedure, which will be used for cursors, etc..
But when I pass the parameter and I compile the S.P. he gives me error (error: table exist not...)
Any help?
Thanks in advance, Marco
Cannot open a cursor explicit when it comes to the dynamic table names or parameters. This is because the explicit and implicit cursors seek real table names since they are static.
Here your name of the table is dynamic, so u need to use dynamic that is ref cursor to and not static cursor.
I made the correction in the code below. Run it and check the result!
CREATE OR REPLACE PROCEDURE "P_1" ( TAB1 VARCHAR2)
AS
field1 CHAR(5);
field2 CHAR(5);
c1 sys_refcursor;
begin
l_str := 'select a,b,c from '||tab1||' INNER JOIN tab2 ON a = .......';
open c1 from l_str;
/*OPEN C1;
CURSOR C1
IS
SELECT a, b , c
FROM TAB1
INNER JOIN
tab2
ON a = .......
OPEN C1;*/
LOOP
FETCH C1
INTO .....
EXIT WHEN C1%NOTFOUND;
.....
END;
END LOOP;
CLOSE C1;
EXCEPTION
WHEN OTHERS
.....
END;
Tags: Database
Similar Questions
-
Pass an array of bytes to the oracle stored procedure
I have a problem with moving from byte array in Oracle stored procedure as an input parameter by using odp.net.
Here is the signature of the stored procedure:
SOMEPROCEDURE(session IN NUMBER, data IN RAW)
Here is c# code, which calls the procedure:
var cmd = new OracleCommand("SOME_PROCEDURE", _connection);
cmd.CommandType = CommandType.StoredProcedure;
var bt = new byte[]{1,68,0,83,128,1};
OracleParameter sessionId = new OracleParameter("dbSessionId", OracleDbType.Decimal, new OracleDecimal(_dbSessionId), ParameterDirection.Input);
OracleParameter data = new OracleParameter("statusData", OracleDbType.Raw, new OracleBinary(bt), ParameterDirection.Input);
cmd.Parameters.Add(sessionId);
cmd.Parameters.Add(data);
cmd.ExecuteNonQuery();
This code does not (stored procedure throws exception, which cannot receive), because in byte array hadou number 128!, if I display 128 on another number, minus 128, it works great!
What should I do?
After some tests I found the solution. Initially, you cannot switch to the array of bytes via the odp.net stored procedure, if the table contains 127 large values.
Yes, solution: 1. create the wrapper procedure
procedure SOME_PROCEDURE_WRAPPER (p_session_id in number, p_data in varchar2)
is v_data raw(1024);
rawdata raw(1024);
rawlen number;
hex varchar2(32760);
i number;
begin
rawlen := length(p_data);
i := 1;
while i <= rawlen-1
loop
hex := substrb(p_data,i,2);
rawdata := rawdata || HEXTORAW(hex);
i := i + 2; end loop;
SOME_PROCEDURE(p_session_id , rawdata);
end;
2 then need to modify the code c# in this way:
var cmd = new OracleCommand("SOME_PROCEDURE_WRAPPER", _connection);
cmd.CommandType = CommandType.StoredProcedure;
string @string = statusData.ToHexString();
OracleParameter sessionId = new OracleParameter("dbSessionId", OracleDbType.Decimal, new OracleDecimal(_dbSessionId), ParameterDirection.Input);
OracleParameter data = new OracleParameter("statusData", OracleDbType.Varchar2,@string.Length, new OracleString(@string), ParameterDirection.Input);
cmd.Parameters.Add(sessionId);
cmd.Parameters.Add(data);
cmd.ExecuteNonQuery();
where
public static string ToHexString(this byte[] bytes)
{
if(bytes == null || bytes.Length == null)
return string.Empty;
StringBuilder hexStringBuilder = new StringBuilder();
foreach (byte @byte in bytes)
{
hexStringBuilder.Append(@byte.ToString("X2"));
}
return hexStringBuilder.ToString();
}
-
Passing an array as a parameter of java (java controls) for the stored procedure
Hello
I use java controls (BEA Weblogic Workshop 8.1) to call a stored procedure and send an array as a parameter to the stored procedure of java. The following code throws an exception 'Fail to convert the internal representation.
Java code
import com.bea.control.DatabaseControl.SQLParameter;
Here I create the java
int [] = {12,13,14} javaArray.
The code below is used to create the table from sql to oracle for the procedure
SQLParameter [] params = new SQLParameter [1];
Object obj0 = javaArray;
params [0] = new SQLParameter (obj0, oracle.jdbc.OracleTypes.ARRAY, SQLParameter.IN);
the code below calls the myFunc in file OJDBCtrl.jcx
String success = dbControl.testFunc (params);
OJDBCtrl.jcx
/**
* @jc: = sql statement ' call CMNT_TST_PROC (?)).
*/
String Myfunc (SQLParameter [] param);
The stored procedure that is used:
SL_tab IS NUMBER TABLE INDEX BY PLS_INTEGER;
Procedure cmnt_tst_proc (cmnt_tst sl_tab);
Procedure cmnt_tst_proc (cmnt_tst sl_tab) is
BEGIN
dbms_output.put_line ('Hello');
END;
I'm getting the following exception
Failure = Java.Sql.SqlException: Internal failure to convert the representation: [I@438af4 [ServiceException] >]
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
at oracle.jdbc.driver.DatabaseError.check_error(DatabaseError.java:861)
at oracle.sql.ARRAY.toARRAY(ARRAY.java:210)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:7768)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7449)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7837)
at oracle.jdbc.driver.OracleCallableStatement.setObject(OracleCallableStatement.java:4587)
at weblogic.jdbc.wrapper.PreparedStatement.setObject(PreparedStatement.java:244)
at com.bea.wlw.runtime.core.control.DatabaseControlImpl._setParameter(DatabaseControlImpl.jcs:1886)
at com.bea.wlw.runtime.core.control.DatabaseControlImpl.getStatement_v2(DatabaseControlImpl.jcs:1732)
at com.bea.wlw.runtime.core.control.DatabaseControlImpl.invoke(DatabaseControlImpl.jcs:2591)
at com.bea.wlw.runtime.core.dispatcher.DispMethod.invoke(DispMethod.java:377)
at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:433)
at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:406)
at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:249)
at com.bea.wlw.runtime.jcs.container.JcsContainer.invoke(JcsContainer.java:85)
at com.bea.wlw.runtime.core.bean.BaseContainerBean.invokeBase(BaseContainerBean.java:224)
at com.bea.wlw.runtime.core.bean.SLSBContainerBean.invoke(SLSBContainerBean.java:109)
at com.bea.wlwgen.StatelessContainer_ly05hg_ELOImpl.invoke(StatelessContainer_ly05hg_ELOImpl.java:153)
...
Can you please let me know, what am I doing wrong and how can I pass an array to a procedure/function using java controls.
Any help will be much appreciated.
Published by: user12671762 on February 24, 2010 05:03
Published by: user9211663 on February 24, 2010 21:04Try using an oracle.sql.ARRAY with a nested table or varray instead of a table index. Create the type SQL and Java object as follows
SQL> create type sl_tab as varray(3) of integer; Java: ArrayDescriptor ad = ArrayDescriptor.createDescriptor ("
.SL_TAB", java.sql.Connection); Object elements = new Object[3]; elements[0] = new Integer(12); elements[1] = new Integer(13); elements[2] = new Integer(14); oracle.sql.ARRAY array = new oracle.sql.ARRAY(ad, oracle.jdbc.OracleTypes.ARRAY, elements); SQLParameter[] params = new SQLParameter[1]; params[0] = new SQLParameter(array, oracle.jdbc.OracleTypes.ARRAY, SQLParameter.IN); String succ = dbControl.testFunc(params); I don't think that you can pass an array of Java, this is why you have more success using an oracle.sql.ARRAY with a SQL varray. -Michael-
-
query as a parameter in a stored procedure
Hi all
I'm working on Oracle 10 g.
Can I send a query as a parameter in a stored procedure?
Thanks in advanceYou can, of course. Should you? At most, rarely.
You can use SQL statements (EXECUTE IMMEDIATE or DBMS_SQL) Dynamics to run an arbitrary string as a SQL statement. There are serious security problems if someone how to pass a statement dangerous SQL in numbers (update the USERS table, remove all data from an important painting, etc.). If you pass in a SELECT statement and you do not know the structure of the result set, you must use DBMS_SQL rather than the simple EXECUTE IMMEDIATE and a more complicated API to describe the result set.
Justin
-
How to pass the Visa Resource Name parameter to labview dll in labwindows/cvi
Hello world
I build a dll of labview, the prototype is: double getchannelpower (double f, uintptr_t * VISAResourceName);
I don't know how to go from VISAResourceName to this function.
Is it related to the ViPSession paremeter in function viOpen(REES ViSession, rn ViRsrc, ViAccessMode am, ViUInt32 ti,ViPSession vi)?
BRs,
lotusky
Hey, guys:
I figured out how to pass the parameter.
In labview, you must replace the control of visa with string control. In this way, the generated dll function at the entrance of the string type.
I hope this will help others!
lotusky
-
Is it possible to move an Oracle null input parameter to a stored procedure
I have a stored procedure taking 3 inputs and 1 output of donne. I use the Oracle parameter to add all the input parameters 3 as follows:
OracleParameter = cmd inobj. Parameters.Add ("wid", OracleDbType.Int32, 50);
inobj. Direction = ParameterDirection.Input;
inobj. Value = _employeeID;
and the addition of the setting of output as follows:
OracleParameter outobj is _cmd. Parameters.Add ("w_first", OracleDbType.Varchar2, 50);
outobj. Direction = ParameterDirection.Output;
On the side of the user interface, the user has the option of providing 1 entry or all inputs or any 2 based on his interest. Stored proc looks like this:
SP (inp1 in parameter, inp2 in inp3 in parameter, parameter, out parameter output1)
If I just get 1 or 2 entries of the user, it is very good query output data using the same stored procedure or do I create stored procedures for each scenario (combination of different entries)?
I get an error in pl/sql which indicates the invalid number of arguments?Maybe I can be more clear with c# code. :)
void SaveSomethingInOracle(int param1, string param2 = null, decimal? param3 = null) { // Set up your oracle connection and query here OracleParameter inobj = _cmd.Parameters.Add("w_id", OracleDbType.Int32,50); inobj.Direction = ParameterDirection.Input; inobj.Value = param1; OracleParameter inobj2 = _cmd.Parameters.Add("name", OracleDbType.Varchar2,50); inobj2.Direction = ParameterDirection.Input; inobj2.Value = param2; OracleParameter inobj3 = _cmd.Parameters.Add("quantity", OracleDbType.Decimal,50); inobj3.Direction = ParameterDirection.Input; if (param3.HasValue) { inobj3.Value = param3.Value; } else { inobj3.Value = null; } }
This c# method takes 3 parameters. The first is necessary, the other two are optional. If you do not set them, they take the value default null and passing it to the database. If you want to set the first and third only, you can still pass null as the other. If you have this piece of code to call the stored procedure any combination of parameters that you use, and the proc will get values or NULL values properly.
Hope he says. You need only one together code to do what you want to do. :)
Published by: Tridus on December 19, 2012 12:10
-
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.
-
relative to the parameter in a stored procedure returns
I'm doing a sp sp / sql with select and update, the idea is to return the value assigned in the select, but when I test the procedure about adding the parameter to the method PPerformance does not, in fact I am new to oracle, I searched some tutorials but I have not managed to solve the problem
my source its:
the table og the request her:create or replace PROCEDURE PA_CONSECUTIVO (TipoConsecutivo in VARCHAR2, AUXI OUT int ) AS aux2 int; BEGIN SELECT consecutivo + 1 into aux2 FROM tbl_consecutivo WHERE UPPER(ltrim(rtrim(Tipo_Consecutivo))) = UPPER(ltrim(rtrim(TipoConsecutivo))); UPDATE tbl_Consecutivo SET consecutivo = aux2 WHERE upper(ltrim(rtrim(Tipo_Consecutivo))) = upper(ltrim(rtrim(TipoConsecutivo))) ; AUXI:=aux2; END PA_CONSECUTIVO;
I appreciate the help.TIPO_CONSECUTIVO VARCHAR2(20 BYTE) CONSECUTIVO NUMBER(38,0) FECHAULTIMO DATE
Published by: 1008490 on 29-may-2013 07:49Your stored procedure has 2 settings while you provide 1. Use something like:
SET SERVEROUTPUT ON DECLARE V_AUXI NUMBER; BEGIN PA_CONSECUTIVO('ENTRADA',V_AUXI); DBMS_OUTPUT.PUT_LINE('AUXI = ' || V_AUXI); END; /
SY.
-
Ignoring the empty parameter in a stored procedure
I am writing a SP that ignores an empty parameter in a where clause like this clause.
Create procedure @myvar AS int blah
Select * from companies
where 1 = 1
If @myvar is <>"
and id = @myvar
This seems to be a simple task, but it does not work. Thanks in advance
Use the ISNULL trick, but at the beginning of your stored procedure, add the line:
IF LTRIM (@myvar) = "SET @myvar = NULL -
How to accept the array as a parameter of stored procedure
Hi, this is the scenario
the java team send me a table of numbers as an input for my procedure.
the size of the array can be dynamic... I do not know the size
what I have to do is
I have to write a procedure that must accept this table as parameter
crosses of the first element of the array too the end of the array to each value in the table
and get on a table for this value and remove this line in the table
How can I do?
Please suggest
concerning
REDA
Published by: raj_fresher on May 7, 2009 11:42Raj,
Here is the code
--This is you will create create or replace type TYP_PHONES as table of Varchar2(15) ; / --- This will be your procedure create or replace procedure give_me_an_array1( p_array in TYP_PHONES ) as begin -- Do whatever you want to with the data you get for i in 1 .. p_array.count loop dbms_output.put_line( p_array(i) ); end loop; end; /
Tell your guy java to define this table as below
String[] intArray= {"john","miller","scott"}; ArrayDescriptor descriptor =ArrayDescriptor.createDescriptor( "TYP_PHONES", conn ); ARRAY array_to_pass = new ARRAY( descriptor, conn, intArray );
* [Full active code | http://db-oracl.blogspot.com/2009/05/passing-arrays-from-java.html] *.
SS
-
How to pass the external APEX URL parameter values
Hi all
Hope you can help me with the following:
During my first APEX application, I created a button that should have a parameter value of the current page to an external URL
I created a button.
The URL redirection target option is set to URL
[I put the URL target for the http://[URLNAME button]? [constant parameters] & p_variable =: P13_VALUE1
The APEX variable does not replace what I understand. Can someone tell me how it CAN be replaced?
Thank you very much
MarcoHi Marko,
You must use & P13_VALUE1. of the element to get by following the link.
Kind regards
Andrea -
How to pass the ProcessRequest for ProcessForm parameter request - Urgent
Hi all
I have a problem... need help please
I have:
Page1 and page2
I'm getting page 1 values/settings and when I go back to page 2 in the ProcessRequest method I am able to get the values of page 1. How can I return values of the method processRequest in page2 in the processFormRequest method because I save button in the processFormRequest method that needs to do validation on the grounds and if false must raise an error. I tried the following
* processRequest {*}
String s = pageContext.getParameter ("val1");
System.out.println (s); Returns a value
pageContext.putParameter ("test", s);
*}*
* processFormRequest {*}
* if (PageContext.GetParameter (saveBtn)! = null) {*}
Var p = pageContext.gatParameter("test");
System.out.println (p); Returns a null value
* if("p validation") {*}
error
*}*
*}*
*}*
Can someone help me please... urgent
Thank you
ValHello
You have entered the value of the process request
String s = pageContext.getParameter ("val1");
so, after that put in sessionpageContext.putSessionValue ("test", s);
Then in the application of the process that you capture booth in the
String value = pageContext.getSessionValue ("test");
Thank you
Gerard -
How to pass the object as a parameter in AS3?
I get the impression that the non-static objects passing is not allowed in AS3. I never had a problem with that in AS2. Am I correct in this understanding?
If Yes, do you know what is considered a best practice regarding pass non-static objects as parameters? Is not a good practice? Thank you!Ooops nevermind, I got the argument name of past typed exactly as the name of the class, that was the problem.
function(passed:passed) = boo boo
-
How to pass a LogicalSchema as a parameter
Hi all
is it possible to move the LSchema to a package?
I try to explain my situation.
I have a source with 3 other schema (one for each company) with the same table structure.
I have a target with 3 other schema (one for each company) with the same table structure.
I had a package that Stoke 1 table in the first pair of schema.
To load this table, I created a procedure that make a statement of 'create a table like' (using KM I have poor performance, suggest to KM performance is appreciated).
Inside of the command procedure I have to write the logic diagram, but this way I can't reuse the packaging, because I have to create another equal to the first package and modify the logic diagram within the ordering process.
In my view, that this is not the right way.
Is it possible to reuse code by the way of a logical schema as a parameter?
Thanks in advanceIf you have 3 environments by and n clients, you'll need to create 3 x n contexts. You have complicated it your first question ;-). I suggest that you have create 1 physical schema entry by actual physical schema and a single logical schema by set of identical tables - in your case, it seems that the contexts will be many, and you need to map the physical schema appropriate to the logical schema for each context.
You must ensure that you select the right logic diagram in any procedure/interface, as at run time, it will seek the combination/logic to resolve schema context which is the physical schema to use. -
How to pass 'SIGNAL' object as a parameter of QML
Hi all
I'm in a fundamental need for the object that caused the SIGNAL to occur,
E.g. by a signal "onClicked" (in QML) of the button if I call a method of CRACK or Q_INVOKABLE, then what I have
the purpose of the call?
As,
Button {}
text: 'Add container ".
onClicked: {}
injection.playSound ();
}
}
The code is taken from the tutorial. As you can see the "injection" is through "setContextProperty" and having
"playSound" method I want to do something like this
injection.playSound (' Button object which invoked this incrimination (onClicked) ');
and the method in the class curresponding will look like.
Q_INVOKABLE Sub playSound (bb::cascades:Button * buttonObject);
One? Please help me in this regard.
RIM, please take a look at these simple things and update documents.
Kind regards
Diagne
In c ++ make your method in the header
Q_INVOKABLE void playSound(QObject* buttonObject);
In your cpp file
MyClass::void playSound(QObject* buttonObject) { // Cast QObject to Button Button* myButton = qobject_cast
In your QML file:
injection.playSound(idOfYourButton);
Maybe you are looking for
-
Unable to connect to certain Web sites.
Unable to connect to youtube, google, and yahoo (search but engine mail works well). This has happened after the update of Windows 10.
-
I used "full screen" by mistake and wan t out is I see my toolbar.
How to get out of the mode "full screen"?
-
HP Pavilion Notebook PC g6: replacing the battery
Hello! As the ability of my current laptop battery starts to be measured in minutes, I am looking for a replacement. However, I had the misfortune to understand what type of battery I need. The HP PartSurfer has not been a great help. Naturally, I wo
-
An ipad will run a program of software written to run on xp, you also will be an ipad running windows? Concerning Nigel
-
Original title: display on the side I was using my computer and I went there for a few minutes. When I got home, the whole screen was on the side... not the monitor, but what was on the screen. I restared, unplugged, everything I could think... eve