Solved

passing array to function

Posted on 2007-11-18
3
1,343 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
Comment Utility
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
Comment Utility
Thanks Guru.
So how can solve the problem ?
is there ways to slove this issue ?

Thanks.
SAM.
0
 
LVL 15

Expert Comment

by:ishando
Comment Utility
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.

Join & Write a Comment

Suggested Solutions

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…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
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.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now