Combining rows with comma delimited
Hi All,
I have two tables
Table A
ID Location ID
1 6
2 7
1 9
2 10
3 7
1 8
2 9
Table B
ID
1
2
3
49
8
6
I have to come up with something like this for each ID in table B, I have to write a query to get
ID Location ID
1 6, 9, 8
2 7, 10, 9
so for each Id I need to grab there Location Id and concatenate them with comma.
How can I acheive this. Is it possible to avoid loops in this case?
Anye help will be apprecaited.
with a as (
select 1 id,6 location_id from dual union all
select 2,7 from dual union all
select 1,9 from dual union all
select 2,10 from dual union all
select 3,7 from dual union all
select 1,8 from dual union all
select 2,9 from dual
b as (
select 1 id from dual union all
select 2 from dual union all
select 3 from dual union all
select 49 from dual union all
select 8 from dual union all
select 6 from dual
-- end of on-the-fly data sample
select id,
rtrim(xmlagg(xmlelement(e,location_id,',').extract('//text()') order by rn),',') location_id_list
from (
select a.id,
a.location_id,
row_number() over(partition by a.id order by a.location_id) rn
from a,
b
where b.id = a.id
group by id
ID LOCATION_ID_LIST
1 6,8,9
2 7,9,10
3 7
3 rows selected.
SQL> SY.
Similar Messages
-
How to combine rows with small numbers into single "other" row?
How can I combine rows with value 6(for example) or lower to single row representing the SUM of all this values and label OTHER, so the pie chart will have a chance to display all small values combined?
I'm using Numbers 09HI Peter,
When you write a decimal number, is the decimal separator a period ( . ) or a comma ( , )? If it's a comma, then the syntax error can be corrected by replacing the list separator in the formula, a comma in Jerry's formula, with a semi colon ( ; ):
=SUMIF(B; "<6"; B)
(Added): The two Bs appear in blue 'lozenges' in Jerry's image because that is the way cell (or column) references are displayed in Numbers when a formula has correct syntax.
Regards,
Barry
Message was edited by: Barry -
How can i get all these values in single row with comma separated?
I have a table "abxx" with column "absg" Number(3)
which is having following rows
absg
1
3
56
232
43
436
23
677
545
367
xxxxxx No of rows
How can i get all these values in single row with comma separated?
Like
output_absg
1,3,56,232,43,436,23,677,545,367,..,..,...............
Can you send the query Plz!These all will do the same
create or replace type string_agg_type as object
2 (
3 total varchar2(4000),
4
5 static function
6 ODCIAggregateInitialize(sctx IN OUT string_agg_type )
7 return number,
8
9 member function
10 ODCIAggregateIterate(self IN OUT string_agg_type ,
11 value IN varchar2 )
12 return number,
13
14 member function
15 ODCIAggregateTerminate(self IN string_agg_type,
16 returnValue OUT varchar2,
17 flags IN number)
18 return number,
19
20 member function
21 ODCIAggregateMerge(self IN OUT string_agg_type,
22 ctx2 IN string_agg_type)
23 return number
24 );
25 /
create or replace type body string_agg_type
2 is
3
4 static function ODCIAggregateInitialize(sctx IN OUT string_agg_type)
5 return number
6 is
7 begin
8 sctx := string_agg_type( null );
9 return ODCIConst.Success;
10 end;
11
12 member function ODCIAggregateIterate(self IN OUT string_agg_type,
13 value IN varchar2 )
14 return number
15 is
16 begin
17 self.total := self.total || ',' || value;
18 return ODCIConst.Success;
19 end;
20
21 member function ODCIAggregateTerminate(self IN string_agg_type,
22 returnValue OUT varchar2,
23 flags IN number)
24 return number
25 is
26 begin
27 returnValue := ltrim(self.total,',');
28 return ODCIConst.Success;
29 end;
30
31 member function ODCIAggregateMerge(self IN OUT string_agg_type,
32 ctx2 IN string_agg_type)
33 return number
34 is
35 begin
36 self.total := self.total || ctx2.total;
37 return ODCIConst.Success;
38 end;
39
40
41 end;
42 /
Type body created.
[email protected]>
[email protected]> CREATE or replace
2 FUNCTION stragg(input varchar2 )
3 RETURN varchar2
4 PARALLEL_ENABLE AGGREGATE USING string_agg_type;
5 /
CREATE OR REPLACE FUNCTION get_employees (p_deptno in emp.deptno%TYPE)
RETURN VARCHAR2
IS
l_text VARCHAR2(32767) := NULL;
BEGIN
FOR cur_rec IN (SELECT ename FROM emp WHERE deptno = p_deptno) LOOP
l_text := l_text || ',' || cur_rec.ename;
END LOOP;
RETURN LTRIM(l_text, ',');
END;
SHOW ERRORS
The function can then be incorporated into a query as follows.
COLUMN employees FORMAT A50
SELECT deptno,
get_employees(deptno) AS employees
FROM emp
GROUP by deptno;
###########################################3
SELECT SUBSTR(STR,2) FROM
(SELECT SYS_CONNECT_BY_PATH(n,',')
STR ,LENGTH(SYS_CONNECT_BY_PATH(n,',')) LN
FROM
SELECT N,rownum rn from t )
CONNECT BY rn = PRIOR RN+1
ORDER BY LN desc )
WHERE ROWNUM=1
declare
str varchar2(32767);
begin
for i in (select sal from emp) loop
str:= str || i.sal ||',' ;
end loop;
dbms_output.put_line(str);
end;
COLUMN employees FORMAT A50
SELECT e.deptno,
get_employees(e.deptno) AS employees
FROM (SELECT DISTINCT deptno
FROM emp) e;
DEPTNO EMPLOYEES
10 CLARK,KING,MILLER
20 SMITH,JONES,SCOTT,ADAMS,FORD
30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES
CREATE OR REPLACE FUNCTION concatenate_list (p_cursor IN SYS_REFCURSOR)
RETURN VARCHAR2
IS
l_return VARCHAR2(32767);
l_temp VARCHAR2(32767);
BEGIN
LOOP
FETCH p_cursor
INTO l_temp;
EXIT WHEN p_cursor%NOTFOUND;
l_return := l_return || ',' || l_temp;
END LOOP;
RETURN LTRIM(l_return, ',');
END;
COLUMN employees FORMAT A50
SELECT e1.deptno,
concatenate_list(CURSOR(SELECT e2.ename FROM emp e2 WHERE e2.deptno = e1.deptno)) employees
FROM emp e1
GROUP BY e1.deptno;
DEPTNO EMPLOYEES
10 CLARK,KING,MILLER
20 SMITH,JONES,SCOTT,ADAMS,FORD
30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES
CREATE OR REPLACE TYPE t_string_agg AS OBJECT
g_string VARCHAR2(32767),
STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg)
RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg,
value IN VARCHAR2 )
RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg,
returnValue OUT VARCHAR2,
flags IN NUMBER)
RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg,
ctx2 IN t_string_agg)
RETURN NUMBER
SHOW ERRORS
CREATE OR REPLACE TYPE BODY t_string_agg IS
STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg)
RETURN NUMBER IS
BEGIN
sctx := t_string_agg(NULL);
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg,
value IN VARCHAR2 )
RETURN NUMBER IS
BEGIN
SELF.g_string := self.g_string || ',' || value;
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg,
returnValue OUT VARCHAR2,
flags IN NUMBER)
RETURN NUMBER IS
BEGIN
returnValue := RTRIM(LTRIM(SELF.g_string, ','), ',');
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg,
ctx2 IN t_string_agg)
RETURN NUMBER IS
BEGIN
SELF.g_string := SELF.g_string || ',' || ctx2.g_string;
RETURN ODCIConst.Success;
END;
END;
SHOW ERRORS
CREATE OR REPLACE FUNCTION string_agg (p_input VARCHAR2)
RETURN VARCHAR2
PARALLEL_ENABLE AGGREGATE USING t_string_agg;
/ -
Rows to comma delimited string
Oracle version Release 10.2.0.4.0
i have the issue with the QuerySQL
SQL returning comma delimited rate_codes for each (outlet, id_service)
QuerySQL:
select
(select ltrim(MAX(SYS_CONNECT_BY_PATH(v.service,',')) KEEP (DENSE_RANK LAST ORDER BY curr),',') ratecodes
from (
select os.outlet, rsm.id_service, os.service,
row_number() OVER (PARTITION BY os.outlet, rsm.id_service ORDER BY os.service) AS curr,
row_number() OVER (PARTITION BY os.outlet, rsm.id_service ORDER BY os.service) -1 AS prev
from prcsd_outletsvcs_test os,
ratecode_service_mapping_test rsm
where os.corp = to_number(substr(:account_number,1,5))
and os.house = ltrim(substr(:account_number,6,6),'0')
and os.cust = ltrim(substr(:account_number,12,2),'0')
and os.outlet = :no_outlet
and rsm.corp = os.corp
and rsm.rate_code = os.service
and rsm.id_service = :id_service
) v
group by outlet, id_service
CONNECT BY prev = PRIOR curr
START WITH curr = 1
) ratecodes
from dual;parameter account_number 0787074919903, no_outlet=2, id_service=3 returns V1,XF
parameter account_number 0787074919903, no_outlet=2, id_service=1 returns X1
This sql works fine, but if i enclose it with another select ... dual and the QuerySQL in cursor like
( the parameters account_number, no_outlet and id_service is returned from some other tables in outer loop, here i am using outer dual to simulate my situation )
select
:no_outlet, :id_service,
cursor (
QuerySQL above
) ratecodes
from dual
) ratecodes
from dual;cursor output:
parameter account_number 0787074919903, no_outlet=2, id_service=3 returns V1,XF
parameter account_number 0787074919903, no_outlet=2, id_service=1 returns nothing
the (outlet,id_service) with only one rate_code is not returning anything
data creation:
CREATE TABLE PRCSD_OUTLETSVCS_TEST
CORP NUMBER NOT NULL,
HOUSE VARCHAR2(6 BYTE) NOT NULL,
CUST VARCHAR2(2 BYTE) NOT NULL,
OUTLET NUMBER NOT NULL,
SERVICE VARCHAR2(2 BYTE) NOT NULL
CREATE TABLE RATECODE_SERVICE_MAPPING_TEST
CORP NUMBER(5),
ID_SERVICE NUMBER(10),
RATE_CODE VARCHAR2(10 BYTE)
Insert into PRCSD_OUTLETSVCS_TEST(corp, house, cust, outlet, service)
Values(7870, '749199', '3', 1, 'X1');
Insert into PRCSD_OUTLETSVCS_TEST(corp, house, cust, outlet, service)
Values(7870, '749199', '3', 1, 'X2');
Insert into PRCSD_OUTLETSVCS_TEST(corp, house, cust, outlet, service)
Values(7870, '749199', '3', 1, 'XC');
Insert into PRCSD_OUTLETSVCS_TEST(corp, house, cust, outlet, service)
Values(7870, '749199', '3', 2, 'V1');
Insert into PRCSD_OUTLETSVCS_TEST(corp, house, cust, outlet, service)
Values(7870, '749199', '3', 2, 'X1');
Insert into PRCSD_OUTLETSVCS_TEST(corp, house, cust, outlet, service)
Values(7870, '749199', '3', 2, 'X2');
Insert into PRCSD_OUTLETSVCS_TEST(corp, house, cust, outlet, service)
Values(7870, '749199', '3', 2, 'XF');
Insert into PRCSD_OUTLETSVCS_TEST(corp, house, cust, outlet, service)
Values(7870, '749199', '3', 3, '94');
Insert into PRCSD_OUTLETSVCS_TEST(corp, house, cust, outlet, service)
Values(7870, '749199', '3', 3, 'X1');
Insert into PRCSD_OUTLETSVCS_TEST(corp, house, cust, outlet, service)
Values(7870, '749199', '3', 3, 'X2');
Insert into PRCSD_OUTLETSVCS_TEST(corp, house, cust, outlet, service)
Values(7870, '749199', '3', 3, 'XR');
Insert into RATECODE_SERVICE_MAPPING_TEST(corp, id_service, rate_code)
Values(7870, 1, 'X1');
Insert into RATECODE_SERVICE_MAPPING_TEST(corp, id_service, rate_code)
Values(7870, 2, 'XC');
Insert into RATECODE_SERVICE_MAPPING_TEST(corp, id_service, rate_code)
Values(7870, 3, 'V1');
Insert into RATECODE_SERVICE_MAPPING_TEST(corp, id_service, rate_code)
Values(7870, 3, 'XF');
Insert into RATECODE_SERVICE_MAPPING_TEST(corp, id_service, rate_code)
Values(7870, 4, '94');
Insert into RATECODE_SERVICE_MAPPING_TEST(corp, id_service, rate_code)
Values(7870, 4, 'X1');
Insert into RATECODE_SERVICE_MAPPING_TEST(corp, id_service, rate_code)
Values(7870, 4, 'XR');thanks for any helppkchan wrote:
i added
where
v.outlet = svc_rc.outlet
and v.id_service = svc_rc.id_serviceand comment out the assignment lines with :no_outlet and :id_service
You misunderstand how hierarchical query works. Look at:
select max(ltrim(SYS_CONNECT_BY_PATH(v.service,','),',')) ratecodes
from (
select os.outlet,
rsm.id_service,
os.service,
row_number() OVER (PARTITION BY os.outlet, rsm.id_service ORDER BY os.service) AS rn
from prcsd_outletsvcs_test os,
ratecode_service_mapping_test rsm
where os.corp = to_number(substr(:account_number,1,5))
and os.house = ltrim(substr(:account_number,6,6),'0')
and os.cust = ltrim(substr(:account_number,12,2),'0')
--and os.outlet = :no_outlet
and rsm.corp = os.corp
and rsm.rate_code = os.service
--and rsm.id_service = :id_service
) v
where
v.outlet = svc_rc.outlet
and v.id_service = svc_rc.id_service
CONNECT BY rn = PRIOR rn + 1
START WITH rn = 1WHERE clause in hierarchical query is applied AFTER hierarchy is build. Therefore rn=1 from EACH combination is joined to rn=2 in ALL combinations and then joined to rn=3 in ALL combinations, etc. and only then WHERE clause is applied. To create proper hierarchies you need:
where
v.outlet = svc_rc.outlet
and v.id_service = svc_rc.id_service
CONNECT BY outlet = PRIOR outlet
AND id_service = PRIOR id_service
AND rn = PRIOR rn + 1
START WITH rn = 1Now:
with svc_rc as
select distinct os.outlet, rsm.id_service
from prcsd_outletsvcs_test os,
ratecode_service_mapping_test rsm
where rsm.corp = os.corp
and rsm.rate_code = os.service
order by outlet, id_service
select
svc_rc.outlet, svc_rc.id_service,
cursor (
select (
select max(ltrim(SYS_CONNECT_BY_PATH(v.service,','),',')) ratecodes
from (
select os.outlet,
rsm.id_service,
os.service,
row_number() OVER (PARTITION BY os.outlet, rsm.id_service ORDER BY os.service) AS rn
from prcsd_outletsvcs_test os,
ratecode_service_mapping_test rsm
where os.corp = to_number(substr(:account_number,1,5))
and os.house = ltrim(substr(:account_number,6,6),'0')
and os.cust = ltrim(substr(:account_number,12,2),'0')
--and os.outlet = :no_outlet
and rsm.corp = os.corp
and rsm.rate_code = os.service
--and rsm.id_service = :id_service
) v
where
v.outlet = svc_rc.outlet
and v.id_service = svc_rc.id_service
CONNECT BY outlet = PRIOR outlet
AND id_service = PRIOR id_service
AND rn = PRIOR rn + 1
START WITH rn = 1
) ratecodes
from dual
) ratecodes
from svc_rc
OUTLET ID_SERVICE RATECODES
1 1 CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
RATECODES
1 2 CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
RATECODES
1 4 CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
RATECODES
2 1 CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
RATECODES
2 3 CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
RATECODES
V1,XF
2 4 CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
RATECODES
3 1 CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
RATECODES
3 4 CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
RATECODES
94,X1,XR
8 rows selected.
SQL> You get 94,X1,XR, but still wrong results for other rows. So get rid of that extra level of select (we already established it is the source of the bug you are experiencing):
with svc_rc as
select distinct os.outlet, rsm.id_service
from prcsd_outletsvcs_test os,
ratecode_service_mapping_test rsm
where rsm.corp = os.corp
and rsm.rate_code = os.service
order by outlet, id_service
select
svc_rc.outlet,
svc_rc.id_service,
cursor (
select ltrim(SYS_CONNECT_BY_PATH(v.service,','),',') ratecodes
from (
select os.outlet,
rsm.id_service,
os.service,
row_number() OVER (PARTITION BY os.outlet, rsm.id_service ORDER BY os.service) AS rn
from prcsd_outletsvcs_test os,
ratecode_service_mapping_test rsm
where os.corp = to_number(substr(:account_number,1,5))
and os.house = ltrim(substr(:account_number,6,6),'0')
and os.cust = ltrim(substr(:account_number,12,2),'0')
and rsm.corp = os.corp
and rsm.rate_code = os.service
) v
WHERE connect_by_isleaf = 1
AND outlet = svc_rc.outlet
AND id_service = svc_rc.id_service
START WITH rn = 1
CONNECT BY outlet = PRIOR outlet
AND id_service = PRIOR id_service
AND rn = PRIOR rn + 1
) ratecodes
from svc_rc
OUTLET ID_SERVICE RATECODES
1 1 CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
RATECODES
X1
1 2 CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
RATECODES
XC
1 4 CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
RATECODES
X1
2 1 CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
RATECODES
X1
2 3 CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
RATECODES
V1,XF
2 4 CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
RATECODES
X1
3 1 CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
RATECODES
X1
3 4 CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
RATECODES
94,X1,XR
8 rows selected.
SQL> SY. -
SQL to match a single value in a field with comma-delimited text
I have a column that can contain none, one or many recordIDs
(from another table) stored as comma-delimited text strings (i.e.,
a list). I need to retrieve all records that match a single value
within that list.
For example, if I want to match all values that equal
recordID 3, and I use ... WHERE MyColumn IN ('3') ... , I will get
all records that have EXACTLY 3 as the value of MyColumn, but not
any MyColumn records whose values include 3, if they are instances
such as "3,17" or the like.
Also using the LIKE operator -- as WHERE MyColumn LIKE '%3%'
-- will get me unwanted records with values such as 35 or 13 ...
Can I use some sort of intervening ColdFusion list processing
to output only the desired records?Normalize your database so that your data becomes
accessible. -
Form field with comma delimited value list to cfc
I have a form that passes a field to an action page with a
comma delimited value.
For instance the field name is: Program_ID
value for program_ID is: 31, 32
I am able to treat this variable as a list and check its
length, and loop over the list prior to passing it to a cfc using
the attached code:
When I try and pass the variable as a string to a cfc and
invoke a query, cf no longer recognizes my var as a list.
Therefore the code attached does not function...
Is there a specific var type that will pass through as a list
and allow me to run the code block attached?
thanks
CraigOk answered my own question.. Here is the answer for those
who are interested...
initialize var for cfc in cfinvoke statement
<cfinvokeargument name="Program_ID"
value="#Form.Program_ID#">
pass argument to cfc as a string
<cfargument name="Program_ID" type="string"
required="true">
use listqualify to parse list in cfc and set new var
<cfset selectedProgramID =
ListQualify(Program_ID,"'",",","CHAR")>
use the new var in the following statement in sql code:
((Program_ID) IN (#PreserveSingleQuotes(selectedProgramID)#))
The following code handles a form field with a single value
or a comma delimited value. -
Convert column values into a row with a delimiter
Hi Gurus,
This may be a trivial question to you. I have an internal table itab with a column called plant, internal table has 'n' records, by the end of loop, I need to convert the column into a row delimited by comma into one row (one field). This needs to be dynamic without hard-coding.
Plant
1000
2000
3000
4000
5000 ....
n....
Expected result of the field:
field1 value: 1000,2000,3000,4000,5000,...n
Let's set a limit to the field say it can hold upto 500 chars.
Thanks,
GP.Hi,
I've already tried this:
ELSEIF <fs_dms_cv>-zca_cv_attr_ind = c_multiple.
w_plant = <fs_plant_ele>-werks.
concatenate w_string w_plant
into w_string separated by c_delimiter.
IF w_end_fl = c_on.
w_tabname = <fs_dms_cv>-dbtabname.
ASSIGN (w_tabname) TO <fs_tabname>.
IF sy-subrc = 0.
ASSIGN COMPONENT <fs_dms_cv>-name_komp OF
STRUCTURE <fs_tabname> TO <fs_destination>.
IF sy-subrc = 0.
<fs_destination> = w_string.
ENDIF.
ENDIF.
There are 2 issues here: One is that after first plant there will be two commas inserted, after that it's consistent. Secondly the key word concatenate is against our code standards.
Please let me know if there is any other way of doing this.
Thanks. -
Multiple flat files with Comma delimiter and Pipe Delimiter in the sub folders.
Hi,
I have a directory C:\doc\Outcomes\Health --(This is the main path).
In the path above i have multiple subfolders like
A
B
C
D
Folder A & B have 20 flat files each which are comma separated and pipe delimiter files.
Folder C&D have 20 excel files each.
1) So, In SSIS while looping through the subfolders how do i limit to loop only excel files one time and flat files one time.
2) In folder A&B, how do i loop only Pipe delimiter files (neglecting comma saperated files). I want to loop only pipe delimiter files while using for each loop container.
ThanksBoth are txt files, but the data inside the files is saperated by ',' and '|'. ( comma and pipe)
Thats ok
If delimiters are not consistent you can use this method
http://visakhm.blogspot.in/2014/07/ssis-tips-handling-inconsistent-text.html
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
How to store a file in application server with comma as a delimiter !!
<i>Hi,
I'm Creating a file in app. server using "open dataset" statment and populating the file using Transfer stmt.
I like to store the data fields with comma delimiter, since it normally fixed length.
Please let me know Any method available.
Thank You,
Senthil</i>No problem, just concatenate all your fields into one field separated by a comma. Then transfer that field only.
data: your_dataset type localfile default '/usr/sap/TST/SYS/Data1.txt'.
data: output type string.
open dataset your_dataset for output in text mode.
loop at itab.
concatenate itab-fld1
itab-fld2
itab-fld3
into output separated by ','.
transfer output to your_dataset.
endloop.
close dataset your_dataset.
REgards,
Rich Heilman -
How to create a String with comma ?
Hi All,
I have a table with 10 records(employee name) and i have to make a string
with comma delimiter and at the end with "."
Can anybody tell me how to write a Java program for this ?
Thanks in advance.// I believe the following example gives you the answer.
class stringEG {
public static void main(String args[]) {
String emprs[] ={"1","2","3","4","5","6","7","8","9","10"};
String vempname = "";
for(int i=0; i<emprs.length; i++) {
if(i == (emprs.length-1))
vempname = vempname + emprs[i] + ".";
else
vempname = vempname + emprs[i] + ", ";
System.out.println("vempname : "+vempname);
Here dont assume that I asked you to get all the results and putting
it into the string arrays. But its a simple example to suit your requirement.
The half-way coding below answers your question, I hope.
vempname = "";
while (emprs.next()) {
if(emprs.isLast())
vempname = vempname + emprs.getString("empname") + ".";
else
vempname = vempname + emprs.getString("empname") + ", ";
// nats. -
I've created an SSIS package to import a comma delimited file (csv) with double quotes for a text qualifier ("). Some of the fields contain the delimiter inside the qualified text. An example row is:
15,"Doe, John",IS2,Alabama
In SSIS I've specified the text qualifier as ". The sample output in the connection manager looks great. The package runs perfectly from VS and when manually executed on the SSIS server itself. The problem comes when I schedule the package to run via SQL
job. At this point the package ignores the text qualifier, and in doing so pushes half of a field into the next available column. But instead of having too many columns, it concatenates the last 2 columns ignoring the delimiter. For example (pipes are fields):
15|"Doe| John"|IS2,Alabama
So the failure happens when the last half of a field is too large to fit into the next available field. In the case above _John" is 6 characters where the IS2 field is char(3). This would cause a truncation failure, which is the error I receive from the
job history.
To further test this I created a failure flow in my data flow to capture the records failing to be pulled from the source csv. Out of ~5000 records, ~1200 are failing, and every one of the failures has a comma delimiter inside the quoted text with a 'split'
length greater than the next ordinal field. The ones without the comma were inserted as normal and records where the split fit into the next ordinal column where also imported, with the last field being concatenated w/delimiter. Example records when selected
from table:
25|"Allan Percone Trucking"|GI6|California --Imported as intended
36|"Renolds| J."|UI6,Colorado --Field position offset by 1 to right - Last field overloaded
To further ensure this is the problem, I changed the csv file and flat file connection manager to pipe delimited, and sure enough every record makes it in perfectly from the SQL job execution.
I've tried comma delimited on the following set ups. Each set up failed.
SSIS Server 2008 R2 RTM
DB Server 2008 RTM
DB Compat 80
SSIS Server 2008 R2 RTM
DB Server 2008 R2 RTM
DB Compat 80
SSIS Server 2008 R2 RTM
DB Server 2008 RTM
DB Compat 100
SSIS Server 2008 R2 RTM
DB Server 2008 R2 RTM
DB Compat 100
Since a lot of our data comes in via comma delimited flat files, I really need a fix for this. If not I'll have to rebuild all my files when I import them to use pipe delimiters instaed of commas. I'd like to avoid the extra processing overhead if possible.
Also, is this a known bug? If so can someone point me to the posting of said bug?
Edit: I can't ask the vendor to change the format to pipe delimited because it comes from a federal government site.Just wanted to share my experience of this for anyone else since I wasted a morning on it today.
I encountered the same problem where I could run the package fine on my machine but when I deployed to a server and ran the package via dtexec, the " delimeter was being replaced with _x0022_ and columns all slurped up together and overflowing columns/truncating
data etc.
Since I didn't want to manually hack the DTS XML and can't install updates, the solution I used was to set an expression on the textdelimiter field of the flat file connection with the value "\"" (a double quote). That way, even if the one stored in XML
gets bodged somewhere along the way, it is overridden with the correct value at run time. The package works fine everywhere now. -
Passing data to different internal tables with different columns from a comma delimited file
Hi,
I have a program wherein we upload a comma delimited file and based on the region( we have drop down in the selection screen to pick the region). Based on the region, the data from the file is passed to internal table. For region A, we have 10 columns and for region B we have 9 columns.
There is a split statement (split at comma) used to break the data into different columns.
I need to add hard error messages if the no. of columns in the uploaded file are incorrect. For example, if the uploaded file is of type region A, then the uploaded file should be split into 10 columns. If the file contains lesser or more columns thenan error message should be added. Similar is the case with region B.
I do not want to remove the existing split statement(existing code). Is there a way I can exactly pass the data into the internal table accurately? I have gone through some posts where in they have made use of the method cl_alv_table_create=>create_dynamic_table by passing the field catalog. But I cannot use this as I have two different internal tables to be populated based on the region. Appreciate help on this.
Thanks,
PavanHi Abhishek,
I have no issues with the rows. I have a file with format like a1,b1,c1,d1,e1, the file should be uploaded and split at comma. So far its fine. After this, if the file is related to region A say Asia, then it should have 5 fields( as an example). So, all the 5 values a1,b1..e1 will be passed to 5 fields of itab1.
I also have region B( say Europe) whose file will have only 4 fields. So, file is of the form a2,b2,c2,d2. Again data is split at comma and passed to itab2.
If some one loads file related to Asia and the file has only 4 fields then the data would be incorrect. Similar is the case when someone tries to load Europe file with 5 fields related data. To avoid this, I want to validate the data uploaded. For this, I want to count the no. of fields (seperated by comma). If no. of fields is 5 then the file is related to Asia or if no. of fields is 4 then it is Europe file.
Well, the no. of commas is nothing but no. of fields - 1. If the file is of the form a1,b1..e1 then I can say like if no. of commas = 4 then it is File Asia.But I am not sure how to write a code for this.Please advise.
Thanks,
Pavan -
Error on commit: Another user has changed the row with primary key : Rec_10
i am using jdev 11g R2
i implemented a master form and two detail tables on a jspx page
added createInsert, commit and rollback buttons
actions from these buttons all are executed from a bean
for entity attributes: refresh after insert and update are marked as checked
i am using login page for authorizing the user by getting the user information from user table
and then using the userid i am applying the setVisible property on some components at bean code
when i am inserting a new row there is no problem, here i am generating the new id like 'Rec_10', using a database sequence
but when i am trying to update a current record, it is showing the error --> Error on commit: JBO-25014: Another user has changed the row with primary key oracle.jbo.Key[Rec_22 ]
on clicking the commit button and also it is not updating the record on database
Thanx in Advance
kumar
Edited by: user10922309 on Nov 18, 2009 3:25 AM
Edited by: user10922309 on Nov 18, 2009 4:28 AMHi John
thnq for your quick responce.
here are the attribute details:
Attribute Name: RecID, Type: String, Value Type: Expression, Value: 'Rec_' + (new oracle.jbo.server.SequenceImpl("Rec_SEQ_AN", object.getDBTransaction())).getSequenceNumber()
Updatable: While New and Primary Key, Queryable, Persistent, Mandatory, Refresh After: Update, Refresh After: Update and Insert are markded as checked
error details:
oracle.jbo.RowInconsistentException: JBO-25014: Another user has changed the row with primary key oracle.jbo.Key[APP_22 ].
at oracle.jbo.server.OracleSQLBuilderImpl.doEntitySelectForAltKey(OracleSQLBuilderImpl.java:1062)
at oracle.jbo.server.BaseSQLBuilderImpl.doEntitySelect(BaseSQLBuilderImpl.java:548)
at oracle.jbo.server.EntityImpl.doSelect(EntityImpl.java:7762)
at oracle.jbo.server.EntityImpl.lock(EntityImpl.java:5554)
at oracle.jbo.server.EntityImpl.beforePost(EntityImpl.java:6057)
at oracle.jbo.server.EntityImpl.postChanges(EntityImpl.java:6229)
at oracle.jbo.server.DBTransactionImpl.doPostTransactionListeners(DBTransactionImpl.java:3127)
at oracle.jbo.server.DBTransactionImpl.postChanges(DBTransactionImpl.java:2935)
at oracle.jbo.server.DBTransactionImpl.commitInternal(DBTransactionImpl.java:1991)
at oracle.jbo.server.DBTransactionImpl.commit(DBTransactionImpl.java:2233)
at oracle.adf.model.bc4j.DCJboDataControl.commitTransaction(DCJboDataControl.java:1580)
at oracle.adf.model.binding.DCDataControl.callCommitTransaction(DCDataControl.java:1404)
at oracle.jbo.uicli.binding.JUCtrlActionBinding.doIt(JUCtrlActionBinding.java:1289)
at oracle.adf.model.binding.DCDataControl.invokeOperation(DCDataControl.java:2120)
at oracle.jbo.uicli.binding.JUCtrlActionBinding.invoke(JUCtrlActionBinding.java:693)
at oracle.adf.controller.v2.lifecycle.PageLifecycleImpl.executeEvent(PageLifecycleImpl.java:394)
at oracle.adfinternal.view.faces.model.binding.FacesCtrlActionBinding._execute(FacesCtrlActionBinding.java:217)
at oracle.adfinternal.view.faces.model.binding.FacesCtrlActionBinding.execute(FacesCtrlActionBinding.java:201)
--> at Index.saveApplicationAll(Index.java:6246)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.el.parser.AstValue.invoke(AstValue.java:157)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)
at org.apache.myfaces.trinidadinternal.taglib.util.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:53)
at org.apache.myfaces.trinidad.component.UIXComponentBase.broadcastToMethodBinding(UIXComponentBase.java:1245)
at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:183)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._invokeApplication(LifecycleImpl.java:673)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:273)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:165)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:191)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:85)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:420)
at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:54)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:420)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:247)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:157)
at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.jps.wls.JpsWlsFilter$1.run(JpsWlsFilter.java:96)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)
at oracle.security.jps.wls.util.JpsWlsUtil.runJaasMode(JpsWlsUtil.java:146)
at oracle.security.jps.wls.JpsWlsFilter.doFilter(JpsWlsFilter.java:140)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:70)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.wls.DMSServletFilter.doFilter(DMSServletFilter.java:202)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3588)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2200)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2106)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1428)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
--> on click commit button Index.saveApplicationAll method will invoked.
Thats it.
Kumar
Edited by: user10922309 on Nov 18, 2009 4:32 AM -
Help with formatting multiline output into comma delimited ordered output
I have 2 tables:
SQL> desc table_1;
Name Null? Type
===================================
ID NOT NULL NUMBER
DATA1 NOT NULL VARCHAR2(440)
DATA2 NOT NULL VARCHAR2(1024)
SQL> desc table_2;
Name Null? Type
===================================
ID NOT NULL NUMBER
ATTNAME NOT NULL VARCHAR2(255)
ATTVAL VARCHAR2 (4000)
DATA1 NOT NULL CHAR(1)
DATA2 VARCHAR2 (2000)
DATA3 VARCHAR2 (255)
I need to get ATTVAL from where e.g. ATTNAME=att_name1 to ATTNAME=att_name6 from every entry (with its unique ID), and format the output into comma delimited format in e.g. this order:
att_val1,att_val3,att_val6,att_val4,att_val5,att_val6
So e.g. for entry with ID "9812" from the query below, the output I need would be:
187,179,156,134,1436,1809
What I've got so far is as follows:
SQL> SELECT id,attname,attval FROM table_2 WHERE id in (SELECT id from table_1 WHERE data2='xxx')
AND attname in ('att_name1','att_name3','att_name6','att_name4','att_name5','att_name6');
ID ATTNAME ATTVAL
===============================
1970 att_name1 123
1970 att_name2 abc
1970 att_name3 1234
1970 att_name4 def
1970 att_name5 1134
1970 att_name6 ghj
9812 att_name4 134
9812 att_name5 1436
9812 att_name3 156
9812 att_name1 187
9812 att_name2 179
9812 att_name6 1809
77 att_name1 1980
77 att_name5 1867
77 att_name3 174
77 att_name4 1345
77 att_name2 1345
77 att_name6 1345
but I don't know how to format the output comma limited in certain order. (or if this is the best way of getting the data out)
Would someone have idea how this could be done?846954 wrote:
Thanks Frank!
I got much further now :).
I've got Oracle 10g So I used the "SYS_CONNECT_BY_PATH" for my query.
Now I get the output in the format I want, however, it comes out in the order that the attributes are (which is pretty random).The values you posted are in order: 'attval1' < 'attval2' < ...
So I'm using this now(had to use "|" as separator because SYS_CONNECT_BY_PATH would not work with comma due to some of the attval having comma in them ):The values you posted don't contain and commas.
You're hiding what the problem is. It would really help if you posted actual data. It always helps if you post CREATE TABLE and INSERT statements for a little sample data, and the results you want from that data.
Assuming you really have something that has to be in a certain order, and that order is not based on anything in the values themselves, then DECODE might be a good way to do it. Storing the sort value in a table might be even better.
It looks like you were using an Oracle 9 exanple. In Oracle 10, using SYS_CONNECT_BY_PATH is simpler:
SELECT id
, LTRIM ( SYS_CONNECT_BY_PATH (attval, '|')
, '|'
) AS attvals
FROM (
SELECT id
, attval
, ROW_NUMBER () OVER ( PARTITION BY id
ORDER BY DECODE (...)
) AS curr
WHERE id IN (
SELECT id
FROM table_1
WHERE data2 = 'xxx'
AND attname IN ('attname1','attname2','attname3','attname4','attname5','attname6')
WHERE CONNECT_BY_ISLEAF = 1
START WITH curr = 1
CONNECT BY curr = PRIOR curr + 1
AND id = PRIOR id
;You don't need two almost-identical ROW_NUMBERs; one will do just fine. -
REGEXP_SUBSTR for comma delimited list with null values
Hi,
I have a column which stores a comma delimited list of values. Some of these values in the list may be null. I'm having some issues trying to extract the values using the REGEXP_SUBSTR function when null values are present. Here are two things that I've tried:
SELECT
REGEXP_SUBSTR (val, '[^,]*', 1, 1) pos1
,REGEXP_SUBSTR (val, '[^,]*', 1, 2) pos2
,REGEXP_SUBSTR (val, '[^,]*', 1, 3) pos3
,REGEXP_SUBSTR (val, '[^,]*', 1, 4) pos4
,REGEXP_SUBSTR (val, '[^,]*', 1, 5) pos5
FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);
POS P POS P P
AAA BBB
SELECT
REGEXP_SUBSTR (val, '[^,]+', 1, 1) pos1
,REGEXP_SUBSTR (val, '[^,]+', 1, 2) pos2
,REGEXP_SUBSTR (val, '[^,]+', 1, 3) pos3
,REGEXP_SUBSTR (val, '[^,]+', 1, 4) pos4
,REGEXP_SUBSTR (val, '[^,]+', 1, 5) pos5
FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);
POS POS POS POS P
AAA BBB DDD FFFAs you can see neither of the calls works correctly. Does anyone know how to modify the regular expression pattern to handle null values? I've tried various other patterns but was unable to get anyone to work for all cases.
Thanks,
Martin
http://www.ClariFit.com
http://www.TalkApex.comHi, Martin,
This does what you want:
SELECT
RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 1), ',') pos1
,RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 2), ',') pos2
,RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 3), ',') pos3
,RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 4), ',') pos4
,RTRIM (REGEXP_SUBSTR (val || ','
, '[^,]*,', 1, 5), ',') pos5
FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);The query above works in Oracle 10 or 11, but in Oracle 11, you can also do it with just REGEXP_SUBSTR, without using RTRIM:
SELECT
REGEXP_SUBSTR (val, '([^,]*),|$', 1, 1, NULL, 1) pos1
,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 2, NULL, 1) pos2
,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 3, NULL, 1) pos3
,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 4, NULL, 1) pos4
,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 5, NULL, 1) pos5
FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);The problem with your first query was that it was looking for sub-strings of 0 or more non-commas. There was such as sub-string. consisting of 3 characters, starting at position 1, so it returned 'AAA', as expected. Then there was another sub-string, of 0 characters, starting at position 4, so it returned NULL. Then there was a sub-string of 3 characters starting at position 5, so it returned 'BBB'.
The problem with your 2nd query was that it was looking for 1 or more non-commas. 'DDD' is the 3rd such sub-string.
Edited by: Frank Kulash on Feb 16, 2012 11:36 AM
Added Oracle 11 example
Maybe you are looking for
-
My iPhone 5 suddenly could not hop onto LTE anymore, after updating to IOS 6.1
My iPhone 5 suddenly could not hop onto LTE anymore, after updating to IOS 6.1. I know there is LTE coverage at my house, since before I updated it, it could hop on to LTE just fine, in the same location. My Carrier is CSL Hong Kong. Does anyone have
-
in a future version of ibook author would be very useful to provide for the creation of shared content online. Teachers can collaborate on the creation of a text. Very useful for teachers to collaborate in the network. sharing sharing sharing
-
EBusiness Suite User "Auto-provisioning" and "Self-Request" Problem
I have two types of OIM User, Staff and Contingent Staff (Role = Full-Time) Contingent (Role = Contractor / Role = Consultant) Resource Object: eBusiness Suite User Here's my RO configuration: Auto Pre-populate: true Allow Multiple: true Self Request
-
When i go to copy something it send out a blank page and say incorrect paper size how do i fix this
i have not changed any settings
-
Problem running simple servlet on tomcat 4.0
hi, i have setup tomcat4.0 on the server and i am trying to run a simple servlet but it is not working. here is what i have done: 1. setting the CATALINA_HOME variable to the directory where tomcat is installed 2. setting the classpath variable to se