Convert comma delimed values to distinct records
Hello,
i wrote the following code to get the data from comma delimited row into distinct values to another table. say for example my data into column looks like this.
long_string column data looks like this:
11,12,14,16,13,18,17
11,12,13,15,16,17,18,19,20,30
11,20,30,40,67,90,87,65,76,43,23,56,78,90,12,22,34 - which doesn't have a comma at the end of the data.
i need to convert this into distinct record for each rows data.
i used mod function...
can some one help me.
DECLARE
cursor c_1 is select LONG_STRING from TEST;
rec c_1%rowtype;
temp_VAR varchar2(100);
size_of_VAR number;
number_of_VAR number;
i number;
cur_VAR varchar2(3);
begin
open c_1;
loop
fetch c_1 into rec;
exit when c_1%notfound;
temp_VAR := rec.LONG_STRING;
size_of_VAR := length(temp_VAR);
number_of_VAR := size_of_VAR/4;
if (mod (size_of_VAR,4) = 0) then
for i in 1..number_of_VAR loop
cur_VAR:=substr(temp_VAR,1,3);
INSERT INTO TEST_ST (LONG_ST_NUM)
VALUES ( cur_VAR);
temp_VAR:= substr(temp_VAR,5);
end loop;
else
dbms_output.put_line('Rules problem for LONG_STRING: ' || rec.LONG_STRING);
end if;
end loop;
close c_1;
end;
Thanks...
Ah, I see, I took my requirement from the later posters as it wasn't clear from OP. It's not the aggregation problem that Listagg solves, but the inverse, disaggregation. I don't know a direct equivalent SQL function, but not to worry, it seems my weekend effort on another thread wasn't wasted because I can see a very simple variation on one of the solutions there that will solve this one very efficiently. It uses the model clause to iterate over the commas without any regular expression functions, XML, tree walks etc. to slow it down, and this approach should work for many similar problems. I'll add an id column so we know where the rows came from and a subid for ordering (you can drop them if you like), and an extra test record with no comma.
CREATE TABLE test_otn (id INTEGER, text VARCHAR2(4000));
INSERT INTO test_otn VALUES (1, '11,12,14,16,13,18,17');
INSERT INTO test_otn VALUES (2, '11,12,13,15,16,17,18,19,20,30');
INSERT INTO test_otn VALUES (3, '99');
INSERT INTO test_otn VALUES (4, '11,20,30,40,67,90,87,65,76,43,23,56,78,90,12,22,34');
SELECT id, numid, num
FROM test_otn
MODEL
PARTITION BY (id)
DIMENSION BY (0 i)
MEASURES (0 compos, 0 nxtpos, text, 0 numid, CAST ('' AS VARCHAR2(5)) num)
RULES
ITERATE (100) UNTIL compos[0] = 0
nxtpos[0] = Instr (text[0], ',', compos[0] + 1, 1),
num[ITERATION_NUMBER] = CASE WHEN nxtpos[0] = 0 THEN Substr (text[0], compos[0]+1)
ELSE Substr (text[0], compos[0] + 1, nxtpos[0] - compos[0] - 1) END,
numid[ITERATION_NUMBER] = ITERATION_NUMBER + 1,
compos[0] = nxtpos[0]
ORDER BY 1, 2
ID NUMID NUM
1 1 11
2 12
3 14
4 16
5 13
6 18
7 17
2 1 11
2 12
3 13
4 15
5 16
6 17
7 18
8 19
9 20
10 30
3 1 99
4 1 11
2 20
3 30
4 40
5 67
6 90
7 87
8 65
9 76
10 43
11 23
12 56
13 78
14 90
15 12
16 22
17 34
35 rows selected.
Similar Messages
-
Converting comma seperated values in rows
Hi Friends
I have a column in which values are like
col1
1,2,3How do I convert them into the following:
col2
1
2
3Thanks...darshilm wrote:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
with data as
select 1 as col1, 'a,b,c' as col2 from dual union all
select 2, 'd,e,f' from dual
select
col1,
regexp_substr(col2, '[^,+]', 1, t.column_value) as split_string
from
data d,
table(cast(multiset(select level from dual connect by level <= length(regexp_replace (d.col2, '[^,]+')) + 1) as sys.OdciNumberList)) t
12 /
COL1 SPLIT
1 a
1 b
1 c
2 d
2 e
2 f
6 rows selected.
Elapsed: 00:00:01.12
ME_XE?
ME_XE?select * from v$version;
BANNER
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
5 rows selected.
Elapsed: 00:00:01.00
ME_XE? -
Converting the comma seperator value format
i am getting the content of a table in a internal table with comma separator value format, dynamically by using dfies table i am getting the header of the table, and displaying it in the output, now my query is that the content of the data which i am getting in a itab having only one field of type string
data : begin of itab occurs 0,
data1 type string,
end of itab.
some where they were concatenating the content of the data and storing it inthe itab, now i want the content of the itab should be displayed corresponding to there header in the outputHi Santosh,
You can remove the commas from the record by using the REPLACE command as below -
LOOP AT itab.
DO.
REPLACE ',' WITH '' INTO itab-data1.
IF sy-subrc NE 0.
EXIT.
ENDIF.
ENDDO.
ENDLOOP.
Reward points if found useful...!
Cheers
Abhishek -
Value Set whose Data come from customize table with distinct record
Dear All,
I am new in Oracle EBS, currently i am creating value set whose data come from customize table which have 40 duplicate record in which distinct column return 27 record .
Table XX_ROUND_SET
Columns (Transactions_id,set_record)
Total Record (40)
Distinct Record (Set_Record --> 27)
I just want to show only 27 record in it.
Thanks
RehanHi Rehan,
PL.IGNORE MY EARLIER UPDATE AND TREAT THIS UPDATE AS YOUR SOLUTION.
Method 1
Create the VIEW based on DISTINCT values; use the VIEW for creates the VALUESET.
Method 2
Paste the QUERY in TABLE field with alias name, and give the column name (with alias name).
(in your case )
TABLE NAME : ( select distinct transactions_id, set_record from XX_ROUND_SET ) Y
VALUE : Y.transactions_id
HTH
Sanjay -
Converting Comma into Dot for Amount value
Hi All,
I need to convert the amount value in comma to dot say 1000,00 to 1000.00.Any function module is there to convert it.After converting it i need to pass this value as exporting parameter to a function module having data type as character(lenght 13).
Thnks
DebHello Deb,
Try the code below:
DATA:
V_AMT TYPE WRBTR VALUE '5000,00',
V_INT1 TYPE NUMC10,
V_DEC1 TYPE NUMC2,
V_DATA TYPE CHAR13.
V_INT1 = TRUNC( V_AMT ).
V_DEC1 = FRAC( V_AMT ).
CONCATENATE V_INT1 '.' V_DEC1 INTO V_DATA.
WRITE: V_DATA.
Hope this helps.
BR,
Suhas -
Converting xml data in to comma separated values in bpel
Is there a way to covert generic xml data to comma separated value in BPEL? i have tried using createDelimitedString but no luck.
Please guide me on this issue.
Thanks!
Shan
Edited by: 876372 on Aug 3, 2011 6:58 AMHi,
Have a luk at the below link it has many examples:
http://download.oracle.com/docs/cd/B31017_01/integrate.1013/b28994/nfb.htm -
How do u convert a numeric value to char
hi,
how do u convert a numeric value NUMBER(22) to a character value.... like a to_char() function?
i've tried the CAST function it won't work.Hi,
Use of CAST function will convert NUMBER to CHAR but it takes a lot of time if there are large number of recrods.
Syntax:
CAST(col_name AS char)
I have tried this, it worked fine for less records.
Are you getting any error while using cast function or while querying..
As far as I know it won't give error in these cases (if correct syntax used) but it will take very much time (depending on the number of records) while querying.
-Vency -
How can I get the number of distinct records that each field of a DB table has?
Hi everyone,
I would like to know how to get he number of distinct records that each field of a DB table has. When tracing a SQL statement either in ST12 or ST05, in the plan execution, if the sentence made useage of an index, then I can click in the index name and see this kind of information (no. of distinct values for each field of that index).
Can I do something like this but with the whole fields of a table?
What I have found until now is in Tx ST10; I search for whatever kind of table statistics and then use the function of "Analyze table" (which takes me to Tx DB05). In here, I can enter a table and up to 5 fields in order to get the information that I want.
Is there any other way to do this?
Regards,
David RezaHi David,
You can export the same to excel and sort as per requirement.
Sorry is that what you are looking for ?
Regards,
Deepanshu Sharma -
Select distinct records in Mapping with no Key field (all fields can vary)
Hi Experts,
Let me take an example (not the actual requirement but same scenario) to explain the problem where I need your help to get best possible way to resolve. This has to be achieved in mapping, don't have other options as its part of complex end 2 end scenario.
I have following input XML:
<Employee>
<Details>
<Id>123</Id>
<Name>ABC</Name>
<Role>Manager</Role>
<Area>Bangalore</Area>
</Details>
<Details>
<Id>123</Id>
<Name>ABC</Name>
<Role>Manager</Role>
<Area>Pune</Area>
</Details>
<Details>
<Id>123</Id>
<Name>ABC</Name>
<Role>Advisor</Role>
<Area>Bangalore</Area>
</Details>
<Details>
<Id>123</Id>
<Name>ABC</Name>
<Role>Manager</Role>
<Area>Bangalore</Area>
<Details>
<Id>143</Id>
<Name>ABC</Name>
<Role>Manager</Role>
<Area>Bangalore</Area>
</Details>
</Employee>
The output XML is:
<Employee>
<MainRec>
<Id>123</Id>
<Name>ABC</Name>
<table name = 'Roles'>
<record>
<Id>123</Id>
<Role>Manager</Role>
<Area>Bangalore</Area>
</record>
<record>
<Id>123</Id>
<Role>Manager</Role>
<Area>Pune</Area>
</record>
<record>
<Id>123</Id>
<Role>Advisor</Role>
<Area>Bangalore</Area>
</record>
</table>
</MainRec>
<MainRec>
<Id>123</Id>
<Name>ABC</Name>
<table name = 'Roles'>
<record>
<Id>143</Id>
<Role>Manager</Role>
<Area>Bangalore</Area>
</record>
</table>
</MainRec>
</Employee>
As you can see from the example above, here I want to populate only distinct records under table, but there is no key fiield to ditunguish. Any of the 3 fields (Id, Role,Area) can vary and between 2 records if all of these fields are same then its duplicate else select it. So in above XML just discard the 4th record from the source XML and populate all others. Each record has to be checked against all other records all 3 values (ID, Role, Area). Only when none of the records have exactly the same values, populate it.
Also records with different ID come under different table node. Hope my requirement is clear, if not please let me know, i will try to explain better.
I thought of creating a UDF to achieve this but not able to decide how to match it to the output message here.
Best Regards,
PratikHi,
For the main record, I think you only need to check for each unique ID, e.g
Id --> removeContext --> sort:ascending --> splitByValue:valueChanged --> collapseContext --> MainRec
For the record, however, you need to create a UDF that will filter out the duplicate values. For this, the UDF sample mentioned here contained multipleResult lists
Id --> removeContext --> concat: : --> concat: : --> UDF --> splitByValue:ValueChanged --> record
role --> removeContext --> / / \ --> Id
area --> removContext -------------> / \ --> role
\ --> area
Context type UDF
Arguments: input
Result: IdResult
Result: roleResult
Result: areaResult
Vector temp = new Vector();
for(int a=0;a<input.length;a++){
if(!temp.contains(input[a])
temp.add(input[a]);
for(int a=0;a<temp.size();a++){
String tmp = (String) temp.get(a);
/*split according to field */
IdResult.addValue(tmp.substring(0,tmp.indexOf(":")));
roleResult.addValue(tmp.substring(tmp.indexOf(":")+1,tmp.lastIndexOf(":")));
areaResult.addValue(tmp.substring(tmp.lastIndexOf(":")+1,tmp.length()));
note: Id and record will both be using the IdResult list.
Hope this helps,
Mark -
Conversion failed when converting the varchar value to data type int
Hi, I am unable to resolve this error and would like some assistance please.
The below query produces the following error message -
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'NCPR' to data type int.
Select Pc2.Assess,
Select Pc1.Title
From Pc1
Where Pc1.Assess = Pc2.Assess
) [Title]
From Pc2
However, when I run the query below I get the results shown in the image . Ie. nothing. Pc1 & Pc2 are aliases and are the same table and the assess field is an int. I found NCPR in one cell but that column (prop) is not used in the query. The table
is nearly 25k rows.
SELECT * FROM Pc1 WHERE Pc1.Assess LIKE '%NCPR%' OR ISNUMERIC(Pc1.Assess) = 0
Thank youWHERE ISNUMERIC(id) = 1 and there are obviously no 'NCPR' records in the view as per my previous post.
That is a bad assumption - SQL Server does not have to evaluate the query in the order you are expecting it to.
Take this simple example
CREATE TABLE #example
col1 VARCHAR(50) NOT NULL
INSERT INTO #example VALUES ('1'), ('2'), ('NaN')
SELECT * FROM
SELECT * FROM #example
WHERE ISNUMERIC(col1) = 1
) X
(3 row(s) affected)
col1
1
2
(2 row(s) affected)
compare to
CREATE TABLE #example
col1 VARCHAR(50) NOT NULL
INSERT INTO #example VALUES ('1'), ('2'), ('NaN')
SELECT * FROM
SELECT * FROM #example
WHERE ISNUMERIC(col1) = 1
) X
WHERE col1 = 1
(3 row(s) affected)
col1
1
Msg 245, Level 16, State 1, Line 8
Conversion failed when converting the varchar value 'NaN' to data type int. -
Convert Database NULL Values to default
Hi Friends,
I have two doubts. Any help on this is appreciated -
1. Convert Database NULL Values to default / Convert Other NULL values to default ( from File Menu - Report Option ), can any one please tell that Default Values are the values from respective Database or Crystal Reports itself?
2. Can anybody please provide the site - link, document covering details of Crystal Reports performance optimization?
Thanks in advance !!
Regards,
Ashish BHi Ashish,
Here are the few tips to enhance the performance of Crystal Reports.
1. While you are using subreports, always try to use on demand subreport when appropriate.
2. If you are creating linked subreports, try to base the link on an indexed field in the subreport.
3. If you are linking subreports with formula fields, try to keep the formula field in the main report and use a database field in the subreport.
4. Try to create proper indexed field in database, so that the data access will be faster.
5. Donu2019t use multiple data sources in reports. CRYSTAL REPORTS allows this situation, but it degrades performance.
6. Try to create SQL expression fields. Since they are evaluated in database server side, so the performance can be enhanced.
7. Always use server side processing or server side grouping. To do so, choose Database | Perform Grouping On Server from the pull down menu.
8. Donu2019t use Crystal Reports formula languageu2019s built-in functions, such as ToText, in your selection criteria.
9. Donu2019t base record selection on formula fields.
There are a number of factors that affect the processing speed of reports in Crystal Reports. For more information, search for the document u2018Tips to Improving Report Processing Speedu2019 which may improve your reportu2019s performance.
Hope it helps!!
Regards,
Alpana -
Insert three values for each record
I have a very complex Data Flow, with several joins, splits, etc.... once all of this logic is completed, I need to insert the values 2013, 2014, and 2015 for a Derived Column (called Year). Each record that comes through this data flow needs to have
a duplicated entry three times, and insert these values for the year.
Here's a simple example source:
Key Name
1 Brandon
2 Thomas
So the target should end up being:
Key Name
Year
1 Brandon
2013
2 Brandon
2014
3 Brandon
2015
4 Thomas
2013
5 Thomas
2014
6 Thomas
2015
Can anyone help?
There are only 10 types of people in the world... those who know binary, and those who don't.Hi,
Try this,
1. Load the data into your destination with 2013 as a derived column.
2. Have an another Dataflow task to load one more time. (Select the distinct record from dest table - have an id key and take distinct based on that or please check for your data nature). After selecting the distinct records, have 2014 as derived column
in that DFT.
3. Again have another DFT to load for 2015.
This is a static method since you have only 3 years to insert. If you have more years like this, do a loop to achieve this logic.
--------------------Mark as Answered or Vote as helpful if this solves your problem.------------------ -
"Select Distinct Records" Option Not Available
Hello Experts.
I am working on a new report in CR XI, and noticed that I had many duplicate records. I went to the File; Report Options; and expected to click on "Select Distinct Records", but that choice was grayed-out. What would have caused me to lose this option, and how do I fix it?
Thanks in advance for your help.Not sure if this covers it or not, but....
The Select Distinct Records command is only available for ODBC, OLE DB, and SQL native drivers; it is not available for Stored Procedures. Note also that your server may automatically sort returned values if no sort is specified in Crystal Reports. -
How to query the comma seperated values stored in Database
Hi,
I have a strange scenario, I am storing the specific data as a comma seperated value in the database. I want to query the DB with the comma seperated value as a Bind variable against the comma seperated value stored in DB.
For eg : The data stored in DB has
Row1 - > 1,2,3,4,5,6,7,8
Row2 - > 4,5,6,7,8,9,10
When I pas the Bind variable as '4,8' I should get Row1 and Row2 .
Quick help his highly appreciated.. Thanks in AdvanceOh, and if you actually wanted the data returned rather than just the row primary keys....
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1 as rw, '1,2,3,4,5,6,7,8' as txt from dual union all
2 select 2, '4,5,6,7,8,9,10' from dual union all
3 select 3, '1,6,7,9' from dual)
4 -- end of test data
5 ,r as (select '4,8' as req from dual)
6 -- end of required data
7 ,split_t as (select rw, regexp_substr(txt, '[^,]+', 1, rn) as val
8 from t, (select rownum rn from dual connect by rownum <= (select max(length(regexp_replace(t.txt, '[^,]'))+1) from t))
9 where regexp_substr(txt, '[^,]+', 1, rn) is not null
10 )
11 ,split_r as (select regexp_substr(req, '[^,]+', 1, rownum) as val
12 from r
13 connect by rownum <= length(regexp_replace(req, '[^,]'))+1
14 )
15 --
16 select distinct t.rw, t.txt
17 from split_t st join split_r sr on (st.val = sr.val)
18 join t on (t.rw = st.rw)
19* order by 1
SQL> /
RW TXT
1 1,2,3,4,5,6,7,8
2 4,5,6,7,8,9,10
SQL> -
Distinct records with conditional select formula
Post Author: nelsonchris
CA Forum: Data Connectivity and SQL
Hello,
I have a simple report pulling data from two tables. I want
only distinct records. I am selecting records based on
parameters; here is the select formula:
({?Service Name} = "*" or {selsvc.ServiceName} like
{?Service Name})and
({?Program Name} = "*" or {selsvc.Selected Service Entry
Program Name} like {?Program Name}) and
({?Agency Name} = "*" or {selsvc.Selected Service Entry
Agency Name} like {?Agency Name})
The problem comes from the fact that Crystal will add the
selsvc fields to the reports SQL select code, which has the
effect of duplicating some records that do not have the same
values for the selsvc fields. The select formula above is
the only place in the report where values from the selsvc
field are used, and as you can see they are only used when
the user has submitted a matching parameter for them. I can
not figure out how to get rid of the duplicates, please
help!
Thanks for your time,
ChrisPost Author: yangster
CA Forum: Data Connectivity and SQL
I don't follow why you are getting duplicates with your selectionare you getting duplicates without the selection criteria?if you are then they really are not duplicates and there could be issues with your joins between the 2 tables
Maybe you are looking for
-
Before my last upgrade when I opened a new tab it would open to a new window without yahoo or any other page just blank that is what I would like to happen now.
-
Airwaves Survey shows duplicate entries per WLAN SSID
Hello Cisco WLAN-experts, I have a nice problem for You: Our WLAN-networks appear twice in every WiFi-Catcher ! We are running 1131LAPs in HREAP-Mode together with a 4402WLC and use two WLANs. One is the typical "Guest WLAN", another a more secure on
-
Display hints, custom format method in VO, is there yet another way?
Did you experience the same and had a solution? Hi, I am using JDeveloper 10.1.3.4 and looking for yet another way of customizing the display of an attribute of a view object. I have two tables: BILL and AWARDS, with composite foreign key relationshi
-
Hi experts, Wht is RRI functionality? Why we need to use this jump target? Wht is the use of this and how it impacts on the reports? thanks, deen
-
HTTP Error 500.24 - Internal Server Error on Web service sdk
Hi, I have installed the mfa server on premise and tested successfully with sms and phone call. I wanted to try the Mobile app so I installed the Web service en the Mobile app according to instructions (changed the web.config with username and passwo