Solved

passing array to function

Posted on 2007-11-18
3
1,345 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
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…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

785 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