How to pass an array to a stored procedure
create or replace package demo_pkg
as
type cityArray is table of city%rowtype index by binary_integer;
procedure city_report( p_inputs in cityArray );
end;
CREATE OR REPLACE PACKAGE BODY demo_pkg
AS
PROCEDURE city_report (p_inputs IN cityarray)
IS
BEGIN
FOR i IN 1 .. p_inputs.COUNT
LOOP
DBMS_OUTPUT.put_line ( 'citycode = '
|| p_inputs (i).city_code
|| ' CITYDESCRIPTION = '
|| p_inputs (i).city_description
INSERT INTO testing
(city_code, city_description
VALUES (p_inputs (i).city_code, p_inputs (i).city_description
commit;
END LOOP;
END;
END;
to call that procedure ia m using this
declare
my_data demo_pkg.cityArray;
begin
my_data(1).city_code := 1234;
my_data(1).CITY_DESCRIPTION := 10;
my_data(2).city_code := 4567;
my_data(2).CITY_DESCRIPTION := 20;
my_data(3).city_code := 4321;
my_data(3).CITY_DESCRIPTION := 30;
demo_pkg.city_report( my_data );
end;
but actually the procedure (demo_pkg.city_report)is called from front end(.net).how they will call this procedure in .net invironment
Hi,
Your exact question has been asked before, see: http://asktom.oracle.com/pls/ask/search?p_string=How+to+pass+an+array+to+a+stored+procedure
or do a search on this forum.
And please use this tag => (yes, just the 4 characters forming the word 'code' between curly brackets)
*before* and *after* your example to maintain formatting and indentation, it's hard to read now....
Similar Messages
-
How to pass the parameter of a stored procedure to iReport
Hi... i don't know how to pass the parameter of the stored procedure to the iReport.
In the Report Query, i tried
1. sp_storedprocedure ' value'
2. sp_storedprocedure +''''+$P{parameter}+''''+
3. sp_storedprocedure +$V+$P{parameter}++$F($F is a variable having a value of ' (a single quote))may you enlighten us please? thank youFor M$ SQL server I find that it only works when U use the fully qualified name...
e.g. catalod.dbo.my_procedure_name 'variable'
My full query in the Report Query window is something like this:
EXEC arc.dbo.jasper_Invoice 1000
Note that you may find that selecting from VIEWS / TABLES fails for no apparent reason and iReport will prompt you with the usual very unhelpful (we have what we "pay" for) prompt, stating that "The document is empty".
To work around this issue, where a statement like "SELECT * FROM arc.dbo.acc_invoices WHERE Invoice_id=1000" does not work, simply create a PROC, something like:
CREATE PROC jasper_MyProc (@my_rec_id integer) AS
SELECT * FROM arc.dbo.acc_invoices WHERE Invoice_id= @my_rec_id integer
...to wrap your SELECT statement, then call the PROC
Edited by: Sylinsr on Apr 22, 2008 4:23 PM -
How to pass javascript variable to PLSQL stored procedure
Hi,
How can I pass a javascript variable to a database procedure. I have a form with a radio button group and would like to save the value of the selected radio button to a database table by passing the value to the stored procedure.
ThanksHi
You can use iframe to call the procedure. Here is an example used in dynamic page or pl/sql portlet. The pl/sql procedure is called myprocedure and resists in the schema myschema. This example passes 2 parameters, but I have not yet reased a limit.
First the call within a javascript function:
myiframe.location.href="myschema.myprocedure?p_myprameter1=" + vJvascriptparameter1 + "&p_myprameter2=" + vJvascriptparameter2;
Then the iframe:
<iframe id="myiframe" height="0" width="0" frameborder="0"></iframe>
You can let the pl/sql procedure print a value, that can be used i the portlet. You can get the value in a javascript this way:
myvalue=top.window.frames["myiframe"].document.body.innerHTML;
Best regards
Klaus -
How to pass RECORD input type to stored procedure from JDBC?
Hi,
We have stored procedure which takes RECORD as input .
We could execute the below script from oracle client tool and get the response.
declare
l_record app.batch_update.add_record;
l_id number;
begin
-- memberNumber
l_record.no := '123456700';
-- Policy Number
l_record.pno := '1234567'
-- Status. This will always be NEW.
-- Call to API to add record
app.batch_update.add_request
(p_record => l_record,
p_id => l_id,
end;
We have requirement to construct RECORD input from Java application and pass it to callable statement.
We have tried to construct it via STRUCT and pass it to callable statement but it didn't work.
We have constructed it like the following but not sure whether it is correct. It was throwing error "java.sql.SQLException: invalid name pattern: app.batch_update.add_record
StructDescriptor structdesc = StructDescriptor.createDescriptor
("app.batch_update.add_record", delConn);
Object[] p1obj = {' 12345','124050'};
STRUCT p1struct = new STRUCT(structdesc, delConn, p1obj);
Not sure whether I am doing the logic correctly.
Please point me to the correct approach.
Thanks in Advice
ThanksWrap the method using a record-type parameter in PL/SQL; a simplified example follows. Add exception handling, translation of types etc. as needed.
CREATE OR REPLACE PROCEDURE prc_wrap_prc_using_rec
pv_my_field_01 IN VARCHAR2,
pv_my_field_02 IN VARCHAR2,
pv_my_field_99 IN VARCHAR2,
pv_err_msg OUT VARCHAR2
) AS
-- Non-scalar parameter
pr_my_record user.pkg_rec_declarations.wr_a_record_decl;
BEGIN
-- Load the work record
pr_my_record.pv_field_01 := pv_my_field_1;
pr_my_record.pv_field_02 := pv_my_field_2;
pr_my_record.pv_field_99 := pv_my_field_99;
-- Call the procedure
pkg_std_routines.prc_do_sumfin(pr_my_record, pv_err_msg);
END; -
How to pass global variables to call stored procedure in form personalizati
Hi,
We want to call a custom store procedure with 2 paramterts, I am storing values into 2 global variables.
We want call the custom store procedure with global variable values in form personalizations.
We tried like
='declare
begin
SUR_TEST_ORDER_LINE_UPD.update_order_line (:global.xx_line_id, :global.ship_set_id);
end'
Could you please suggest.
Advance Thanks
SubbuHi,
Doc number (MOS Doc 743490.) is avaiable in metalink or ?Yes.
Note: 743490.1 - Customization in Oracle Applications
https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=743490.1
Regards,
Hussein -
Passing array to oracle stored procedure in VC++ 2005
Hi,
I am try to send an array of integers to a stored procedure via ODBC 10.2.0.3 on VC++2005 enviornment. I get the below error
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'MYPROC1'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored ... Error Code = 6550
[]E R R O R
The same code works if I use an INSERT statement.
SQLUSMALLINT* rowsProcessed = new SQLUSMALLINT;
RETCODE nRetCode;
const int arraySize = 200;
long ptrVal[arraySize];
long ptrInd[arraySize];
long ptrStatus[arraySize];
for (int i = 0; i < arraySize; i++)
ptrVal = i;
ptrInd = 0;
nRetCode = SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0);
// assign the number of sets of parameters that are to be inserted
nRetCode = SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER)iSizeOfArray, 0);
// assign an array to retrieve status info for each row of parameter values
nRetCode =SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAM_STATUS_PTR, (SQLPOINTER)ptrStatus, 0);
// assign a buffer to store the number of sets of parameters that have been processed
nRetCode = SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAMS_PROCESSED_PTR, (SQLPOINTER)rowsProcessed, 0);
nRetCode = SQLBindParameter(m_hstmt, nParamIndex, nDirection, SQL_C_LONG, SQL_INTEGER, 0, 0, ptrVal, 0, ptrInd);
//suceeds
SQLPrepare(m_hstmt, (SQLCHAR*)"INSERT INTO my_table VALUES (?)", SQL_NTS);
//fails
SQLPrepare(m_hstmt, (SQLCHAR*)"{CALL mypackage.myproc1(?)}", SQL_NTS);
SQLExecute(m_hstmt);
package is
create or replace package mypackage
as
type mytable is table of binary_integer;
procedure myproc1( l_tab in mytable);
end;
show errors
create or replace package body mypackage
as
procedure myproc1( l_tab in mytable)
as
begin
insert into my_table values (100);
commit;
FORALL i IN l_tab.first .. l_tab.last
INSERT into my_table values( l_tab(i) );
end;
end;
any ideas?I believe when you're doing it with an insert, you're saying "execute this insert statement a bunch of times, here's all the values in advance", which is different than passing an array to a stored procedure where you want it to execute once.
Oracle's ODBC driver doesnt support Associative Arrays (aka index-by tables).
Hope it helps,
Greg -
How to pass int array as an IN parameter to PLSQL Procedure
Hi,
How to pass int array in java to a stored procedure througn jdbc
and what type of data type I should declare to this IN parameter
in PLSQL Procedure.
Thanks,
SimiHi,
The best way to do what you want depends on what you want. Start by describing what you need to do. It's best to post some sample data (CREATE TABLE and INSERT statments) and what results you want from that sample data. (See the forum FAQ: https://forums.oracle.com/message/9362002)
If you have ideas about how to do the job (e.g., populating a temporary table) it can be helpful to include those, too, but distinguish clearly between WHAT you need to do and HOW you might do it.
As Bencol suggested, a SYS_REFCURSOR might be the best way to pass back the results.
Since you didn't post your table, or even describe what you wanted to do with it, I'll illustrate using scott.emp, which is probably on your system.
Say you wanted a procedure that took a DATE as an argument, and returned a some designated columns (empno, ename and hiredate in the example below) for all employees hired on or after the given DATE. You might write a procedure like this:
CREATE OR REPLACE PROCEDURE hired_since
( start_date IN DATE
, out_data OUT SYS_REFCURSOR
AS
BEGIN
OPEN out_data FOR
SELECT empno, ename, hiredate
FROM scott.emp
WHERE hiredate >= start_date;
END hired_since;
SHOW ERRORS
You can test it in SQL*Plus like this:
VARIABLE c REFCURSOR
EXEC hired_since (DATE '1982-01-01', :c);
PRINT :c
The output I got from this test was:
EMPNO ENAME HIREDATE
7788 SCOTT 19-APR-87
7876 ADAMS 23-MAY-87
7934 MILLER 23-JAN-82 -
I am ussing a DLL created by another party. I have the list of the C declaretions. I have been able to write a seq that can turn the comport ON/OFF or select a different port but I have not been able to send or recieved any data. I have created an array of bytes(unsigned 8-bit integers)to send and recieved data but nothing goes out or in.
Hi Toro,
There is an example in your \Examples\AccessingArrays\PassingArrayParametersToDLL directory that illustrates exactly how to pass TestStand arrays as arguments to dll functions. The source files for the .dll are located in the same directory.
For more information on passing arrays as parameters to modules you should read the "DLL Flexible Prototype Adapter" section of Chatper 13 in the TestStand User Manual, and pay special attention to the subsection entitled "Array Parameters". You can access the User Manual from the TestStand Start Menu group, the TestStand Sequence Editor's Help menu, the \Doc directory, or online at the following link:
http://digital.ni.com/manuals.nsf/websearch/50B69DA356B8D38C86256A0000660E6B?OpenDocumen
t&node=132100_US
Jason F.
Applications Engineer
National Instruments
www.ni.com/ask -
Passing arrays to Oracle Stored procedure.
Have any body passed arrays to Oracle stored procedures while the app is running in Weblogic app server. I am able to pass the arrays with regular JDBC connection. If I run the same piece of code using a connection recieved from the datasource of weblogic server, its not working. I am getting serialization errors with the ArrayDescriptor class. Looks like the ArrayDescriptor is not serializable.
Does anybody know solution/workaround to pass arrays ?
Thanks in advanceyou could write a wrapper class that extends ArrayDescriptor and implements serializable...
for example your class would look something like this.
public class MyArrayDescriptor extends ArrayDescriptor
implements Serializable
in your regular code use the wrapper class in place of the ArrayDescriptor (it will contain all the same methods as the real ArrayDescriptor) and you should be able to toss your wrapper class anywhere you please. -
How to pass an Array to jsp:param
Hi,
I am trying to find out how to pass an array to a jsp:param tag abnd then retrieve
the values in the next page. Please help soon. Thanks
Here's my code - Assume the books array has more than 1 value
String[] books = request.getParameterValues("book");
<jsp:include page="<%=contentPage%>" flush="true">
<jsp:param name="bookSelected" value="<%= books %>" />
</jsp:include>
The 'contentPage' takes me to the next page where I have the following to retrieve
the value of 'bookSelected'
String[] bookSelected = request.getParameter("bookSelected");
I tried accessing the array like this
if(bookSelected.equals("book1"))
but did not succeed.
I tried accessing the array in a loop but it did not work. Here's what I tried.
<jsp:include page="<%=contentPage%>" flush="true">
<%for (int i = 0; i<books.length; i++){
%>
<jsp:param name="bookSelected" value="<%= books %>" />
<% } %>
</jsp:include>
Hi
tell me how you redirect from __confirmdelete.jsp:__ to deleteServlet.java..
and post detail code of __confirmdelete.jsp:__ -
URGENT: I want to pass a variable to a stored procedure at run time
Post Author: aruplabs
CA Forum: Data Connectivity and SQL
I work for a health care provider and I have reports that pull PHI (Protected Health Information) about patients that needs to be logged according to federal HIPAA regulations. One of the pieces of information that needs to be logged is the username of the person who ran the report. Since these reports will be run from our Crystal Enterprise server I can get this from the CurrentCEUserName variable but I am looking for a way to pass this value to a stored procedure that will not only return the records for the report, but also log the disclosure in our PHI disclosure tracking table. I know you can pass a parameter to a stored procedure but I dont know how, or if it is even possible, to pass a run time variable. This is an urgent problem that I need to find a solution for. Any help would be appreciated.
Thank you.Here it is. Right now, when i press te "Go" it runs for the specific time i've set and when its done the variable "Run" is set true. When i call this VI from another VI it waits for the loop to be finished before it will read the variable.
Regards
Viktor
Attachments:
Untitled 2.vi 26 KB -
Passing multi-value parameter in stored procedure ssrs
I have customer parameter which is a drop down list in my report and I have set it to "allow multiple values". This is an SSRS report.
How do I pass multiple values to my stored procedure?
RJHi ,
Create a Table valued function in SQL Functions as below
Step 1
CREATE FUNCTION [dbo].[FnSplit]
@List nvarchar(2000),
@SplitOn nvarchar(5)
RETURNS @RtnValue table
Id int identity(1,1),
Value nvarchar(100)
AS
BEGIN
While (Charindex(@SplitOn,@List)>0)
Begin
Insert Into @RtnValue (value)
Select
Value = ltrim(rtrim(Substring(@List,1,Charindex(@SplitOn,@List)-1)))
Set @List = Substring(@List,Charindex(@SplitOn,@List)+len(@SplitOn),len(@List))
End
Insert Into @RtnValue (Value)
Select Value = ltrim(rtrim(@List))
Return
END
Step 2 in your store procedure change the parameter where condition something like below
ALTER PROCEDURE [dbo].[SomeSP]
-- Add the parameters for the stored procedure here
@CostCentre NVARCHAR(255)
SELECT
[ProjectCode],[ProjectName],[ProjectManager],SUM([Hours]) AS [Hours MTD]FROM dbo.Rpt_NRMA_CATS NC
INNER JOIN PeriodID P ON NC.PeriodID=P.PeriodID
WHERE
([CostCentre]) collate database_default IN(SELECT Value FROM dbo.FnSplit(@CostCentre,','))
END
I hope this will help you.
Dasari -
Conversion of java Array to oracle SQL Array while calling Stored Procedure
How java Array can be converted to oracle SQL array while calling Stored procedure with callable statement.
i.e java Array ---> Sql Array in Oracle while setting the datatypes to callable statement arguments.Look at:
http://forum.java.sun.com/thread.jsp?forum=48&thread=376735&tstart=0&trange=15
Paul -
How to execute multiple queries in one stored procedure.
Hi,
I am Kumar,
How to execute multiple queries in one stored procedure.
here is the my requirements,
1. get the max value from one table and sum of the that value.
2. insert the values and also sum of the max value.
using stored procedure
I am using SQL server 2000 database.
Please help me.
Advance thanks
by,
KumarThis is not a java question and it is not even a problem: your only problem is
1) lack of knowledge
2) lack of interest to find a manual
But you are going to have to change both by actually reading a book or a manual that explains the stored procedure language of SQL Server. It is the same as Sybase I think, so you could also look for a manual for that DBMS. -
Command for "How to find Cursor Size" in Oracle Stored Procedure"
Hi
Can u tell me....
How to find Cursor Size" in Oracle Stored Procedure........
I want command for that........why don't you try select count(*) from your_table;That requires running the same query twice - or rather running two different queries twice. Besides it still doesn't guarantee anything, because Oracle's read consistency model only applies at the statement level (unless you're running in a serialized transaction).
This is such a common requirement - users are wont to say "well Google does it" - it seems bizarre that Oracle cannot do it. The truth is that that Google cheats. Firstly it guesses the number on the basis of information in its indexes and refines the estimate as pages are returned. Secondly, Google is under no onus to kepp all its data and indexes synchronized - two simultaneous and identical queries which touch different Google servers can return different results. Oracle Text works the same way, which is why we can get a count with CTX_QUERY.COUNT_HITS in estimate mode.
Cheers, APC
blog: http://radiofreetooting.blogspot.com
.
Maybe you are looking for
-
How to put ipod on another comp withou losing info
My neighbor put my daughters ipod on his computer yesterday now when i try to put it on mine it asks if I want to change the library location but that all the songs on her ipod 30G will be lost. How can I change library locations without losing this
-
User exit to set user status for quote
Hi, I need to update the user status in the header of quotation (using VA22) based on some conditions. I checked the user exit's under 'MV45AFZZ' but no use. Could any one please provide me where I can write the code to put the conditions before upat
-
Hi gurus I m facing a typical error in Bex Reporting. This report displays the details of consumer address details. The data is successfully browsed from data tgt browser in ODS.while creating the reporting and query it gives me these 3 errors. Note:
-
Library preparing.......................never does, why?
-
Delete distribution point in specific package
I need to delete already assign distribution points for specific package. Basically need to remove distribution point and add different distribution point to selected package . since sms_distributionPoint status property read only I cant change it to