How to pass an array to a function from a SELECT statement
Hi all. I have a problem with passing an array to a function directly from a SELECT statement.
Here is what I want. If I have a function
function AAA(arrayVar <ArrayType>) return number;
I want to be able to call this function this way
select AAA((2,3,4))
from dual
or this way
select AAA((10,12))
from dual
In other words I want to be able to pass an arbitrary number of numbers to the function. And I want this to work in a SELECT statement.
Does anyone have any ideas how to implement this? What <ArrayType> should I use?(I've read about VARRAY, nested tables in the Oracle documentation but as far as I've understood these array types are meant to be used within PL/SQL blocks).
I found only this http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:208012348074 through Google but it didn't help me.
Thank you in advance.
> What <ArrayType> should I use?
SQL data types - as 3360 showed above. You cannot use PL/SQL structures and user types in the SQL Engine.
You can however use all SQL structures and types in PL/SQL.
Arrays in SQL is created as collection type - basic o-o. The collection type (or class) serve as a container for instantiated objects or scalar type.
This is covered in detail in [url http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14260/toc.htm]
Oracle® Database Application Developer's Guide - Object-Relational Features
Similar Messages
-
How to pass table type variable into function from SQL*PLUS ?
How to pass a table type variable from sql*plus prompt into a function ?
Thanx in advance.Krishna,
Do you mean like this?SQL> DECLARE
2 TYPE t_tbl IS TABLE OF VARCHAR2(20);
3 l_sample_tbl t_tbl;
4
5 FUNCTION print_contents ( p_tbl IN t_tbl )
6 RETURN VARCHAR2
7 IS
8 l_string VARCHAR2(1000);
9 BEGIN
10 FOR i IN 1..p_tbl.COUNT LOOP
11 IF (i = 1) THEN
12 l_string := p_tbl(i);
13 ELSE
14 l_string := l_string || ', ' || p_tbl(i);
15 END IF;
16 END LOOP;
17 RETURN (l_string);
18 END print_contents;
19
20 BEGIN
21 l_sample_tbl := t_tbl();
22 l_sample_tbl.EXTEND;
23 l_sample_tbl(1) := 'one';
24 l_sample_tbl.EXTEND;
25 l_sample_tbl(2) := 'two';
26 l_sample_tbl.EXTEND;
27 l_sample_tbl(3) := 'three';
28 l_sample_tbl.EXTEND;
29 l_sample_tbl(4) := 'four';
30 l_sample_tbl.EXTEND;
31 l_sample_tbl(5) := 'five';
32 DBMS_OUTPUT.PUT_LINE(print_contents(l_sample_tbl));
33 END;
34 /
one, two, three, four, five
PL/SQL procedure successfully completed.
SQL> HTH,
T. -
Pass string array to Oracle function from Web page
Hi. I need to pass a two-dimensional array of string values to an Oracle function from an ASP.NET page. Is there an efficient way to accomplish this? I'm thinking I'll have to create a long string with special delimiters,
|12345^4.000|67890^3.670|.....
I'd parse the string on Oracle and break it into its component parts. In this example, each "record" is separated by the bar "|" and each field is separated by the up arrow "^". So each record has two fields.
Is this a good approach? Your input is much appreciated. Thanks.In PL/SQL, it is easy enough to define a record type with two attributes and declare a store procedure that takes in an array of those parameters. I know that from Java it is possible to create and pass in such an array. I would suspect that the same is possible from .Net but I am not a competent .Net developer.
Justin -
How to pass rowtype argument to a function from select statement?
Hi all!
I have function that takes mytable%rowtype as in parameter. can I pass entire row of mytable to the function from select statement? kind of
select myfunction(mytable.*) from mytable where ....
Thanks in advanceThe function can be used in a SQL statement only if it accepts SQL types and returns SQL type. %ROWTYPE being PL/SQL construct and not a SQL datatype, can not be used in this context.
http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10743/datatype.htm#i2093 -
How to pass jsp array to javascript function()
function delete(var arr[][])
out.print(arr[1][2]);
<%String [][] arra=new String[1][2];
%>
<select name="" onClick="delete(<%=arra%>)">
<option>fvfvfdfdfddffdd</option>
</select>Thanks again for constant support .Now , here comes my real problem .
I'm having a listbox . I need to find out how to get the values selected in a JSP variable .
Like I'm having names of cities in listbox .When , I click on save button , i need the names of selected cities in JSP variable or an array .
<html>
<head>
<script language="JavaScript">
function show(acl)
for(var i=0;i<4;i++)
if(acl.aclnames.options.selected)
// i don't know what to put here
alert("in show");
</script>
</head>
<body>
<form name="acl" method="post">
<select name="aclnames" multiple="true" size="3">
<option>Ahmedabad</option>
<option>Baroda</option>
<option>Surat</option>
<option>Rajkot</option>
</select>
<input type="button" name="save" value="Save" onClick="show(acl)">
</form>
</body>
</html> -
I am ussing a DLL created by another party. I have the list of the C declaretions. I have been able to write a seq that can turn the comport ON/OFF or select a different port but I have not been able to send or recieved any data. I have created an array of bytes(unsigned 8-bit integers)to send and recieved data but nothing goes out or in.
Hi Toro,
There is an example in your \Examples\AccessingArrays\PassingArrayParametersToDLL directory that illustrates exactly how to pass TestStand arrays as arguments to dll functions. The source files for the .dll are located in the same directory.
For more information on passing arrays as parameters to modules you should read the "DLL Flexible Prototype Adapter" section of Chatper 13 in the TestStand User Manual, and pay special attention to the subsection entitled "Array Parameters". You can access the User Manual from the TestStand Start Menu group, the TestStand Sequence Editor's Help menu, the \Doc directory, or online at the following link:
http://digital.ni.com/manuals.nsf/websearch/50B69DA356B8D38C86256A0000660E6B?OpenDocumen
t&node=132100_US
Jason F.
Applications Engineer
National Instruments
www.ni.com/ask -
How to pass parameter in Function by using select statement?
Hi,
I got a problem. I cant pass in parameter to function by using select statement. But it can pass in parameter by using 'hardcode' method. How can I solve this problem?
Eg,
select * from table (SplitFunction('HS750020,HS750021')) <<< this work.
but
select * from table (SplitFunction(select LOT_NO from TRACER_SEARCH_SCHEDULE where JOB_ID = '36')) <<< do not work.
Thanks for who try to help. Thanks.skymonster84 wrote:
I have try this before. But it not work.here is an example
create or replace type stringlist as table of varchar2(100)
create or replace function splitstring(pstring in varchar2) return stringlist
as
lstringlist stringlist;
begin
select regexp_substr(pstring,'[^,]+',1, level) bulk collect into lstringlist
from dual
connect by level <= length(pstring)-length(replace(pstring,','))+1;
return lstringlist;
end;
select * from table(select splitstring('xx,yy,zz') from dual)
create table t(str varchar2(100))
insert into t values('x,y,z')
insert into t values('a,b,c')
select * from table(select splitstring(str) from t where rownum<2)
/If you supply multiple values then it will fail.
select * from table(select splitstring(str) from t)
/ -
How to pass int array as an IN parameter to PLSQL Procedure
Hi,
How to pass int array in java to a stored procedure througn jdbc
and what type of data type I should declare to this IN parameter
in PLSQL Procedure.
Thanks,
SimiHi,
The best way to do what you want depends on what you want. Start by describing what you need to do. It's best to post some sample data (CREATE TABLE and INSERT statments) and what results you want from that sample data. (See the forum FAQ: https://forums.oracle.com/message/9362002)
If you have ideas about how to do the job (e.g., populating a temporary table) it can be helpful to include those, too, but distinguish clearly between WHAT you need to do and HOW you might do it.
As Bencol suggested, a SYS_REFCURSOR might be the best way to pass back the results.
Since you didn't post your table, or even describe what you wanted to do with it, I'll illustrate using scott.emp, which is probably on your system.
Say you wanted a procedure that took a DATE as an argument, and returned a some designated columns (empno, ename and hiredate in the example below) for all employees hired on or after the given DATE. You might write a procedure like this:
CREATE OR REPLACE PROCEDURE hired_since
( start_date IN DATE
, out_data OUT SYS_REFCURSOR
AS
BEGIN
OPEN out_data FOR
SELECT empno, ename, hiredate
FROM scott.emp
WHERE hiredate >= start_date;
END hired_since;
SHOW ERRORS
You can test it in SQL*Plus like this:
VARIABLE c REFCURSOR
EXEC hired_since (DATE '1982-01-01', :c);
PRINT :c
The output I got from this test was:
EMPNO ENAME HIREDATE
7788 SCOTT 19-APR-87
7876 ADAMS 23-MAY-87
7934 MILLER 23-JAN-82 -
How to pass an array to a stored procedure
create or replace package demo_pkg
as
type cityArray is table of city%rowtype index by binary_integer;
procedure city_report( p_inputs in cityArray );
end;
CREATE OR REPLACE PACKAGE BODY demo_pkg
AS
PROCEDURE city_report (p_inputs IN cityarray)
IS
BEGIN
FOR i IN 1 .. p_inputs.COUNT
LOOP
DBMS_OUTPUT.put_line ( 'citycode = '
|| p_inputs (i).city_code
|| ' CITYDESCRIPTION = '
|| p_inputs (i).city_description
INSERT INTO testing
(city_code, city_description
VALUES (p_inputs (i).city_code, p_inputs (i).city_description
commit;
END LOOP;
END;
END;
to call that procedure ia m using this
declare
my_data demo_pkg.cityArray;
begin
my_data(1).city_code := 1234;
my_data(1).CITY_DESCRIPTION := 10;
my_data(2).city_code := 4567;
my_data(2).CITY_DESCRIPTION := 20;
my_data(3).city_code := 4321;
my_data(3).CITY_DESCRIPTION := 30;
demo_pkg.city_report( my_data );
end;
but actually the procedure (demo_pkg.city_report)is called from front end(.net).how they will call this procedure in .net invironmentHi,
Your exact question has been asked before, see: http://asktom.oracle.com/pls/ask/search?p_string=How+to+pass+an+array+to+a+stored+procedure
or do a search on this forum.
And please use this tag => (yes, just the 4 characters forming the word 'code' between curly brackets)
*before* and *after* your example to maintain formatting and indentation, it's hard to read now.... -
How to pass an Array to jsp:param
Hi,
I am trying to find out how to pass an array to a jsp:param tag abnd then retrieve
the values in the next page. Please help soon. Thanks
Here's my code - Assume the books array has more than 1 value
String[] books = request.getParameterValues("book");
<jsp:include page="<%=contentPage%>" flush="true">
<jsp:param name="bookSelected" value="<%= books %>" />
</jsp:include>
The 'contentPage' takes me to the next page where I have the following to retrieve
the value of 'bookSelected'
String[] bookSelected = request.getParameter("bookSelected");
I tried accessing the array like this
if(bookSelected.equals("book1"))
but did not succeed.
I tried accessing the array in a loop but it did not work. Here's what I tried.
<jsp:include page="<%=contentPage%>" flush="true">
<%for (int i = 0; i<books.length; i++){
%>
<jsp:param name="bookSelected" value="<%= books %>" />
<% } %>
</jsp:include>
Hi
tell me how you redirect from __confirmdelete.jsp:__ to deleteServlet.java..
and post detail code of __confirmdelete.jsp:__ -
How to pass runtime parameters to MySQL Query from xMII server
Please can anybody help in How to pass runtime parameters to Orcle Query from xMII server
The answer is the same as for your other thread. The mechanism is the same regardless of the end database. The SQL syntax will be different for each database vendor depending upon which functions you are invoking. The main areas of difference between SQL Server, Oracle, DB2, etc. deal with dates (times also) and strings, but there are others as well.
Regards,
Mike -
How to pass column name as a values from one page to another
hi
i have created a report(pivot) from a table
SQL> SELECT * FROM T;
C1 C2 C3 D SEQ
A AA 2 1
A AB 3 2
A AC 2 3
B AB 5 4
B AC 6 5
SQL> SELECT C1
2 ,NVL(MAX(CASE WHEN C2='AA' THEN C3 END),'') AA
3 ,NVL(MAX(CASE WHEN C2='AB' THEN C3 END),'') AB
4 ,NVL(MAX(CASE WHEN C2='AC' THEN C3 END),'') AC
5 ,SUM(C3) FROM T GROUP BY C1;
C1 AA AB AC SUM(C3)
A 2 3 2 7
B 5 6 11
SQL>
my requirement in Apex is like this(reverse)
eg-
when i click on cell values '2' then,it should return
C1 C2 C3 D SEQ
A AA 2 1
{quote}how to pass column name as a values from one page to another
for example i have to pass 'c2' as a value to next page{quote}for report pivot you can reffer below link
Report
Amuthanks for your reply
i 'm doing what exactly you mention here .
my problem here is
i have 15 columns
i am executing a query based on the values of the column(column name) in the target page
1)here i am passing(all) the column values to the next page-but i want to pass only one column values(column name)
when i click on any cell of that column
OR
2)i can pass all column name to target page -there(in the target page) i can filter out
i think option 1 would good if you filter out the unwanted columns
Regards
Amul -
How to disable some of the automatic function from my bluetooth (jabra) while iphone does not have the capacity to set up the bluetooth property like BB?
Sorry. You're not making sense. Please re-phrase the question or post in your native language.
-
How to pass runtime parameters to Oracle Query from xMII server
Please can anybody help me that how to pass runtime parameter to Orcle Query from xMII server.
It works the same way as I described in this thread [How to pass runtime parameters to MySQL Query from xMII server]. It does not matter the datasource MII will work the same for all queries, at least for passing in parameters. How to write those queries and their datatypes will be the differences.
-
Return multiple values from a function to a SELECT statement
I hope I've provided enough information here. If not, just let me know what I'm missing.
I am creating a view that will combine information from a few tables. Most of it is fairly straightforward, but there are a couple of columns in the view that I need to get by running a function within a package. Even this is fairly straightforward (I have a function named action_date in a package called rp, for instance, which I can use to return the date I need via SELECT rp.action_date(sequence_number).
Here's the issue: I actually need to return several bits of information from the same record (not just action_date, but also action_office, action_value, etc.) - a join of the tables won't work here as I'll explain below. I can, of course, run a separate function for each statement but that is obviously inefficient. Within the confines of the view select statement however, I'm not sure how to return each of the values I need.
For instance, right now, I have:
Table1:
sequence_number NUMBER(10),
name VARCHAR(30),
Table2:
Table1_seq NUMBER(10),
action_seq NUMBER(10),
action_date DATE,
action_office VARCHAR(3),
action_value VARCHAR(60),
I can't simply join Table1 and Table2 because I have to do some processing in order to determine which of the matching returned rows I actually need to select. So the package opens a cursor and processes each row until it finds the one that I need.
The following works but is inefficient since all of the calls to the package will return columns from the same record. I just don't know how to return all the values I need into the SELECT statement.
CREATE VIEW all_this_stuff AS
SELECT sequence_number, name,
rp.action_date(sequence_number) action_date,
rp.action_office(sequence_number) action_office,
rp.action_value(sequence_number) action_value
FROM table1
Is there a way to return multiple values into my SELECT statement or am I going about this all wrong?
Any suggestions?
Thanks so much!Hi,
What you want is a Top-N Query , which you can do using the analytic ROW_NUMBER function in a sub-query, like this:
WITH got_rnum AS
SELECT action_seq, action_dt, action_office, action_type, action_value
, ROW_NUMBER () OVER ( ORDER BY action_date
, action_seq
, action_serial
) AS rnum
FROM table2
WHERE action_code = 'AB'
AND action_office LIKE 'E' -- Is this right?
SELECT action_seq, action_dt, action_office, action_type, action_value
FROM got_rnum
WHERE rnum = 1
;As written, this will return (at most) one row.
I suspect you'll really want to get one row for each group , where a group is defined by some value in a table to which you're joining.
In that case, add a PARTITION BY clause to the ROW_NUMBER function.
If you'd post a little sample data (CREATE TABLE and INSERT statements), I could show you exactly how.
Since I don't have your tables, I'll show you using tables in the scott schema.
Here's a view that has data from the scott.dept table and also from scott.emp, but only for the most senior employee in each department (that is, the employee with the earliest hiredate). If there happens to be a tie for the earliest hiredate, then the contender with the lowest empno is chosen.
CREATE OR REPLACE VIEW senior_emp
AS
WITH got_rnum AS
SELECT d.deptno
, d.dname
, e.empno
, e.ename
, e.hiredate
, ROW_NUMBER () OVER ( PARTITION BY d.deptno
ORDER BY e.hiredate
, e.empno
) AS rnum
FROM scott.dept d
JOIN scott.emp e ON d.deptno = e.deptno
SELECT deptno
, dname
, empno
, ename
, hiredate
FROM got_rnum
WHERE rnum = 1
SELECT *
FROM senior_emp
;Output:
. DEPTNO DNAME EMPNO ENAME HIREDATE
10 ACCOUNTING 7782 CLARK 09-JUN-81
20 RESEARCH 7369 SMITH 17-DEC-80
30 SALES 7499 ALLEN 20-FEB-81
By the way, one of the conditions in the query you posted was
action_office LIKE 'E'which is equivalent to
action_office = 'E'(LIKE is always equivalent to = if the string after LIKE doesn't contain any wildcards.)
Did you mean to say that, or did you mean something like this:
action_office LIKE 'E%'instead?
Maybe you are looking for
-
ADT's & Triggers in Oracle 8i and 9i
Does anyone know about Oracle 8i/9i not supporting manipulation of ADT completely(Abstract Data Types, Object Types) as being part of triggers, when the trigger is a DELETE or UPDATE trigger.
-
How to complete the incompletion sales documents
Hi, We have around 8600 old sales documents (incompletion log, TCode V.01) for which subsequent documents created for some and now we have an requirement to clear/convert all the documents to completion or not to display under this transaction. SD_SA
-
can u forward a sms message on the iphone if so how
-
Open mailbrowser with attachment
Hello together! I need to open the window to send a new mail and attach a file to it, but I need to be platform independend. Is that possible and if yes can anybody give me a link of a similar example so that I can get familar with it? Or is it bette
-
I wrote a custom access gate for j2ee application (servlet filter). When I create a resource object, I use request URI, is it correct? ObResourceRequest resource = new ObResourceRequest("http", request.getRequestURI(), request.getMethod()); The reaso