1000 Claues in IN Clause
I found that one can not choose more than 100 values in a IN Clause
SELECT col1, col2 from MY_TABLE where col3 IN (1,2,3,4,5,..............10000, 10001...)
I have to pull up a report of about 25K users and currently what I am doing is runing it for 1000 values in IN clause at a time - How can this be automated?
-Chinmay
Agree with Sundar
here you can try this:-)
SQL> ed
Wrote file afiedt.buf
1 select rownum
2 from (select rownum
3 from dual
4* connect by level<=10)
SQL> /
ROWNUM
1
2
3
4
5
6
7
8
9
10
10 rows selected.
so you can try this
SELECT col1, col2 from MY_TABLE where col3
IN (select rownum
from dual
connect by level<=1000))HTH
Similar Messages
-
Returning 250 rows with 1000 Values in "IN" Clause Oracle 10g On IBM AIX !!
Hi,
Recently we have done the OS migration of Oracle 10g Server from Windows Server to IBM AIX. Everything is fine, But today we came across one crucial bug in the code, i.e In the Select Query, though we're expecting 1000 rows with 1000 values in "IN" Clause , It's returning Only 250 rows. Where as it's returning 1000 rows in Windows Environment with 1000 values in "IN" Clause. I have browsed throgh Google for the resolution but failed to get that.
This is something like,
In Oracle 10g On windows :-
select * from emp
where dept_id in (1,2,3,...................1000);
Assuming there are the dept_id values in Emp table from 1 ... 1000, It's returning 1000 rows.
In Oracle 10g On IBM AIX ,
select * from emp
where dept_id in (1,2,3,...................1000);
Assuming there are the dept_id values in Emp table from 1 ... 1000, It's returning 250 rows. Pls help me, what could be the reason for this. and what needs to be checked to fix this.
Pls suggest !!!
Rajammmh. Did you compared the select count(*) from your_table; in the two cases.
If the result is not good and nobody has deleted rows between migration and your test, you migration need to be replayed.
Which migration did you select, Transportable database or exp/imp...?
Edited by: Dba Z on 16 août 2009 08:56 -
SQL select query having more than 1000 values in 'IN' clause of predicate.
Hi,
We are executing a select query from a table and showing it through a front end screen. When the count of values given in the 'IN' clause of predicate are exceeding 1000 , it is throwing error.
eg. select * from Employees where emp.Id. in('111',123','121','3232',........1001 Ids)
We are using Oracle version 10.2.0.
Please suggest how to tackle such issue.
Regards,
Naveen Kumar.C.
Edited by: Naveen Kumar C on Aug 30, 2008 10:01 PMUse a nested table:
create or replace type numbertype
as object
(nr number(20,10) )
create or replace type number_table
as table of numbertype
create or replace procedure tableselect
( p_numbers in number_table
, p_ref_result out sys_refcursor)
is
begin
open p_ref_result for
select *
{noformat} from employees
, (select /*+ cardinality(tab 10) */ tab.nr
from table(p_numbers) tab) tbnrs
where id = tbnrs.nr;
end;
/{noformat}
Using nested tables will reduce the amount of parsing because the sql statement uses binded variables! The cardinality hint causes Oracle to use the index on employees.id. -
How to pass more than 1000 entries in 'IN' clause, Oracle 11g
Hi All,
I know this is a very common question in Oracle discussion forum. But, Im in different zone.
I use C#, .NET and Oracle 11g. I have a situation where I will create a query statement using 'IN' clause in C# code based on my requirement and execute that statement from code itself with oracle connection object. I do not have any procedures. I must phrase my query statement and pass it on to OracleConnection object to execute it.
My code looks like this....
List<decimal> x_Ids = new List<decimal>();
I will load my IDs into x_Ids here;
string whereInClause = ........I will prepare a 'IN' clause (All IDs separated by ',')
My query would looks like this....
string query = select * from MYTABLE where X_ID in [ whereInClause with more than 1000 entries]
oraConn.ExecuteQuery(query);
I have a workaround with OR operator with 'IN' clause like below.
X_ID in [ Ids till 1000 entries] OR X_ID in [Next 1000 entries] OR X_ID in [Next 1000 entries] ....so on.....
It is working, but, I heard that this may slowdown the performance of the application. Is this really a performance hit to my application?
Can you please suggest any other workaround to overcome this situation?>
I have a workaround with OR operator with 'IN' clause like below.
X_ID in [ Ids till 1000 entries] OR X_ID in [Next 1000 entries] OR X_ID in [Next 1000 entries] ....so on.....
It is working, but, I heard that this may slowdown the performance of the application. Is this really a performance hit to my application?There should be no performance difference between a statement like
select * from myTab
where ID in (1,2,3,4,5)
OR ID in (6,7,8,10,12) and
select * from myTab
where ID in (1,2,3,4,5,6,7,8,10,12) The execution plan should be identical.
However those values might better be send as a single object (collection or table of numbers type).
I think the ODP or OO4O connectivity allows to create and such oracle object types.
Another way could be to think about how all the values are created? Did any user enter them manually? Certainly not. Then maybe you can apply the same logic to the SQL statement that created those values in your .Net application.
something like
select * from myTab
where ID in (select t2.FK_ID from otherTab t2 where t2.Col1 = 100) This approach would probably beat all others performancewise. Since you avoid the overhead of constructing the in-lists. -
Handeling more than 1000 columns in where clause
Hi,
I am using oracle 9i. We are creating a select query and adding where clause at runtime.
The no of clolumns in where clause depends on the results from another enterprise app. There may be any no of columns from 0-N. Till 1000 columns every thing works fine but when it goes beyond 1000 it gives the following error:
ERROR:
java.sql.SQLException: ORA-01795: maximum number of expressions in a list is 100
0
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.oci8.OCIDBAccess.check_error(OCIDBAccess.java:2321)
at oracle.jdbc.oci8.OCIDBAccess.parseExecuteDescribe(OCIDBAccess.java:12
55)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.jav
a:2391)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStateme
nt.java:2672)
at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:
572)
Please help.
Thanks in advance.Thanks Archana,
You are right.
I think i have not framed my question right.
Actually its problem with "IN", which i am using in where clause. It working properly till 1000 expressions like "select * from foo where fooid in (n0,n1,n2......,n1000)".
But throwing exception once the count increases to 1000 like
"select * from foo where fooid in (n0,n1,n2......,n1000,n1001,n1002)".
Thanks,
Mukesh -
More than 1000 record in IN clause
RDBMS : Oracle 10.2
OS : CentOS 5
Hi,
I have a situation where I have to compare more than 1000 ids in my IN clause.
I have used something like
slect col,col2....
from tble ......
where .....
and id in (--first 1000 ids ---)
or id in (--next 1000 ids ---);
the query is taking a lot time. If I omit second IN clause, it executes instantly .
Can you please suggest how to handle such situation ?Take your full list of 2000 ids, paste them into a program like Notepad++ (or even regular notepad) then use the replace function to replace all commas with: " from dual union all select ". Add "with a as (select " to the front and " from dual)" to the end also add an alias like aid to the first item in the list. Paste that on the front of your query and change your "in" clause to say "id in (select aid from a)"
Then instead of this:
select col,col2
from tble
where id in (1,2,3,4,5);you'll use this:
with a as (select 1 aid from dual union all
select 2 from dual union all
select 3 from dual union all
select 4 from dual union all
select 5 from dual)
select col,col2
from tble
where id in (select aid from a); -
ORA-01795:maximum number of expressions in a list is 1000
Hi,
JDev 11.1.1.5.0
I've a usecase, where i need to pass more than 1000 values for IN clause.
I found that, there is some restriction in number of values for IN clause to 1000.
I got following reference on this issue
ORA-01795:maximum number of expressions in a list is 1000. Any work around?
Conclusion:
there are two options to fix this issue
Fix 1:
You can have any number of tuples, not just 1000, in an IN-list like this:
(id, 0) IN ( (1,0), (2,0), (3,0), (5,0), (8,0), ... )
Fix 2:
Use global temporary table to populate values and then use the temp table
select * from table A1 where A1.ID in (Select ID from temp_table)
Please suggest the best option to fix our issue.
As of now, i am applying IN clause as
inClause = (1,2,3,4,5...)
criteriaRow.setAttribute("id", inClause);
I can prepare inClause as per Fix 1. But iam concern about setting attribute as (id,0)
can you suggest a way to apply as (id,0) IN (...)
Thanks in advance,
Samba.I would suggest fix nr 2. Since it's more flexible (for example when the list of items changes then you don't want to change every IN clause).
-
Difference between global temporary table and with clause
what is the difference between global temporary table and with claue .(with clause is used as table in select query)
what is the difference between global temporary table and with claue .(with clause is used as table in select query)Its big difference between the two.
Global temporary table exists for a session or a transaction while, with clause lives only for a query.
GTT is a named permanent storage table whose data flushes away on session exit or at end of a transaction while WITH clause just provides names to a reference data within a query (which is as good as having union subquery in FROM clause)
eg
SQL> with c as
2 (
3 select 1 id1, 2 id2 from dual union all
4 select 2,4 from dual union all
5 select 3,5 from dual)
6 select * from c
7 /
ID1 ID2
1 2
2 4
3 5
SQL> ed
Wrote file afiedt.buf
1 select *
2 from
3 (
4 select 1 id1, 2 id2 from dual union all
5 select 2,4 from dual union all
6* select 3,5 from dual)
7 /
ID1 ID2
1 2
2 4
3 5But GTT serves its purpose very well in case of session specific transaction and the scnearion with multiple users working on same data. -
Instead of trigger example - INSERT works but UPDATE and DELETE does not?
Below is a demostration script of what I am trying to troubleshoot. Tests are done on 10gR2;
conn system/system
drop table tt purge ;
create table tt nologging as select * from all_users ;
alter table tt add constraint pk_tt_user_id primary key (user_id) nologging ;
analyze table tt compute statistics for table for all indexed columns ;
conn hr/hr
drop database link dblink ;
create database link dblink
connect to system identified by system
using 'xe.turkcell' ;
select * from global_name@dblink ;
drop view v_tt ;
create view v_tt as select username, user_id, created from tt@dblink order by 2 ;
select count(*) from v_tt ;
COUNT(*)
13
drop sequence seq_pk_tt_user_id ;
create sequence seq_pk_tt_user_id
minvalue 1000 maxvalue 99999
increment by 1;
create synonym tt for tt@dblink ;
CREATE OR REPLACE PROCEDURE prc_update_tt(old_tt v_tt%ROWTYPE, new_tt v_tt%ROWTYPE) IS
BEGIN
IF old_tt.user_id != new_tt.user_id THEN
RETURN; -- primary key
END IF;
IF old_tt.user_id IS NOT NULL AND new_tt.user_id IS NULL THEN
DELETE FROM tt
WHERE user_id = nvl(old_tt.user_id,
-99);
RETURN;
END IF;
IF (old_tt.username IS NULL AND new_tt.username IS NOT NULL) OR
(old_tt.username IS NOT NULL AND new_tt.username != old_tt.username) THEN
UPDATE tt
SET username = new_tt.username
WHERE user_id = nvl(old_tt.user_id,
-99);
END IF;
IF (old_tt.created IS NULL AND new_tt.created IS NOT NULL) OR
(old_tt.created IS NOT NULL AND new_tt.created != old_tt.created) THEN
UPDATE tt
SET created = new_tt.created
WHERE user_id = nvl(old_tt.user_id,
-99);
END IF;
END prc_update_tt;
CREATE OR REPLACE PROCEDURE prc_insert_tt(old_tt v_tt%ROWTYPE, new_tt v_tt%ROWTYPE) IS
new_tt_user_id NUMBER;
BEGIN
SELECT seq_pk_tt_user_id.NEXTVAL INTO new_tt_user_id FROM dual;
INSERT INTO tt
(username, user_id, created)
VALUES
(new_tt.username, new_tt_user_id, new_tt.created);
END prc_insert_tt;
CREATE OR REPLACE PROCEDURE prc_delete_tt(old_tt v_tt%ROWTYPE, new_tt v_tt%ROWTYPE) IS
BEGIN
DELETE FROM tt
WHERE user_id = nvl(old_tt.user_id,
-99);
END prc_delete_tt;
CREATE OR REPLACE TRIGGER trg_iof_v_tt
INSTEAD OF UPDATE OR INSERT OR DELETE ON v_tt
FOR EACH ROW
DECLARE
new_tt v_tt%ROWTYPE;
old_tt v_tt%ROWTYPE;
BEGIN
dbms_output.put_line('INSTEAD OF TRIGGER fired');
dbms_output.put_line(':NEW.user_id ' || :NEW.user_id);
dbms_output.put_line(':OLD.user_id ' || :OLD.user_id);
dbms_output.put_line(':NEW.username ' || :NEW.username);
dbms_output.put_line(':OLD.username ' || :OLD.username);
dbms_output.put_line(':NEW.created ' || :NEW.created);
dbms_output.put_line(':OLD.created ' || :OLD.created);
new_tt.user_id := :NEW.user_id;
new_tt.username := :NEW.username;
new_tt.created := :NEW.created;
old_tt.user_id := :OLD.user_id;
old_tt.username := :OLD.username;
old_tt.created := :OLD.created;
IF inserting THEN
prc_insert_tt(old_tt,
new_tt);
ELSIF updating THEN
prc_update_tt(old_tt,
new_tt);
ELSIF deleting THEN
prc_delete_tt(old_tt,
new_tt);
END IF;
END trg_iof_v_tt;
set serveroutput on
set null ^
insert into v_tt values ('XXX', -1, sysdate) ;
INSTEAD OF TRIGGER fired
:NEW.user_id -1
:OLD.user_id
:NEW.username XXX
:OLD.username
:NEW.created 30/01/2007
:OLD.created
1 row created.
commit ;
select * from v_tt where username = 'XXX' ;
USERNAME USER_ID CREATED
XXX 1000 31/01/2007 <- seems to be no problem with insert part but
update v_tt set username = 'YYY' where user_id = 1000 ;
INSTEAD OF TRIGGER fired
:NEW.user_id
:OLD.user_id
:NEW.username YYY
:OLD.username
:NEW.created
:OLD.created
1 row updated.
commit ;
select count(*) from v_tt where username = 'YYY' ;
COUNT(*)
0 <- here is my first problem with update part, Oracle said "1 row updated."
delete from v_tt where user_id = 1000 ;
INSTEAD OF TRIGGER fired
:NEW.user_id
:OLD.user_id
:NEW.username
:OLD.username
:NEW.created
:OLD.created
1 row deleted.
commit ;
select count(*) from v_tt ;
COUNT(*)
14 <- here is my second problem with delete part, Oracle said "1 row deleted."
Any comments will be welcomed, thank you.
Message was edited by:
TongucY
changed "-1" values to "1000" in the where clause of delete and update statements.
it was a copy/paste mistake, sorry for that.What table do you process in your procedures ? You don't use DBLINK to
reference remote table in your procedures.
Seems, you have table "TT" in "HR" schema too.
Look:
SQL> create table tt nologging as select * from all_users where rownum <=3;
Table created.
SQL> select * from tt;
USERNAME USER_ID CREATED
SYS 0 25-APR-06
SYSTEM 5 25-APR-06
OUTLN 11 25-APR-06
SQL> conn scott/tiger
Connected.
SQL> create database link lk65 connect to ... identified by ... using 'nc65';
Database link created.
SQL> select * from tt@lk65;
USERNAME USER_ID CREATED
SYS 0 25-APR-06
SYSTEM 5 25-APR-06
OUTLN 11 25-APR-06
SQL> create view v_tt as select username, user_id, created from tt@lk65 order by 2;
View created.
SQL> select * from v_tt;
USERNAME USER_ID CREATED
SYS 0 25-APR-06
SYSTEM 5 25-APR-06
OUTLN 11 25-APR-06
SQL> create sequence seq_pk_tt_user_id
2 minvalue 1000 maxvalue 99999
3 increment by 1;
Sequence created.
SQL> CREATE OR REPLACE PROCEDURE prc_insert_tt(old_tt v_tt%ROWTYPE, new_tt v_tt%ROWTYPE) IS
2 new_tt_user_id NUMBER;
3 BEGIN
4 SELECT seq_pk_tt_user_id.NEXTVAL INTO new_tt_user_id FROM dual;
5 INSERT INTO tt
6 (username, user_id, created)
7 VALUES
8 (new_tt.username, new_tt_user_id, new_tt.created);
9 END prc_insert_tt;
10 /
Warning: Procedure created with compilation errors.
SQL> show error
Errors for PROCEDURE PRC_INSERT_TT:
LINE/COL ERROR
5/1 PL/SQL: SQL Statement ignored
5/13 PL/SQL: ORA-00942: table or view does not exist
SQL> edit
Wrote file afiedt.buf
1 CREATE OR REPLACE PROCEDURE prc_insert_tt(old_tt v_tt%ROWTYPE, new_tt v_tt%ROWTYPE) IS
2 new_tt_user_id NUMBER;
3 BEGIN
4 SELECT seq_pk_tt_user_id.NEXTVAL INTO new_tt_user_id FROM dual;
5 INSERT INTO tt@lk65
6 (username, user_id, created)
7 VALUES
8 (new_tt.username, new_tt_user_id, new_tt.created);
9* END prc_insert_tt;
SQL> /
Procedure created.Rgds. -
IN Clause issue in oracle -- not accepting more than 1000 expressions
update table_name set col1='Y' where col2 in ('a','b',.......1500 expressions)
Please suggest me the best method to replace the above sql statement..vasanthi b wrote:
update table_name set col1='Y' where col2 in ('a','b',.......1500 expressions)
Please suggest me the best method to replace the above sql statement..The best method is the correct method.
Normalisation.
Col2 is not normalised. That is the core problem.
And trying to hack that failure in the data model with a 1000+ expression clause... that is just plain bloody silly. -
How to put more than 1000 values into an Oracle IN clause
Is there any way to get around the Oracle 10g limitation of 1000 items in a static IN clause? I have a comma delimited list of many of IDs that I want to use in an IN clause, Most of the times values may exceed 5000. And I don't have privileges to create a temporary table, so that I can put all those in that and run at a time.
Thanks
SreenivasAlthough the trick of using OR would likely work, why don't you use a dynamic collection on the right-hand-side of the where in clause?
This thread has details Re: Binding collection to right-hand-side of WHERE num_col in (:1) clause?
Binding a VArray is not super easy, but at least with a bind value (the collection), you can have a single prepared statement, and vary just the collection you pass in. --DD -
Limitation that only 1000 records can be included in the "IN" clause
In RapidSQL we have a limitation that only 1000 records can be included in the "IN" clause - is there a way to give more than 1000 records so that it will reduce the execution time.
Why do you need to list more than 1000 individual items in the first place? That's generally not a good way to go about building a query.
You can always include a query that returns as many rows as you'd like in an IN clause, i.e.
SELECT *
FROM some_table
WHERE some_column IN (SELECT some_column FROM some_other_table)So if you throw the thousands of values you want in the IN list into a table, you could then query the table in your IN clause.
From a performance standpoint, of course, you may also want to look at the EXISTS clause depending on the relative data volumes involved.
Justin -
In clause list exceeding 1000 item
Hi All,
I have a query like:
select name,sal from emp where empno in(some_dynamicaly_build_list);
My "some_dynamicaly_build_list" contains more than 1000 items in it.
As far as i know the in caluse in a query must not have more than 1000 eliments.
Can you please help me to implement this in any other way.
Thanks
SKPhttp://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425
http://forums.oracle.com/forums/search.jspa?threadID=&q=in+list+exceeding+1000&objID=f75&dateRange=all&userID=&numResults=15&rankBy=10001 -
Using the Case clause with Model clause
Hello PL SQL gurus
I've used some scripts I've found on these forums to create a mortgage amortization statement. What I am trying to accomplish is getting the script to run a calculation or use a value within a table based upon the value in that table.
Here are the two tables:
CREATE TABLE mortgage_facts (customer VARCHAR2(20), fact VARCHAR2(20),
amount NUMBER(10,3));
INSERT INTO mortgage_facts VALUES ('Smith', 'Loan', 131828.81);
INSERT INTO mortgage_facts VALUES ('Smith', 'Annual_Interest', 3.348);
INSERT INTO mortgage_facts VALUES ('Smith', 'Payments', 72);
INSERT INTO mortgage_facts VALUES ('Smith', 'PaymentAmt', 0);
CREATE TABLE mortgage (customer VARCHAR2(20), pmt_num NUMBER(4), principalp NUMBER(10,3), interestp NUMBER(10,3), mort_balance NUMBER(10,3));
INSERT INTO mortgage VALUES ('Smith',0, 0, 0, 131828.81);
If the value within the table mortgage_facts is zero, I want the script to run a calculation to be used in a MODEL clause. If it is not zero, I would like to use that value instead of the calculation. Below is the script that I am getting an error on (I have bolded the portion in question):
SELECT c, p, to_char(round(m,2),'fm$9999999.00') principal_balance,
to_char(round(pp,2),'fm$9999999.00') towards_principal,
to_char(round(ip,2),'fm$9999999.00') towards_interest,
to_char(round(mp,2),'fm$9999999.00') monthly_payment
FROM MORTGAGE
MODEL --See 1
IGNORE NAV
REFERENCE R ON
*(SELECT customer, fact, amt --See 2*
FROM mortgage_facts
*MODEL DIMENSION BY (customer, fact) MEASURES (amount amt) --See 3*
RULES SEQUENTIAL ORDER
CASE WHEN mortgage_facts.fact = 'PaymentAmt' AND mortage_facts.amt = 0 THEN
*amt[ANY, 'PaymentAmt'] = mortgage_facts.amt*
ELSE
*amt[any, 'PaymentAmt']= (amt[CV(),'Loan']**
*Power(1+ (amt[CV(),'Annual_Interest']/100/12),*
*amt[CV(),'Payments']) **
*(amt[CV(),'Annual_Interest']/100/12)) /*
*(Power(1+(amt[CV(),'Annual_Interest']/100/12),*
*amt[CV(),'Payments']) - 1)*
END
DIMENSION BY (customer cust, fact) measures (amt)
MAIN amortization
PARTITION BY (customer c)
DIMENSION BY (0 p)
MEASURES (principalp pp, interestp ip, mort_balance m, customer mc, 0 mp )
RULES SEQUENTIAL ORDER
ITERATE(1000) UNTIL (ITERATION_NUMBER+1 =
r.amt[mc[0],'Payments'])
(ip[ITERATION_NUMBER+1] = m[CV()-1] *
r.amt[mc[0], 'Annual_Interest']/1200,
mp[ITERATION_NUMBER+1] = r.amt[mc[0], 'PaymentAmt'],
pp[ITERATION_NUMBER+1] = r.amt[mc[0], 'PaymentAmt'] - ip[CV()],
m[ITERATION_NUMBER+1] = m[CV()-1] - pp[CV()]
ORDER BY c, p
Any help is much appreciated. Thank you!!Ok, here we go, one way with iterative model:
select *
from mortgage_facts
model
partition by (Customer)
dimension by (1 p)
measures(loan, payments, INTEREST, PAYMENTAMT, INTERESTPMT, PRINCIPALPMT, balance)
rules iterate(1e9) until (iteration_number+2 >= payments[1])
(loan[iteration_number+2]=loan[1]
,payments[iteration_number+2]=cv(p)-1
,interest[iteration_number+2]=interest[1]
,paymentamt[iteration_number+2]=ROUND(
(LOAN[1] * (INTEREST[1]/12/100)*Power((1+INTEREST[1]/12/100), PAYMENTS[1])/(Power((1+INTEREST[1]/12/100),PAYMENTS[1])-1)), 2)
,INTERESTPMT[iteration_number+2]=round(balance[cv(p)-1]*interest[1]/1200, 2)
,PRINCIPALPMT[iteration_number+2]=paymentamt[cv()]-INTERESTPMT[cv()]
,balance[iteration_number+2]=balance[cv()-1]-PRINCIPALPMT[cv()]
CUSTOMER P LOAN PAYMENTS INTEREST PAYMENTAMT INTERESTPMT PRINCIPALPMT BALANCE
Smith 1 131828.81 72 3.348 0 0 0 131828.81
Smith 2 131828.81 1 3.348 2023.55 367.8 1655.75 130173.06
Smith 3 131828.81 2 3.348 2023.55 363.18 1660.37 128512.69
Smith 4 131828.81 3 3.348 2023.55 358.55 1665 126847.69
Smith 5 131828.81 4 3.348 2023.55 353.91 1669.64 125178.05
Smith 6 131828.81 5 3.348 2023.55 349.25 1674.3 123503.75
Smith 7 131828.81 6 3.348 2023.55 344.58 1678.97 121824.78
Smith 8 131828.81 7 3.348 2023.55 339.89 1683.66 120141.12
Smith 9 131828.81 8 3.348 2023.55 335.19 1688.36 118452.76
Smith 10 131828.81 9 3.348 2023.55 330.48 1693.07 116759.69
Smith 11 131828.81 10 3.348 2023.55 325.76 1697.79 115061.9
Smith 12 131828.81 11 3.348 2023.55 321.02 1702.53 113359.37
Smith 13 131828.81 12 3.348 2023.55 316.27 1707.28 111652.09
Smith 14 131828.81 13 3.348 2023.55 311.51 1712.04 109940.05
.... -
MODEL clause to process a comma separated string
Hi,
I'm trying to parse a comma separated string using SQL so that it will return the parsed values as rows;
eg. 'ABC,DEF GHI,JKL' would return 3 rows;
'ABC'
'DEF GHI'
'JKL'
I'm thinking that I could possibily use the MODEL clause combined with REGULAR expressions to solve this as I've already got a bit of SQL which does the opposite ie. turning the rows into 1 comma separated string;
select id, substr( concat_string, 2 ) as string
from (select 1 id, 'ABC' string from dual union all select 1, 'DEF GHI' from dual union all select 1, 'JKL' from dual)
model
return updated rows
partition by ( id )
dimension by ( row_number() over (partition by id order by string) as position )
measures ( cast(string as varchar2(4000) ) as concat_string )
rules
upsert
iterate( 1000 )
until ( presentv(concat_string[iteration_number+2],1,0) = 0 )
( concat_string[0] = concat_string[0] || ',' || concat_string[iteration_number+1] )
order by id;
Can anyone give me some pointers how to parse the comma separated string using regexp and create as many rows as needed using the MODEL clause?Yes, you could do it without using ITERATE, but FOR ... INCREMENT is pretty much same loop. Couple of improvements:
a) there is no need for CHAINE measure
b) there is no need for CASE in RULES clause
c) NVL can be applies on measures level
with t as (select 1 id, 'ABC,DEF GHI,JKL,DEF GHI,JKL,DEF GHI,JKL,DEF,GHI,JKL' string from dual
union all
select 2,'MNO' string from dual
union all
select 3,null string from dual
SELECT id,
string
FROM T
MODEL
RETURN UPDATED ROWS
partition by (id)
DIMENSION BY (0 POSITION)
MEASURES(
string,
NVL(LENGTH(REGEXP_REPLACE(string,'[^,]+','')),0)+1 NB_MOT
RULES
string[FOR POSITION FROM 1 TO NB_MOT[0] INCREMENT 1] = REGEXP_SUBSTR(string[0],'[^,]+',1,CV(POSITION))
SQL> with t as (select 1 id, 'ABC,DEF GHI,JKL,DEF GHI,JKL,DEF GHI,JKL,DEF,GHI,JKL' string from dual
2 union all
3 select 2,'MNO' string from dual
4 union all
5 select 3,null string from dual
6 )
7 SELECT id,
8 string
9 FROM T
10 MODEL
11 RETURN UPDATED ROWS
12 partition by (id)
13 DIMENSION BY (0 POSITION)
14 MEASURES(
15 string,
16 NVL(LENGTH(REGEXP_REPLACE(string,'[^,]+','')),0)+1 NB_MOT
17 )
18 RULES
19 (
20 string[FOR POSITION FROM 1 TO NB_MOT[0] INCREMENT 1] = REGEXP_SUBSTR(string[0],'[^,]+',1,CV(POSITION))
21 )
22 /
ID STRING
1 ABC
1 DEF GHI
1 JKL
1 DEF GHI
1 JKL
1 DEF GHI
1 JKL
1 DEF
1 GHI
1 JKL
2 MNO
ID STRING
3
12 rows selected.
SQL> SY.
Maybe you are looking for
-
Calling Java screens from Oracle Forms application
I am working with a client that has a large Oracle forms application. Since rewriting the entire application in Java is not an option at this time, the strategic direction is that any new modules that are to be created for the application are to be d
-
KE350_We ticked "do not cost" in MM03 with KE4J setting, error in billing.
Hi Experts, Most of materials need to be done costing run before creating billing in our company; therefore, we set "KE4J costing key for Type of Material (FERT) " to check if mat. already done cost estimate or not. But some of FERT mat. from old sys
-
I have updated my iphone to ISO5 yesterday, and suddenly after 1day, the message app show that I have got (-1) message, and everytime when I am trying to send a message, it will always show as sending but never get sent even if the message has alread
-
The problem is that when i try to upload a file from a client into the iFS usign both de WebUI and the WindowsUI iFS throws an exception: iFS-30002: Unable to create NewLibraryObject After that one, an other error is displayed: java.lang.exception: N
-
File could not be written - Secude
hi to all, sorry interupting you but i am new here and couldnt find the right place for my question. maybe you can help me. following error message is struggeling me quiet hard: psemanagment: file could not be written: U:\My documents\appdata\keys\%