How to pass a table as parameter on a stored procedure
Hello all,
I want to pass the name of a table as parameter into a stored procedure, that will be used for cursors etc.
But when i pass the parameter and i compile the S.P. it give me error (error: table not existing...)
Any Help?
Thanks in advance, Marco
Marco wrote:
As i've written above, i'm using stored procedures like 'batch' programs which will be executed with oracle scheduler (passing to s.p. the name of the 'input' tables)
These input tables are 'external' tables which have got the same structure; for example i've got TABLEX_001, TABLEX_002, XXTAB etc. with the same structure.
This is the the reason... what do you think?An external table definition can reference multiple files via the LOCATION definition or you can user "ALTER TABLE" to alter the location and change the file that the external table points to.
Thus you only need one static External Table and use an alter table (via execute immediate) to change the file location it points to, or if you want all the data together, just specify all the files in the location.
That would be clean design, using one fixed table, without the need to pass any table names, just dynamically altering the file names if necessary at run time.
Similar Messages
-
Add Table Valued Parameter to a stored procedure
I have a stored procedure that voids an invoice and puts the items back into inventory and makes available the payment that was used to apply to this invoice... I would like to be able to do all this for a number of invoices at a time using a table valued
parameter how would I be able to do it?
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Debra
-- Create date: March 25, 2014
-- Description: Void an invoice.
-- =============================================
CREATE PROCEDURE AR_VOID
-- Add the parameters for the stored procedure here
@Invoice INT,
@InvType nvarchar(3)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
IF(@InvType = 'reg')
BEGIN
UPDATE INV SET ONHAND = ONHAND + ARD.Qty ,STAMPED = CASE WHEN INV.TYPE = 'CIG' THEN STAMPED + ARD.QTY ELSE 0 END, LASTDATE = CONVERT(DATE, GETDATE()) FROM ARD JOIN INV ON ARD.ITEM = INV.ITEM
WHERE ARD.INVOICE = @Invoice
MERGE INTO RECEIPTSH target
USING (SELECT JOURNAL, SUM(AMOUNT) AMOUNT FROM Applied
WHERE INVOICE = @Invoice GROUP BY JOURNAL) AS source
ON target.Journal = source.Journal
WHEN MATCHED THEN
UPDATE
SET Applied = Applied - SOURCE.Amount;
DELETE Applied WHERE INVOICE = @Invoice
END
ELSE
BEGIN
UPDATE INV SET ONHAND = ONHAND - ARD.Qty ,STAMPED = CASE WHEN INV.TYPE = 'CIG' THEN STAMPED - ARD.QTY ELSE 0 END, LASTDATE = CONVERT(DATE, GETDATE()) FROM ARD JOIN INV ON ARD.ITEM = INV.ITEM
WHERE ARD.INVOICE = @Invoice
MERGE INTO ARH target
USING (SELECT INVOICE, SUM(AMOUNT) AMOUNT FROM CREDITMEMO WHERE CINVOICE = @Invoice GROUP BY INVOICE) AS source
ON target.INVOICE = source.INVOICE
WHEN MATCHED THEN
UPDATE
SET [OPEN] = 'TRUE', CLOSEDATE = NULL, PAID = target.PAID - source.AMOUNT;
DELETE CREDITMEMO WHERE CINVOICE = @Invoice
END
UPDATE ARH SET SUBTOTAL = 0, TAXES = 0, PAID = 0, STATUS = 'VOD', [OPEN] = 'FALSE', CLOSEDATE = CONVERT(DATE,GETDATE()) WHERE INVOICE = @Invoice
UPDATE ARD SET QTY = 0, ARD.PRICE = 0 WHERE INVOICE = @Invoice
END
GO
Debra has a questionTry
CREATE TYPE InvoicesList AS TABLE (InvoiceID INT)
GO
- =============================================
-- Author: Debra
-- Create date: March 25, 2014
-- Description: Voids passed invoices.
-- =============================================
CREATE PROCEDURE AR_VOID
@InvoicesList InvoicesList READONLY,
@InvType nvarchar(3)
AS
BEGIN
SET NOCOUNT ON;
IF(@InvType = 'reg')
BEGIN
UPDATE INV SET ONHAND = ONHAND + ARD.Qty ,STAMPED = CASE WHEN INV.TYPE = 'CIG' THEN STAMPED + ARD.QTY ELSE 0 END, LASTDATE = CONVERT(DATE, GETDATE()) FROM ARD JOIN INV ON ARD.ITEM = INV.ITEM
WHERE ARD.INVOICE IN (SELECT InvoiceID FROM @InvoicesList)
MERGE INTO RECEIPTSH target
USING (SELECT JOURNAL, SUM(AMOUNT) AMOUNT FROM Applied
WHERE INVOICE IN (SELECT InvoiceID FROM @InvoicesList) GROUP BY JOURNAL) AS source
ON target.Journal = source.Journal
WHEN MATCHED THEN
UPDATE
SET Applied = Applied - SOURCE.Amount;
DELETE Applied WHERE INVOICE IN (Select InvoiceID FROM @InvoicesList)
END
ELSE
BEGIN
UPDATE INV SET ONHAND = ONHAND - ARD.Qty,STAMPED = CASE WHEN INV.TYPE = 'CIG' THEN STAMPED - ARD.QTY ELSE 0 END, LASTDATE = CONVERT(DATE, GETDATE()) FROM ARD JOIN INV ON ARD.ITEM = INV.ITEM
WHERE ARD.INVOICE IN (SELECT InvoiceID FROM @InvoicesList)
MERGE INTO ARH target
USING (SELECT INVOICE, SUM(AMOUNT) AMOUNT FROM CREDITMEMO WHERE CINVOICE IN (SELECT InvoiceID FROM @InvoicesList) GROUP BY INVOICE) AS source
ON target.INVOICE = source.INVOICE
WHEN MATCHED THEN
UPDATE
SET [OPEN] = 'TRUE', CLOSEDATE = NULL, PAID = target.PAID - source.AMOUNT;
DELETE CREDITMEMO WHERE CINVOICE IN (SELECT InvoiceID FROM @InvoicesList)
END
UPDATE ARH SET SUBTOTAL = 0, TAXES = 0, PAID = 0, STATUS = 'VOD', [OPEN] = 'FALSE', CLOSEDATE = CONVERT(DATE,GETDATE()) WHERE INVOICE IN (SELECT InvoiceID FROM @InvoicesList)
UPDATE ARD SET QTY = 0, ARD.PRICE = 0 WHERE INVOICE IN (SELECT InvoiceID FROM @InvoicesList)
END
GO
I didn't look too close into your code, so I just translated your code as is into TVP.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
How to pass a list of IDs to a stored procedure ?
Hi All,
My table has two columns customerID (int) and customerName
I want to write a stored procedure that will get a list of integers and then return all the customers names associated with these IDs. How to do that ?
ThanksPlease post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on SQL forums.
<Removed unrelated comments>
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking in
Sets / Trees and Hierarchies in SQL -
CR XI - Pass a Multi-value Parameter to a Stored Procedure
Hello,
Here is my problem !
My Main Report accept a Multi-value Parameter "myParameter".
I create a formula "lstParameter" (Join({?myParameter},',') linked to my SubReport (string static parameter based on a Stored Procedure which returns a RefCursor (ORACLE)).
When I launch the Main Report, he is blank...but if I open the subreport in the overview i can see the result...
it seems like the MainReport don't call the SubReport, or something like that...
I hope you can help me !
Thanks
Anthony
Edited by: anthony.44 on Jan 12, 2012 4:53 PM
Edited by: anthony.44 on Jan 13, 2012 9:51 AMhello,
I resolve my problem....just inside into the detail of the Master report a result of a query (ex: select sysdate from dual)...and the sub report is called correctly -
How to pass parameters when we create datablock through stored procedure..
I have one table emp table.
I have created one package pk_ref_cursor,In that my recursor return type is record type.
I created one procedure p_test with two parameters...
1. ref cursor type
2. deptno
Now i created one data block through procedure...
Then i run my form it's giving no records.Because i am not passing parameter deptno.
Now i go to block property 'QUERY DATA SOURCE ARGUMENTS'.Here i set the parameter p_deptno is 20
Then i run the form it's giving some records for deptno 20.
But every time i cannot open fmb form and change the property.
Is there any way to pass parameter..
Just see my code...
--Package spec
CREATE OR REPLACE PACKAGE pk_ref_cursor IS
TYPE p_record IS RECORD(p_num emp.empno%TYPE,
p_name emp.ename%TYPE);
TYPE p_ref IS REF CURSOR RETURN p_record;
PROCEDURE p_test(p_data IN OUT p_ref,p_deptno IN NUMBER);
END pk_ref_cursor;
--Package body
CREATE OR REPLACE PACKAGE BODY pk_ref_cursor IS
PROCEDURE p_test(p_data IN OUT p_ref,p_deptno IN NUMBER) IS
BEGIN
OPEN p_data FOR SELECT empno,ename FROM EMP WHERE deptno = p_deptno;
END;
END pk_ref_cursor;
Thanks,But how to use package variables...
Can u show me one example.. -
Passing Multi-Value Parameter to a Stored Procedure
Has anyone experienced passing a Parameter (MultiValue) to a Stored Procedure? I am aware that Crystal Passes the Param as an Array. How would you go about handling this within a Stored Procedure???
Hi Daniel
Try as below:
1. Create a Crystal report, and add a multi-value parameter.
2. Since the multi-value parameter is treated as an array, create a formula that uses the JOIN function. Create a formula as below:
//Formula: @JoinFormula
Join ({?Multi-value parameter array},";")
====================
NOTE:
In the formula above, a semi-colon (";") is the delimiter.
====================
3. Within the main report, create a subreport based on the stored procedure, and include the parameter to be populated with the multi-value list.
4. Link the Join formula in the main report to the stored procedure parameter in the subreport.
Doing so passes a multi-value parameter to the stored procedure.
Hope this helps!!!!
Regards
Sourashree -
Would like to pass multi-value parameter to a stored procedure
Hi,
Is it possible to pass a multi-value parameter to a stored procedure using crystal reports.
Is there is a way to do so??/
Thanks,
Brian.Hi,
Is it that you want to pass 2 or more parameters to a stored proc. it is possible
go to database expert
select your connection and click on add command their you will have to create parameters and pass to a proc
for ref..
{CALL `menagerie`.`sp_timer`({?delay time},{?delay time2})}
where `menagerie`.`sp_timer` is a stored proc.
and delay time and delay time2 are parameters.
but if it is like you have to pass multiple values to stored proc using single parameter as per my experience its
not possible. -
Table of records from a stored procedure
Hi
Where could I find an example or documentation about how to retrive a table of records from a Stored Procedure ??
ThanksTry:
CREATE OR REPLACE TYPE scott.MYRECORDTYPE as object
(a int, b varchar2(40), c date, d number(10));
CREATE OR REPLACE TYPE scott.MYTABLETYPE is table of myrecordtype;
CREATE OR REPLACE PACKAGE BODY scott.MYPACKAGE
as
type number_collection is table of number(38) index by binary_integer;
type varchar2_collection is table of varchar2(4000) index by binary_integer;
type date_collection is table of date index by binary_integer;
g_data myTableType;
empno_col number_collection;
ename_col varchar2_collection;
hiredate_col date_collection;
mgr_col number_collection;
function my_function return myTableType
is
begin
select empno, ename, hiredate, mgr
bulk collect into empno_col, ename_col, hiredate_col, mgr_col
from emp
order by empno; -- Get some data
g_data := myTableType(); -- Initialize
for i in empno_col.first .. empno_col.last loop
g_data.extend; -- Write something in the array
g_data(i) := myRecordtype(empno_col(i), ename_col(i), hiredate_col(i), mgr_col(i));
end loop;
return g_data;
end;
end;
-- Demonstration-View
CREATE OR REPLACE VIEW scott.myview
AS
select a,b,c,d
from table(cast(myPackage.my_function() as mytabletype)); -
How to pass internal table values to parameter
hi,
how to pass internal table values to parameter in selection screen.if is it possible means please sent codeings.
thanks.
stalin.hi,
tables : mara.
data : begin of itab_mara occurs 0,
matnr like mara-matnr,
ernam like mara-ernam,
end of itab_mara.
selection-screen : begin of block blk1 with frame title text-001.
parameters : p_matnr like mara-matnr.
selection-screen : end of block blk1.
select matnr ernam from mara into corresponding fields of itab_mara
where matnr = p_matnr.
loop at itab_mara.
write :/ itab_mara-matnr,
itab_mara-ernam.
endloop.
<b><REMOVED BY MODERATOR></b>
Message was edited by:
Alvaro Tejada Galindo -
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 more than one parameter
Hello,
This is my code.
How to pass more than one parameter:
SELECT:responsibility_name responsibility_name,
LPAD(' ', 6*(LEVEL-1))
|| menu_entry.entry_sequence sequence ,
LPAD(' ', 6*(LEVEL-1))
|| menu.user_menu_name SubMenu_Description ,
LPAD(' ', 6*(LEVEL-1))
|| func.user_function_name Function_Description ,
LPAD(' ', 6*(LEVEL-1))
|| menu_entry.prompt prompt
,menu.menu_id ,
func.function_id
--menu_entry.grant_flag Grant_Flag ,
--DECODE( menu_entry.sub_menu_id , NULL, 'FUNCTION' , DECODE( menu_entry.function_id , NULL, 'SUBMENU' , 'BOTH') ) Type
FROM fnd_menu_entries_vl menu_entry ,
fnd_menus_tl menu ,
fnd_form_functions_tl func
WHERE menu_entry.sub_menu_id = menu.menu_id(+)
AND menu_entry.function_id = func.function_id(+)
AND MENU.LANGUAGE(+) = 'US'
AND FUNC.LANGUAGE(+) = 'US'
--AND func.user_function_name LIKE '%Primary Care Providers%'
AND grant_flag = 'Y'
START WITH menu_entry.menu_id =
(SELECT menu2.menu_id
FROM fnd_menus_tl menu2,apps.fnd_responsibility_vl resp
WHERE menu2.menu_id=resp.menu_id
and resp.responsibility_name= :responsibility_name
--and menu2.user_menu_name = ('ATCO HR INQ USER'
AND LANGUAGE = 'US'
CONNECT BY MENU_ENTRY.MENU_ID = PRIOR MENU_ENTRY.SUB_MENU_ID
and menu_entry.function_id not in (select func.function_id
from --fnd_form_functions_vl fnc,
apps.fnd_resp_functions exc,
apps.fnd_responsibility_vl res
where func.function_id = exc.action_id
and res.responsibility_name =:responsibility_name
and res.responsibility_id=exc.responsibility_id)
and menu_entry.sub_menu_id not in (select menu.menu_id
from --fnd_menus_vl imn,
apps.fnd_resp_functions exc,
apps.fnd_responsibility_vl res
where menu.menu_id = exc.action_id
and res.responsibility_name =:responsibility_name
and res.responsibility_id=exc.responsibility_id)
ORDER SIBLINGS BY menu_entry.entry_sequence;
Thank you for your help
ShuishenmingHi, Ming,
One way is to put the "parameters" in a table, and join to that table in your query. If you make it a Global Temporary Table, then multiple sessions can run the query at the same time, and each can be seeing different responsibilities.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data. Since this problem involves parameters, you should give a couple of different sets of parameters, and the results you want from the same sample data for each set.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002 -
How to pass multi value selection parameter to SAP Function Module?
Hi ,
Anyone know how to pass CR multi value parameter - array to SAP Function module ?
eg multi selection of customer in CR
and then pass to Function module
in SAP FM, the SQL select these customer only
How should the import parameter / table of SAP Function module designed?
and how should CR pass the data to SAP FM
thx
JohnMoved to Integration Kit forum
-
Pass temporary table as parameter to a procedure from Java
Hi,
I have a PL/SQL procedure that has as input parameter a temporary table. For calling this procedure from PL/SQL there is no problem: I declare a variable having the type temporary table%ROWTYPE, I fill the table with data and then call the procedure. Now I have to call this procedure form Java and I do not know how can I declare a variable of type temporary table, fill it with data and then pass it to the procedure. I have seen and implemented passing arrays of strings or numbers to stored procedures but I have no clue how can I pass the temporary table. Anyone any clues?
Thank you,
FlorinHi Avi,
the table is defined like this:
CREATE GLOBAL TEMPORARY TABLE ticket_api (
ticket VARCHAR2(16),
party_id NUMBER,
date_from DATE,
date_to DATE )
ON COMMIT PRESERVE ROWS;
there is defined a type like this:
TYPE ticket_tabletype IS
TABLE OF ticket_api%ROWTYPE;
the procedure definition is like this:
PROCEDURE get_ticket_data (
p_tickets IN ticket_tabletype ,
x_action_plan OUT NOCOPY action_plan_tabletype );
the action_plan_tabletype is defined like this:
TYPE action_plan_tabletype IS
TABLE OF action_plan_cursor%ROWTYPE;
When calling the procedure from PL/SQL I use the following code:
DECLARE
inTickets ticket_tabletype := ticket_tabletype ();
outActionPlan action_plan_tabletype;
BEGIN
inTickets.EXTEND;
inTickets(1).ticket := 'ABCDEFG';
inTickets(1).party_id := 123456789;
inTickets(1).date_from := TO_DATE('01-JAN-05', 'DD-MON-YY');
inTickets(1).date_to := SYSDATE;
get_ticket_data(
p_tickets => inTickets,
x_action_plan => outActionPlan);
DBMS_OUTPUT.PUT_LINE('Actions: '||outActionPlan.COUNT);
END;
Thanks for your quick feedback,
Florin -
How to pass internal table to method of class
Hi all,
I am new to abap objects, i want to pass one internal table to class.
i am trying in this way.
class c1 definition.
method get_material importing t_stpo type any table
exporting t_mast type any table.
endmethod.
endclass.
class c1 implementation.
method get_material.
select f1 f2 f3 from <tab> into table t_mast
for all entries in t_stpo
where stlnr = t_stpo-stlnr.
endmethod.
endclass.
ERROR:
"stlnr" is not available
if i use this way. its not giing error.
class c1 definition.
method get_material exporting t_mast type any table.
endmethod.
endclass.
class c1 implementation.
method get_material.
select f1 f2 f3 from <tab> into table t_mast
for all entries in it_stpo
where stlnr = it_stpo-stlnr.
endmethod.
endclass.
how to pass internal table with some specific reference may be using like or type <it_xxxx>
thanksTry this.
TYPES : BEGIN OF ty_stpo,
stlnr TYPE stpo-stlnr,
idnrk TYPE stpo-idnrk,
menge TYPE stpo-menge,
END OF ty_stpo,
BEGIN OF ty_mast,
matnr TYPE mast-matnr,
werks TYPE mast-werks,
stlnr TYPE mast-stlnr,
END OF ty_mast,
tt_stpo TYPE TABLE OF ty_stpo,
tt_mast TYPE TABLE OF ty_mast.
DATA : it_stpo TYPE tt_stpo,
it_mast TYPE tt_mast.
* CLASS c1 DEFINITION
CLASS c1 DEFINITION.
PUBLIC SECTION.
METHODS : get_bom_numbers EXPORTING ex_stpo type tt_stpo,
get_parent_material IMPORTING im_stpo TYPE tt_stpo
EXPORTING ex_mast TYPE tt_mast.
endclass.
* CLASS c1 IMPLEMENTATION
CLASS c1 IMPLEMENTATION.
METHOD get_bom_numbers.
ENDMETHOD. "get_bom_numbers
METHOD get_parent_material.
ENDMETHOD. "get_parent_material
START-OF-SELECTION.
DATA : obj TYPE REF TO c1.
CREATE OBJECT obj.
CALL METHOD obj->get_bom_numbers
IMPORTING
t_stpo = it_stpo.
CALL METHOD obj->get_parent_material
EXPORTING
im_stpo = it_stpo
IMPORTING
ex_mast = it_mast.
Regards,
Rich Heilman -
How to pass this multi-value parameter via GoURL?
Currency is equal to / is in 'USD', 'GBR', 'RUR'. How to pass such multi-value parameter via GoURL?
P0=1&P1=eq&P2=Measures.Currency&P3=?Found. P0=1&P1=eq&P2=Measures.Currency&P3=3+USD+GBR+RUR
Maybe you are looking for
-
Query SQ01: Table for customer revenue
Hi, I have created a query using amongst other table KNKK. The requirement his now to get for a customer (in all sales-areas and company code) the total revenue for a give year. What is the best way to acheive this? Is there a table i could use which
-
YouTube not available in denmark on iPhone
YouTube has not been available in denmark for more than a week now. If I change from danish to english it works just fine, but back to danish it unavailable.
-
Device registration is awful!
I am Sky Multiscreen customer so I have 4 available slots for sky go devices but I only use 2. I removed a xbox from the 3rd slot yesterday as we no longer have that xbox Anyway I was using Sky go fine yesterday on my laptop then earlier today I upda
-
Ipod requires disk utility repair after update
I have the 80gb fifth gerneration ipod, i have had issues alrady mentioned error 48, unable to write/read etc. However i restored the ipod and disabled iphoto impport to ipod and they have gone away... I updated my ipod with some new tracks and ran "
-
Acrobat Pro broken after Time Machine restore
I had to restore my whole 10.5.2 system yesterday using a Time Machine backup from a week ago. All my CS3 apps are fine after the restore -- except for Acrobat Pro 8.1.2 which on attempted launch declares "Adobe Acrobat was unable to install and must