Solved

passing array to function

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle report printing 2 pages in one page 2 58
Oracle DATE Column Space 11 63
SQL Query 34 81
use lov values 2 32
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

920 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