Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

passing array to function

Posted on 2007-11-18
3
Medium Priority
?
1,363 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
[X]
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
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
ishando earned 150 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
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 videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

718 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