Passing different tables as a input parameter
HI,
I've 5 tables TAB1, TAB2, TAB3, TAB4, TAB5
and I created 5 store procedures to generate 5 file.txt with utl_file utility.
Now I'd like to know if possible create just one stored procedure (or package) with just one cursor
that passing different tables as a input parameter.
Have you any idea?
Thanks in advance!
Here you go...
SQL> create table tab1 as select 1 as x, 'A' as y from dual union
2 select 2, 'B' from dual union
3 select 3, 'C' from dual;
Table created.
SQL>
SQL> create table tab2 as select 4 as x, 'D' as y from dual union
2 select 5, 'E' from dual union
3 select 6, 'F' from dual;
Table created.
SQL>
SQL> CREATE OR REPLACE PROCEDURE output_tbl (p_table_name IN VARCHAR2) IS
2 v_cur SYS_REFCURSOR;
3 x NUMBER;
4 y VARCHAR2(10);
5 BEGIN
6 OPEN v_cur FOR 'SELECT x, y FROM '||p_table_name||' ORDER BY x';
7 LOOP
8 FETCH v_cur INTO x, y;
9 EXIT WHEN v_cur%NOTFOUND;
10 -- Here you would output to your file, but for ease of
11 -- demonstration I'll just dbms_output the data
12 DBMS_OUTPUT.PUT_LINE(x||' : '||y);
13 END LOOP;
14 END;
15 /
Procedure created.
SQL> exec output_tbl('TAB1');
1 : A
2 : B
3 : C
PL/SQL procedure successfully completed.
SQL> exec output_tbl('TAB2');
4 : D
5 : E
6 : F
PL/SQL procedure successfully completed.
SQL>
Similar Messages
-
Pass multiple values as single input parameter into pipelined function
Hi all,
My need is to pass multiple values as single input parameter into pipelined function.
For example - "2" and "3" are values of input parameter "t":
with data as (
select 1 as t from dual union all
select 2 as t from dual union all
select 3 as t from dual union all
select 4 as t from dual union all
select 5 as t from dual
select * from data where t in (2,3)Is it possible at all?Not exactly sure, but usually 'multiple values'+'pipelined function' = some IN-LIST related approach?
See:
SQL> create table data as
2 select 1 as t from dual union all
3 select 2 as t from dual union all
4 select 3 as t from dual union all
5 select 4 as t from dual union all
6 select 5 as t from dual;
Table created.
SQL> --
SQL> CREATE OR REPLACE FUNCTION in_list (p_in_list IN VARCHAR2)
2 RETURN sys.odcivarchar2list PIPELINED
3 AS
4 l_text VARCHAR2(32767) := p_in_list || ',';
5 l_idx NUMBER;
6 BEGIN
7 LOOP
8 l_idx := INSTR(l_text, ',');
9 EXIT WHEN NVL(l_idx, 0) = 0;
10 PIPE ROW (TRIM(SUBSTR(l_text, 1, l_idx - 1)));
11 l_text := SUBSTR(l_text, l_idx + 1);
12 END LOOP;
13
14 RETURN;
15 END;
16 /
Function created.
SQL> --
SQL> select *
2 from data
3 where t in ( select *
4 from table(in_list('1,2'))
5 );
T
1
2
2 rows selected.http://www.oracle-base.com/articles/misc/dynamic-in-lists.php
or
http://tkyte.blogspot.nl/2006/06/varying-in-lists.html -
Pass Layout Template as a input parameter to Data Template
Hi,
I am using BI Publisher Standalone version 10.1.3.4. I was wondering if it is possible to use the selected layout template as a input parameter to the data model (SQL Query or Data Template).
Any help is appreciated.
Thank you in advance.Well, you could get the list of templates using Webservices but then you need develop a java application
to make use of it :), I guess this changes the original question.
regards
Jorge -
Pass list of structure as input parameter to visual composer iview
Hi
In my application, I need to create an iview which has a table view. Start point has same structure as table columns. Now I deployed this iview and assign to every user core role. Now i am using in in my GP. It is getting a list of structure as input but it is showing only one row in the table.
Anyone has idea about this.
Regards
Saurabh GargHi Saurabh,
How did you do for passing at least one row ?
Can you explain that ?
Thanks a lot
btw, Did you succeed to pass several rows ? -
Hi,
I have a scenario where my stored procedure takes 5 parameters and the users can pass NULL or some value to these parameters and based on the parameters, I need to pull data from various tables.
Is it possible to use a case statement in the join, similar the one in the below example. I'm getting error when I use the below type of statement.
select a.*
from a
case
when parameter1=1 then
inner join a on a.id = b.id
when parameter1=2 then
inner join a on a.id = c.id
end;
Please let me know, if this type of statement works, and if it works will it create any performance issues?. If the above doesn't work, could you please give me some alternate solutions?
Thanks.Here's a technique for joining A to B or C depending on the input parameters. In theory, you are joining to both tables but the execution plan includes filters to skip whichever join is not appropriate. The drawback is that you have to do outer joins, not inner ones.
CREATE TABLE A AS SELECT LEVEL ak FROM dual CONNECT BY LEVEL <= 100;
CREATE TABLE b AS SELECT ak, bk
FROM A, (SELECT LEVEL bk FROM dual CONNECT BY LEVEL <= 10);
CREATE TABLE c(ak, ck) AS SELECT ak, bk*10 FROM b;
variable p1 NUMBER;
variable p2 NUMBER;
exec :p1 := 1;
exec :p2 := 20;
SELECT /*+ gather_plan_statistics */ A.ak, nvl(b.bk, c.ck) otherk FROM A
LEFT JOIN b ON A.ak = b.ak AND :p1 IS NOT NULL AND b.bk = :p1
LEFT JOIN c ON A.ak = c.ak AND :p1 is null and :p2 IS NOT NULL and c.ck = :p2
WHERE A.ak <= 9;
SELECT * FROM TABLE(dbms_xplan.display_cursor(NULL,NULL,'IOSTATS LAST'));
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
| 0 | SELECT STATEMENT | | 1 | | 9 |00:00:00.01 | 7 |
|* 1 | HASH JOIN OUTER | | 1 | 9 | 9 |00:00:00.01 | 7 |
|* 2 | HASH JOIN OUTER | | 1 | 9 | 9 |00:00:00.01 | 7 |
|* 3 | TABLE ACCESS FULL | A | 1 | 9 | 9 |00:00:00.01 | 3 |
| 4 | VIEW | VW_DCL_5532A50F | 1 | 9 | 9 |00:00:00.01 | 4 |
|* 5 | FILTER | | 1 | | 9 |00:00:00.01 | 4 |
|* 6 | TABLE ACCESS FULL| B | 1 | 9 | 9 |00:00:00.01 | 4 |
| 7 | VIEW | VW_DCL_5532A50F | 1 | 9 | 0 |00:00:00.01 | 0 |
|* 8 | FILTER | | 1 | | 0 |00:00:00.01 | 0 |
|* 9 | TABLE ACCESS FULL | C | 0 | 9 | 0 |00:00:00.01 | 0 |
Predicate Information (identified by operation id):
1 - access("A"."AK"="ITEM_0")
2 - access("A"."AK"="ITEM_1")
3 - filter("A"."AK"<=9)
5 - filter(:P1 IS NOT NULL)
6 - filter(("B"."AK"<=9 AND "B"."BK"=:P1))
8 - filter((:P2 IS NOT NULL AND :P1 IS NULL))
9 - filter(("C"."AK"<=9 AND "C"."CK"=:P2))
You can see that table C was not really accessed: the buffer count is 0.
exec :p1 := NULL;
SELECT /*+ gather_plan_statistics */ A.ak, nvl(b.bk, c.ck) otherk FROM A
LEFT JOIN b ON A.ak = b.ak AND :p1 IS NOT NULL AND b.bk = :p1
LEFT JOIN c ON A.ak = c.ak AND :p1 is null and :p2 IS NOT NULL and c.ck = :p2
WHERE A.ak <= 9;
SELECT * FROM TABLE(dbms_xplan.display_cursor(NULL,NULL,'IOSTATS LAST'));
Now table B is not accessed.
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads |
| 0 | SELECT STATEMENT | | 1 | | 9 |00:00:00.02 | 7 | 2 |
|* 1 | HASH JOIN OUTER | | 1 | 9 | 9 |00:00:00.02 | 7 | 2 |
|* 2 | HASH JOIN OUTER | | 1 | 9 | 9 |00:00:00.01 | 3 | 0 |
|* 3 | TABLE ACCESS FULL | A | 1 | 9 | 9 |00:00:00.01 | 3 | 0 |
| 4 | VIEW | VW_DCL_5532A50F | 1 | 9 | 0 |00:00:00.01 | 0 | 0 |
|* 5 | FILTER | | 1 | | 0 |00:00:00.01 | 0 | 0 |
|* 6 | TABLE ACCESS FULL| B | 0 | 9 | 0 |00:00:00.01 | 0 | 0 |
| 7 | VIEW | VW_DCL_5532A50F | 1 | 9 | 9 |00:00:00.01 | 4 | 2 |
|* 8 | FILTER | | 1 | | 9 |00:00:00.01 | 4 | 2 |
|* 9 | TABLE ACCESS FULL | C | 1 | 9 | 9 |00:00:00.01 | 4 | 2 | -
Extracting Multiple Table Data Dynamically..Table is an Input parameter
Hi All
Can any one update the Program/design of extracting multiple table data as a list or to an excel sheet
For eg:- Mutliple Tables are entered in selection screen and upon executing the output should be to an excel sheet sequenctially according to the table names entered in the selection screen
Awaiting for your update
Regards
Shiva
Edited by: shivakumar bandari on May 29, 2009 9:35 PMHI Naimes
Thanks for youe reply
your second step says to select data from 'table' here tables are dynamic in nature I mean they are an input parameters..how can I write select on a table..
I can get the table existence from DD02L table and pass the retrieved tables to FM Get_Component_List to get the fields existing for the particular table,
But I cannot pass the dynamic table value to select query to retrieve the data..Please update me if you have anything on retrieving data from dynamically inputted value
Can I do this
Select * from <dyntable>
Any suggestions will be appreciated
thank you -
Passing a table as a procedure parameter
I'm trying to pass a table_name as a parameter but it is not working. Any idea ???
CREATE OR REPLACE PROCEDURE SIMM.populate_field
( field_name IN all_tab_columns.column_name%TYPE)
IS
v_a part_index_temp.no_dossier%TYPE;
CURSOR c_temp IS
SELECT no_dossier FROM part_index_temp FOR UPDATE;
BEGIN
OPEN c_temp;
LOOP
FETCH c_temp INTO v_a;
EXIT WHEN c_temp%NOTFOUND;
UPDATE part_index_temp a
SET
a.nouv_nom = (
SELECT field_name
FROM part_index_temp
WHERE rnum= (SELECT (1+ABS(MOD(dbms_random.random,10)))
FROM dual)
WHERE CURRENT OF c_temp;
END LOOP;
CLOSE c_temp;
END;What are you trying to accomplish?
Describe the business requirement and we can help you.
The way you are trying to pass in a Column name (not the table name) requires dynamic sql... -
Passing a table to an import parameter for a FM
Hello experts,
The goal is to update the date of a record from the database table ZSHIPM_PLAN05.
In ABAP dictionnany I define a structure ZST_SHIPM_PLAN05 based on a database table in ZSHIPM_PLAN05
Further I define a variable import in function Module(FM): IV_SHIPMENT type ZST_SHIPM_PLAN05.
But I get the following error when compiling the FM: "IV_SHIPMENT" is neither specified under "TABLES" nor defined as a internal table.
Thank you for your Help.
In the top_include I have :
TYPES: BEGIN OF tt_ZST_SHIPM_PLAN05.
INCLUDE STRUCTURE ZST_SHIPM_PLAN05.
END OF tt_ZST_SHIPM_PLAN05.
DATA: gt_outtab TYPE TABLE OF tt_ZSHIPM_PLAN05,
wa_ZSHIPM_PLAN05 LIKE LINE OF gt_outtab.
CALL FUNCTION 'Z_SHIPM_PLAN_SAVE05'
EXPORTING
iv_shipment = gt_outtab
IMPORTING
es_return = gty_bapiret2.
FUNCTION Z_SHIPM_PLAN_SAVE05.
""Local Interface:
*" IMPORTING
*" REFERENCE(IV_SHIPMENT) TYPE ZST_SHIPM_PLAN05
*" EXPORTING
*" REFERENCE(ES_RETURN) TYPE BAPIRET2
LOOP AT IV_SHIPMENT INTO wa_ZST_SHIPM_PLAN05.
settings the color
IF wa_ZST_SHIPM_PLAN05-art = 'AA02' and wa_ZST_SHIPM_PLAN05-descr = 'ci0017'.
wa_ZSHIPM_PLAN05-crea_date = sy-date.
ENDIF.
MODIFY gt_outtab FROM wa_ZST_SHIPM_PLAN05 TRANSPORTING crea_date.
ENDLOOP.
"MESSAGE 'Do you want save' type 'I'.
SET SCREEN 0.
ENDFUNCTION.Hi,
Assign IV_SHIPMENT under changing or tables Parameter because import and Export statement holds a field not structure or table.
Thanks
Arbind -
How to make joins using different tables depending on inputs? Dynamic Query
Hi,
I have this situation:
- A form with a few input messages;
- Each input corresponds to a table on a DB;
- A user can search for information filling any input, one or more;
- With the inputs filled I have to dynamic create the query, execute it and show the returned lines on a table.
How I am supposed to do that? What is the right way to make it? Can I alter a VO query on runtime including from arguments?
Any light would be apreciate!
Thanks,
MarceloYou can make View Object with Dynamic Select Statement.
See the detailed instructions in the
oracle.apps.fnd.framework.server.OAViewDef Javadoc for creating a thread-specific view instance at Run time. -
Can I pass an array as an input parameter for a stored procedure on SQL Server 2000
I am trying to pass an array to a stored procedure residing on my SQL Server 2000 database server. Is this even possible? If it is possible, what is the syntax for this?
Any help would be greatly appreciated.
ThanksI have passed arrays to and from a database using SQL and ActiveX, including to and from stored procedures, but I cannot recall the precise method used to do so. If memory serves, everything is in the form of a string. You need to do a lot of parsing and 'unparsing' to get this data into your stored procedure.
You are left with a couple of options to get your data to the stored procedure. I recommend using SQL in LabVIEW wherever possible as it saves the amount of external code calls (and believe me, calling ActiveX procedures developed by someone else in Visual Basic is NOT much fun at all...). You can either send the array and other data to the stored procedure (you will find the syntax in the SQL references in LabVIEW help under SQL), or you can send
the array to the database, and have the database then act upon the array.
I strongly recommend making routines (subVIs) to handle these operations.
Sorry I don't have the syntax, I don't have SQL installed on this machine. If you can't find the syntax in the help, please post here again.
-Mike Du'Lyea -
Passing a table as a parameter
Hi,
I want to pass a table name as a parameter to a procedure . A cursor in the procedure will be using the passed parameter , to fetch the values.
For eg.
Procedure A(X varchar2)
cursor c1 is
select *
from X;
right now i'm getting an error , X must be defined...is there any other way to do the same..?
Thanx in advance.
PreethaYou'll need to use dynamic SQL for this. Look up either the dbms_sql package or the 'execute immediate' call.
With execute immediate, you'd do something like
Procedure A(X varchar2)
IS
sqlStatement varchar2(4000);
BEGIN
sqlStatement := 'select * from " || x;
execute immediate sqlStatement;
END
Justin -
How to pass a table of data to transaction.
Hi,
I need to pass several rows of data to an internal table of a bapi from a page .
I know how to create a table in xMII transaction within itself.
But I couldn't figure how to pass several rows from a HTML page to an input parameter of a Xacute query.
Here is the scenario.
My HTML page is having a table of 3 rows and 12 columns.
I need to pass this data to an input parameter of a Xacute query.
Can some one help me in this regard.
Thanks,
Srinivas.Rick,
Thank you very much Rick. Your work around is working fine.
I am trying to enhace it a little bit this concept as below.
I created a transaction which takes string input through transaction parameters and impliments your logic of saving to a local text file and loads as XML data through XML loader and finally assigning to OUTPUT parameter of xml type.
Through this I can call this transaction where ever I need to convert string to XML.
But the problen I am facing here is whenI test this transaction through Xacute Query with some well formed XML data as input I am getting nothing in the test page.
Here are the steps I followed in the transaction:
1. Save the input text to a local file.
2. Load the same file using XML Loader.
3. Assign the xmlLoader.xmlContent -> Transaction.OUTPUT ( Assign XML) through assignment block.
4. Delete the temporary file.
Can you help in this regard.
Thanks,
Srinivas.
Thanks, -
Passing the same input parameter twise in execute sql task
Hi All, I want to insert some values to 3 different tables in sql server. Execute sql task is used to populate three tables. Here is the sql statement.
DECLARE @Dt AS DATE
SET @Dt = ?
INSERT INTO TABLE1 SELECT ?, COL2, COL3 FROM TABLE_A
INSERT INTO TABLE2 SELECT ?, COL2, COL3 FROM TABLE_B
Input parameter is mapped as follows :
Variable name : User::EffectiveDate
Direction : Input Data Type :
Date Parameter name :0
Parameter size :-1
User::EffectiveDate is datetime variable.
When the package is executed, it throws an error.
[Execute SQL Task] Error: Executing the query " " failed with the following error: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.". Possible failure reasons: Problems
with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly. I am not sure what I am doing wrong here. If anyone could point me to the right direction, I really appreciate.
Thanks
shamenTo expand on the other answers.
Your SQL command
DECLARE @Dt AS DATE
SET @Dt = ?
INSERT INTO TABLE1 SELECT ?, COL2, COL3 FROM TABLE_A
INSERT INTO TABLE2 SELECT ?, COL2, COL3 FROM TABLE_B
It using 3 input variables. I assume you didn't pass 3 variables and you want @DT to be column 1 in each. In that case you would use:
DECLARE @Dt AS DATE
SET @Dt = ?
INSERT INTO TABLE1 SELECT @Dt, COL2, COL3 FROM TABLE_A
INSERT INTO TABLE2 SELECT @Dt, COL2, COL3 FROM TABLE_B -
Passing multiple values to a single input parameter
Hi folks,
I have a Microstrategy query successfully passing input parameter to a calculation view. For example I can pass a movement type to a material movements calculation view input parameter. However if I try to pick more than one movement type the query then fails;
Generated SQL that works looks like this;
select
sum(a11.TOTALQUANTITY) WJXBFS1
from
"_SYS_BIC"."MyPackage/CA_TEST_PASS_PARAMETER"
('PLACEHOLDER' = ('$$MoveType$$', '101')
a11
When choosing more than one value in Microstrategy the SQL now fails and looks like this;
select
sum(a11.TOTALQUANTITY) WJXBFS1
from
"_SYS_BIC"."MyPackage/CA_TEST_PASS_PARAMETER"
('PLACEHOLDER' = ('$$MoveType$$', '101'),
'PLACEHOLDER' = ('$$MoveType$$', '103'))
a11
If I cut and paste the SQL and run directly in HANA studio the error is;
Could not execute 'select sum(a11.TOTALQUANTITY) WJXBFS1 from "_SYS_BIC"."MyPackage/CA_TEST_PASS_PARAMETER" ...' in 66 ms 361 µs .
SAP DBTech JDBC: [2048]: column store error: search parameter error: [2018] A received argument has an invalid value;TABLE/VIEW parameter: ( 'PLACEHOLDER'='$$MoveType$$, 103') not supported
Is it possible to pass multiple values in a single parameter? I'm using SP67 for this test.
Thanks,
-PatrickRavi, also to answer one of your questions about how this will work in Microstrategy; I just heard back from my Microstrategy developer and he is trying MSTR Freeform SQL query with syntax like this;
select (sumPAR_TEST.TOTALQUANTITY TOTALQUANTITY
from "_SYS_BIC"."MyPackage/CA_TEST_PASS_PARAMETER"
('PLACEHOLDER' =('$$MoveType$$', '[Movement Type]')) PAR_TEST
In this example [Movement Type] is the microstrategy prompt. Unfortunately though it translates like this which is missing extra single quotes around each value;
select sum(PAR_TEST.TOTALQUANTITY) TOTALQUANTITY
from "_SYS_BIC"."development.pr1959/CA_TEST_PASS_PARAMETER"
('PLACEHOLDER' = ('$$MoveType$$', ''101', '102'')) PAR_TEST
instead of what we need which is;
('PLACEHOLDER' = ('$$MoveType$$', '''101'', ''102''')) PAR_TEST
So at this point we are not sure if this will be possible or not.
-Patrick -
Hi Experts,
I am a BW consultant and new to webdynpro. Not sure how to run RSO_METADATA_REPOSITORY multiple times and by passing different parameter values each time(either taken from an a standard BW table or user provided - anything is fine) and build web pages with parameter name. Need help with direction on where to start.
Let me step back and explain my requirement:
In BW we have an object called transformation.
One way of generating documentation for transformation is highlight transformation and press F1. Then its documentation will be opened as a local web page.
I need these web pages for all transformations. This is my requirment.
I came to know that RSO_METADATA_REPOSITORY is beeing used to generate this web page.
The web link is something like below:
http://ubw05.xxx.com:8005/SAP/BW/DOC/METADATA/?page=BW_O_D&SystemID=BWPCLNT100&ClassID=TRFN&ID=0KHR6J65AIIUTCJZEC093K6XDFV909PB&objectVersion=A&sap-language=EN&sap-client=100
When i run this link seperately(not by selecting transformation and pressing F1) i need to enter login credentials to BW system.
My challenges is how do i pass login credentials and multiple transformation IDs to generate multipe web pages with each page named by transformation ID?
WHere to start? First of all is RSO_METADATA_REPOSITORY Webdynpro JAVA or webdynpro ABAP or can i use anything?
Since it is beeing opened as local webpages i assume it is webdynpro JAVa is that correct?
Thanks,
Raghuhello,
might be a problem with the version you are using.
regards,
the oracle reports team
Maybe you are looking for
-
When trying to sign in to iCloud, I always get the message, iCloud has encountered a error while trying to connect to the server. How do I get in????
-
How can I format cells in numbers to display swim times?
I need to list swim times in a numbers spread sheet. Swim times are listed as 2:17.75, meaning 2 minutes, 17 seconds and 75 hundreths of a second. Numbers automatically changes this to 2 m 17s and 750mm, or 2 h 18m 15s. I have tried to make a cust
-
Hi SAP SD Gurus Can I post a goods issue on a sales order directly? This need cam in as I wanted to do a Billing on the order (order relevant billing) If yes, kindly let me know the steps Thanks
-
I recently updated to Quicktime 7.1.2. Since that time I am unable to run Tiger Woods 2005. I cannot find a reinstaller that will allow me to go back to 6.5, and after talking to a Apple "Genius" at the local Apple Store, have been told that it is ne
-
Disk utility: verify selection- which to choose
When you open disk utility, you see the size/type of HD you have, then underneath usually "Macintosh HD." Assuming this is all you have and you haven't split your disk up, does it matter which you choose in order to repair and verify? Does each locat