Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

passing array to function

Posted on 2007-11-18
3
1,347 Views
Last Modified: 2013-12-19
Hello,
I am new here and in ORACLE pl/sql.
The array dosn't passing to the body of the function.
If Ireplace the:
x InStrTab := InStrTab(v_object_name); -- Get the objects name from the select.
TO
x InStrTab := InStrTab('TBL1','TB1'); -- TBL1, TB1 are tables in my DB

The function work well.

The Function:

CREATE OR REPLACE TYPE InStrTab IS TABLE OF VARCHAR2(4000 BYTE);
/
CREATE OR REPLACE TYPE gett_arr1 AS OBJECT (
      v_OBJECT_ID     NUMBER
);
/
CREATE OR REPLACE TYPE gett_arr_TBL AS TABLE OF gett_arr1;
/

CREATE OR REPLACE FUNCTION fn_gett_arr(
      v_type IN VARCHAR2,
      v_schema_name IN VARCHAR2,
      v_object_name IN VARCHAR2
)
RETURN gett_arr_TBL AS v_ret  gett_arr_TBL;
      v_stam  VARCHAR2(250);
      v_int PLS_INTEGER;
      x InStrTab := InStrTab(v_object_name);
BEGIN
      dbms_output.put_line('The Objects var :'||v_object_name);
      SELECT
            CAST(
            multiset(
                  SELECT OBJECT_ID FROM ALL_OBJECTS WHERE OBJECT_NAME IN(SELECT TO_CHAR(column_value) FROM TABLE(CAST(x AS InStrTab)))
                  AND OWNER LIKE ''||v_schema_name||''      
            ) AS gett_arr_TBL) INTO v_ret FROM dual;
      RETURN v_ret;
      
END;
/
sho err

SELECT * FROM TABLE(fn_gett_arr('UP','SYS','''TBL1'',''TB1'''));




can anybody take a look to my function ?

Thanks guys.
SAM
0
Comment
Question by:sammeras
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
ishando earned 50 total points
ID: 20310074
you are passing in '''TBL1'',''TB1''' to the function, which is a single string

when you do x InStrTab := InStrTab(v_object_name); this is still being treated as a single string, and you x table is created with a single row with value : 'TBL1','TB1' and not as two rows with values TBL1 and TB1
0
 

Author Comment

by:sammeras
ID: 20311096
Thanks Guru.
So how can solve the problem ?
is there ways to slove this issue ?

Thanks.
SAM.
0
 
LVL 15

Expert Comment

by:ishando
ID: 20316241
you could just pass it is as an array
CREATE OR REPLACE FUNCTION fn_gett_arr
   (v_type IN VARCHAR2, v_schema_name IN VARCHAR2, v_object_name IN InStrTab)
  RETURN gett_arr_TBL 
AS 
  v_ret  gett_arr_TBL;
  v_stam  VARCHAR2(250);
  v_int PLS_INTEGER;
BEGIN
  SELECT CAST( multiset( 
    SELECT OBJECT_ID FROM ALL_OBJECTS 
    WHERE OBJECT_NAME IN ( 
      SELECT TO_CHAR(column_value) FROM TABLE(CAST(v_object_name AS InStrTab)))
    AND OWNER LIKE ''||v_schema_name||'') AS gett_arr_TBL) INTO v_ret FROM dual;
  RETURN v_ret;
END;
/
 
SELECT * FROM TABLE(fn_gett_arr('UP','SYS',InStrTab('TBL1','TB1')));

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
help on oracle query 5 53
Oracle collections 15 27
minium over 4 numeric columns for each row in oracle 2 29
DECLARATION OF CURSOR IS INCOMPLETE OR MALFORMED 5 22
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question