Re: Oracle sql function SPLIT?
- From: "Alex" <akizub@xxxxxxxxx>
- Date: 5 May 2006 15:47:19 -0700
it's not possibleJoe:
I appreciate you spent your time answering questions.
But don't be so sure about negative answres.
I'm java programmer and definitely not DBA. So, with DBA's help I found
this:
http://asktom.oracle.com/pls/ask/f?p=4950:8:16225135796265676711::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:10720306411201
which exactly meet my needs.
I post it only for other forum's readers so they will be not confused
with previuos negative answer.
SQL> create or replace type myArray as table of number
2 /
Type created.
SQL>
SQL> create or replace function str2table( p_string in varchar2 )
return myArray
2 as
3 l_data myArray := myArray();
4 l_string long := p_string;
5 l_n number;
6 begin
7 while (l_string is not null)
8 loop
9 l_n := instr( l_string, ';' );
10 if ( l_n = 0 )
11 then
12 l_n := length(l_string)+1;
13 end if;
14 l_data.extend;
15 l_data(l_data.count) := substr( l_string, 1,
l_n-1 );
16 l_string := substr( l_string, l_n+1 );
17 end loop;
18 return l_data;
19 end;
20 /
Function created.
SQL> select * from TABLE ( str2table('12; 15; 8') );
COLUMN_VALUE
------------
12
15
8
SQL>
Quote:
in fact I want to use this function in a IN clause:
eg:
(...) where id_param in str2table('12, 15, 8');
Alex.
Joe Weinstein wrote:
Alex wrote:
I simplified task as much as possible.
See, this is quintessence of what I need.
Prepared statement is huge and this is only one piece which I still
don't have.
As well as whole application is huge and complicated. Which I like.
All what I need is this simple piece. The rest I can do by myself.
The reason why I use this groups is that I need it in Java. If I'll use
(let's say database.oracle) it would be definitely PL/SQL answer and
nobody will understand why I can't use it. And I can't since I'm not
DBA and do not have rights to work with database on their level.
Of course I can use not prepared statement but generated one like
"select a,b from table where key in ("+"1,2,3" +")"
but I really like something better like
select a,b from table where key in (select split(?) from dual)
Ok, Now that we know really what you want, it's not possible.
A '?' is not a free pass to put in any subset of SQL or any list
of things. It is only for supplying a single data value that the
DBMS can plug into a query plan it generated for the prepared
statement's SQL. The best you can/should do is to parse your
list in java and use/reuse a prepared statement like:
prepareStatement("select a,b from table where key in (?,?,?,?,?,?...)");
with as many '?'s as you want, and if your current list is shorter than
the number of '?'s, fill the remaining ones with impossible or repeat
values. If your list is bigger, collect the returns and rerun the statement
to get the rest...
Joe Weinstein at BEA Systems
.
- Follow-Ups:
- Re: Oracle sql function SPLIT?
- From: joeNOSPAM@xxxxxxx
- Re: Oracle sql function SPLIT?
- References:
- Oracle sql function SPLIT?
- From: Alex
- Re: Oracle sql function SPLIT?
- From: Bjorn Abelli
- Re: Oracle sql function SPLIT?
- From: Alex
- Re: Oracle sql function SPLIT?
- From: Bjorn Abelli
- Re: Oracle sql function SPLIT?
- From: Alex
- Re: Oracle sql function SPLIT?
- From: Joe Weinstein
- Oracle sql function SPLIT?
- Prev by Date: loadDataFromFile() method not working
- Next by Date: Character encoding problem Using Java 1.4.2 and Mysql 5.0
- Previous by thread: Re: Oracle sql function SPLIT?
- Next by thread: Re: Oracle sql function SPLIT?
- Index(es):
Relevant Pages
|
|