Multiple row values of a column (variable) into a single record
Hi,
I have the follwing table structure - ITEM_MASTER
Item Item_Parent Item_Type
------- ---------------------- -----------1000 ITEM
998272 1000 EAN
998873 1000 EAN
998874 1000 EAN
I need it as follows:
Item EAN1 EAN2 EAN3
1000 998272 998873 998874
The query I am trying to use outer join as follows but without success:
select im.item, im_ean1.item,
from ITEM_MASTER im
LEFT OUTER JOIN on ITEM_MASTER im_ean1
on (im.item = im_ean1.item_parent and im_ean1 = 'EAN' )
I am not getting the 3 EANs in a single row.
I am getting them in multiple rows.
Please suggest how should I proceed.
Thanks in advance
Suddha Satta Ray
RANK may give you multiple time same occurrence, that's why I used ROW_NUMBER, see example below :
SQL> ed
Wrote file afiedt.buf
1 select sal,
2 rank() over (order by sal) rk,
3 dense_rank() over (order by sal) drf,
4 row_number() over (order by sal) rn
5* from emp
SQL> /
SAL RK DRF RN
800 1 1 1
950 2 2 2
1100 3 3 3
1250 4 4 4
1250 4 4 5
1300 6 5 6
1500 7 6 7
1600 8 7 8
2450 9 8 9
2850 10 9 10
2975 11 10 11
3000 12 11 12
3000 12 11 13
5000 14 12 14
14 rows selected.
Elapsed: 00:00:00.00
SQL> Maybe it's your problem.
Nicolas.
Similar Messages
-
Concatenate multiple row values into single column value
Hello,
Can anyone please refresh my memory on how to concatenate multiple row values into a single column value.
In the following query, I will get multiple denial reasons per application and I would rather return all denial reasons on one line.
SELECT a.application_id, a.membership_number,
r.reason_text AS denial_reason,
a.appl_receipt_date AS application_receipt_date,
a.plan_request_1 AS application_plan_code,
a.adjudication_date AS application_denial_date
FROM application a, PLAN p, application_reason ar, reason r
WHERE a.plan_request_1 = p.plan_cd
AND a.application_id = ar.application_id
AND ar.reason_id = r.reason_id
AND a.adjudication_cd = 'D'
AND a.appl_receipt_date BETWEEN '01-jan-2006' AND '31-dec-2006'
AND p.plan_type_id = 12 and a.application_id = :appId
ORDER BY application_id
Any help is greatly appreciated.
Thanks,
-Christinefound the following
SELECT deptno,
LTRIM(MAX(SYS_CONNECT_BY_PATH(ename,','))
KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
FROM (SELECT deptno,
ename,
ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) AS curr,
ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) -1 AS prev
FROM emp)
GROUP BY deptno
CONNECT BY prev = PRIOR curr AND deptno = PRIOR deptno
START WITH curr = 1;
DEPTNO EMPLOYEES
10 CLARK,KING,MILLER
20 ADAMS,FORD,JONES,SCOTT,SMITH
30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
3 rows selected.at http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php -
Select values from table%ROWTYPE variable into a cursor
I have a stored procedure which has an OUT parameter of table1%ROWTYPE.
In future we might have to add more OUT parameters of table2%ROWTYPE etc. But at any point of time only one will have values.
So instead of having table%ROWTYPE as OUT parameter, can I send these single row ( with variable values) in a cursor, so that declaration part atleast will not change.
Is it possible to select values from table%ROWTYPE variable into a cursor.
cursorOUT IS
SELECT * FROM varREC;
where varREC is table.ROWTYPE variable.
Or which is the better solution in this situation.
Thanks.SQL> var a refcursor
SQL> declare
2 bb emp%ROWTYPE;
3 begin
4 select * into bb from emp where rownum = 1;
5 open :a for select bb.ename ename, bb.empno empno from dual;
6 end;
7 /
PL/SQL procedure successfully completed.
SQL> print a
ENAME EMPNO
SMITH 7369Rgds. -
Hide row values for certain column in GRR2
Hi Experts,
Looking for some help in report painter. I need to hide row values for certain columns in report painter. The requirement is I have 5 columns in the report, the 5 th column is the sum of col 1 to 4 and in my row i have a formula setup to sum of values for each column, what i would like to do is for column 1 thru 4 i didnt want to display the total values in row total but i wanted to dispaly value for column 5 in row total. I have been trying my best with putting formula, but couldnt succeed.
Could somebody let me know is there an way to get this addressed.
Thanks in advance
Best Regards,
gjHow was it achieved ? Did you use sections for the columns for which rows needed to be hidden?
I have a smiliar issue of hiding certain rows for few columns. -
Concatenate multiple records into one single record
Hello everyone,
Can anyone guide me how to merge multiple records into one single record
like......... I am getting the data in the file like
aaaaa/bbbbbbb/ccccccccccc/dddddddddddd/eee
ffffff/gggg/hhhhhhhhhhhhhh
/123/4567/55555/99999999/kaoabfa/eee
fffff/kkkkkkkk/llllllllllllllllllllllll
when i use gui_upload I am getting the data into the internal table in the above format.
My main intension is to split the record at / to multiple lines and dowload it into another file.
What i am planning to do is... if the line does not start with / then i want to concatenate the multiple lines into single line and then split it into multiple records. Can anyone guide me how to achieve this.Yes, it should work.
In my example
Loop at itab.
concatenate i_text itab into i_text.
endloop.
You change that loop for the loop of your internal table with the file records
So if you have this three records
'aaaa/bbb/ccc'
'/dddd/efg'
'hijk/lmn'
i_text will look like this at the end
'aaaa/bbb/ccc/dddd/efghijk/lmn'
then in this part of the code
split i_text at '/' into table itab2.
itab2 will have the records looking like this
aaaa
bbb
ccc
dddd
efghijk
lmn' -
How to insert sales text (MM02) into a single record of a Ztable.
Hi,
I'm extracting data from different data base tables and populating a Ztable which has Matnr as primary key and sales text as a field.
I have already used READ_TEXT to display the text and it is displayed in multiple records which in turn leads to duplication of Material numbers.
Now I want to avoid duplication of records (Matnr) as this being a primary record, and display the sales text of a particular material number into one single record.
Can anyone tell me how to insert sales text (MM02) transaction into one single record.
Thanks,
Govindsorry i am not enough clear about your requirement...
as i can understand i am explaining to you.
suppose your itab contains repaeating matnr.
matnr
1
1
2
2
2
3
3
like this.
data : text(200),
matnr like mara-matnr.
loop at itab.
call READ_TEXT fnmodule.
loop at tline.
concatenate text tline-tdline into text.
endloop.
matnr = itab-matnr.
at end of matnr.
itab1-matnr = matnr.
itab1-text = text.
append itab1.
clear text.
endat.
endloop.
NB change the code as per your requirement
regards
shiba dutta -
Update multiple rows based on two columns in same row
I have a 1000 rows in a table I would like to update with a unique value. This unique value is a cocatenation of two columns in teh same row.
Each row has a (i) date and a (ii) time and a (iii) date_time column. I would like to update the date_time (iii) column with a cocatenation of the (i) date and (ii) time columns.
I know how I would update a single row but how can I update multiple rows with a cocatenation of each of the two columns - i.e put a different value into the date_time column for each row?this?
update table tab_name
set date_time =date||time
where your_condition -
How do I extract values if one of the tabs can occur multiple times?
Here is my xml structure:
JobPositionPosting > dsSearch > dsId > "technis"
JobPositionPosting > dsSearch > dsLocation > dsLongitude > "-889558"
JobPositionPosting > dsSearch > dsLocation > dsLatitude > "404743"
JobPositionPosting > JobPosting > JobPositionPosting > JobPositionPostingId > "1001117543"
JobPositionPosting > JobPosting > JobSpecific > DigestedSkills > Skill > "automation"
JobPositionPosting > JobPosting > JobSpecific > DigestedSkills > Skill > "c"
JobPositionPosting > JobPosting > JobSpecific > DigestedSkills > Skill > "c#"
JobPositionPosting > JobPosting > JobSpecific > DigestedSkills > Skill > "c++"
JobPositionPosting > JobPosting > JobSpecific > DigestedSkills > Skill > "clearcase"
JobPositionPosting > JobPosting > JobSpecific > DigestedSkills > Skill > "design"
JobPositionPosting > JobPosting > JobSpecific > DigestedSkills > Skill > "development"
If I run the query below it runs just fine.
select
extractValue(object_value, '/JobPositionPosting/dsSearch/dsId') dsId ,
extractValue(object_value, '/JobPositionPosting/dsSearch/dsLocation/dsLongitude') LONGIT ,
extractValue(object_value, '/JobPositionPosting/dsSearch/dsLocation/dsLatitude') Lat
from DANB.invoicexml_tbl
But when I try to include skills it blows up with
select
extractValue(object_value, '/JobPositionPosting/dsSearch/dsId') dsId ,
extractValue(object_value, '/JobPositionPosting/dsSearch/dsLocation/dsLongitude') LONGIT ,
extractValue(object_value, '/JobPositionPosting/dsSearch/dsLocation/dsLatitude') Lat,
extractValue(object_value, '/JobPositionPosting/JobPosting/JobSpecific/DigestedSkills/Skill') skill
from DANB.invoicexml_tbl
ORA-19025: EXTRACTVALUE returns value of only one node
Looks like having skil there multiple times is a problem.You need to use XMLTable (or table(xmlsequence(extract(...))) if your version doesn't have XMLTable) to parse out the repeating elements into multiple rows.
Here is a sample based off what you posted
WITH base AS
(SELECT XMLTYPE('<?xml version="1.0" encoding="UTF-8"?>
<JobPositionPosting>
<dsSearch>
<dsId>technis</dsId>
<dsLocation>
<dsLongitude>-889558</dsLongitude>
<dsLatitude>404743</dsLatitude>
</dsLocation>
</dsSearch>
<JobPosting>
<JobPositionPosting>
<JobPositionPostingId>1001117543</JobPositionPostingId>
</JobPositionPosting>
<JobSpecific>
<DigestedSkills>
<Skill>automation</Skill>
<Skill>c</Skill>
<Skill>c#</Skill>
<Skill>c++</Skill>
<Skill>clearcase</Skill>
<Skill>design</Skill>
<Skill>development</Skill>
</DigestedSkills>
</JobSpecific>
</JobPosting>
</JobPositionPosting>') xmlcol
FROM dual
SELECT m.dsid, x.*
FROM base,
xmltable('/JobPositionPosting'
PASSING base.xmlcol
COLUMNS
dsId VARCHAR2(20) PATH '/JobPositionPosting/dsSearch/dsId',
skills XMLTYPE PATH '/JobPositionPosting/JobPosting/JobSpecific/DigestedSkills/Skill') m,
xmltable('/Skill'
PASSING m.skills
COLUMNS
ind_skill VARCHAR2(20) PATH '/Skill') xproduces
DSID IND_SKILL
technis automation
technis c
technis c#
technis c++
technis clearcase
technis design
technis development -
Multiple row value coming in a single row(nclob)
hi ,
i have a requirement where i have to work on a column on datatype nclob, now here the value of 2 rows coming into a single column. like this:
select distinct extractvalue(xmltype(details),'/Anything/invoiceNumber') as invoices ,
actinguserid as user_id ,createdt
from bchistevent where bucket = 201301
and upper(type) = 'COM.AVOLENT.PRESENTATION.EVENT.INVOICEDOWNLOADEVENT'
--and bchistevent.bucket = to_char (add_months (sysdate, -1),'YYYYMM')
395452969-000-20130103 1.46388193452398E37 1/8/2013 3:05:42 AM
300000590-000-20090723 1.46388193452398E37 1/11/2013 8:11:45 AM
300000590-000-20090723 1.46388193452398E37 1/11/2013 8:12:50 AM
395453127-000-20130103 1.46388193452398E37 1/14/2013 4:44:26 AM
*300084670-000-20120906, 300084671-000-20120906* 1.46388193452398E37 1/7/2013 12:45:19 AM
395452626-000-20130103 1.46388193452398E37 1/8/2013 3:03:57 AM
300084679-000-20120906 1.46388193452398E37 1/11/2013 8:10:47 AM
300000728-000-20090731 1.46388193452398E37 1/11/2013 8:19:19 AM
300084679-000-20120906 1.46388193452398E37 1/14/2013 12:31:48 AM
300000590-000-20090723 1.46388193452398E37 1/14/2013 4:13:19 AM
395452718-000-20130103 1.46388193452398E37 1/8/2013 7:10:19 AM
300084679-000-20120906 1.46388193452398E37 1/23/2013 6:54:11 AM
300084679-000-20120906 1.46388193452398E37 1/22/2013 3:11:54 AM
300000590-000-20090723 1.46388193452398E37 1/11/2013 8:14:02 AM
395453127-000-20130103 1.46388193452398E37 1/14/2013 4:33:12 AM
300084679-000-20120906 1.46388193452398E37 1/22/2013 3:03:36 AM
300084679-000-20120906 1.46388193452398E37 1/14/2013 12:34:13 AM
395452997-000-20130103 1.46388193452398E37 1/7/2013 3:31:38 AM
395452391-000-20121027 1.46388193452398E37 1/3/2013 4:40:05 AM
and the value of bold highlighted row is coming in a single row, plzz help how to break this in 2 rows??
Edited by: user1175303 on Mar 13, 2013 5:43 AMuser1175303 wrote:
the column value which is in question is <Anything><invoiceNumber>300084670-000-20120906, 300084671-000-20120906</invoiceNumber></Anything> here i am getting 2 values in a single column and because of this i am unable to get desired output...So you have XML issue but trying to resolve it in Oracle??? Why <invoiceNumber> holds two invoice numbers? Anyway:
with t as (
select distinct extractvalue(xmltype(details),'/Anything/invoiceNumber') as invoices,
actinguserid as user_id,
createdt
from bchistevent
where bucket = 201301
and upper(type) = 'COM.AVOLENT.PRESENTATION.EVENT.INVOICEDOWNLOADEVENT'
select regexp_substr(invoices,'[^,]+',1,column_value) invoices,
user_id,
createdt
from t,
table(
cast(
multiset(
select level
from dual
connect by level <= length(regexp_replace(invoices,'[^,]')) + 1
as sys.OdciNumberList
/SY. -
How to get rows values in a column only ?
How to get all returned values in rows in a column.
e.g., a query gives output as :
123
234
233
12121
all in different rows. But i want the result like this:
123,234,233,12121.All in a single row and a single column .
How is this possible ?prakash wrote:
hi ,
Use the following example
CREATE or replace FUNCTION fn_return_row
RETURN VARCHAR2
IS
v_row VARCHAR2 (32767);
BEGIN
FOR curr_row IN (SELECT ename
FROM emp11)
LOOP
v_row := v_row ||','|| curr_row.ename;
END LOOP;
RETURN v_row;
EXCEPTION
WHEN OTHERS
THEN
RETURN NULL;
END fn_return_row;
select fn_return_row from dual ;Thanks,
P PrakashThere's no need to use PL/SQL when SQL provides adequate functionality to do it.
The title of the thread is misleading as turning rows into columns is called pivoting, but the description of the issue wanting to join all the rows together into a single column, is actually called string aggregation.
As already demonstrated it can be done several ways.
1. with XML functionality
2. using the SYS_CONNECT_BY_PATH method
and if you have 11gR2, there's...
3. the new LISTAGG analytical function.
There is also an undocumented WMSYS.WM_CONCAT function, though this isn't as flexible as other methods in that you can't control the order of the aggregated data so easily, and using such undocumented functions in production code is dangerous, as the functionality could change in future versions of Oracle, as well as it's use making your code such that Oracle will not provide support if the code with issue is using it. -
I am wanting to exactly match two ID numbers from two worksheets within the one work book. ID numbers are non linear. Once exactly matched I wish to retrieve a corresponding row value from worksheet two and have it appear in worksheet one against the correct ID number. I have been looking at IF, VLOOKUP, and MATCH functions and suspect that what I want to do requires a combination of two or more. Any help will be greatly appreciated.
regards VaughanhVaughan,
Data A:D is all cells start at column A thru column D.
There is built-in help using the menu item "View > Show Function Browser" in the search field (top right) you can enter vlookup and you will see the detailed description.
From this we see:
VLOOKUP
(search-for, columns-range, return-column, close-match)
search-for: The value to find. search-value can contain any value type.
columns-range: A range of cells. range is a reference to a single range of cells, which may contain values of any type.
return-column: A number that specifies the relative column number of the cell from which to return the value. return-column is a number value. The leftmost column in the range is column 1.
close-match: An optional value that determines whether an exact match is required.
close match (TRUE, 1, or omitted): If there’s no exact match, select the column with the largest top-row value that is less than the search value. Wildcards can’t be used in search-for.
exact match (FALSE or 0): If there’s no exact match, return an error. Wildcards can be used in search-for.
So... the 2,0 means return the value form the same row as the lookup value but from the 2nd column of the range. 3, 0 means from the 3rd column. the ", 0" means exact match -
Hi Friends,
I have a table layout as follows
Friends FirstName LastName
Friend1 Annie Bose
Friend2 Lisa Ray
Friend3 Mary D'sourza
GO
when i click on this GO button all three row values hould be stored in the table
but i m able to save only the first row value(Annie,Bose)
How to save other row values?(Lisa Ray and Mary D'sourza)
I am attaching the code
//Rows.html
<html>
<body>
<form method="post" action="Rows.jsp">
<table border=1>
<tr><td>Friends</td><td>First Name</td><td>Last Name</td></tr>
<tr><td>Friend1</td><td><input type="textbox" name="fname"></td><td><input type="textbox" name="lname"></td></tr>
<tr><td>Friend2</td><td><input type="textbox" name="fname"></td><td><input type="textbox" name="lname"></td></tr>
<tr><td>Friend3</td><td><input type="textbox" name="fname"></td><td><input type="textbox" name="lname"></td></tr>
</table>
<input type="submit" name="s1" value="Go">
</form>
</body>
</html>
//Rows.jsp
<html>
<body>
<%@page import ="java.sql.*" %>
<%
try
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
Class.forName("acs.jdbc.Driver");
String url = "jdbc:atinav:localhost:7227:C:/Try.mdb";
Connection con= DriverManager.getConnection(url);
PreparedStatement pstmt=con.prepareStatement("insert into Friends values(?,?)") ;
pstmt.setString(1,fname);
pstmt.setString(2,lname);
int cnt=pstmt.executeUpdate();
System.out.println("values inserted");
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from Friends");
while(rst.next())
String str1=rst.getString("FirstName");
String str2=rst.getString("LastName");
out.println(str1);
out.println(str2);
catch(Exception e)
e.printStackTrace();
%>
</body>
</html>
Please solve my problem asap
It's urgent
Thanx in advance
Poojaenumerate the field names on the form
<%int value=number of text fields
for (int i=0; i<value; i++)
{ %>
<input type="text" name="first_name<%=i%>"> <input type="text" name="last_name<%=i%>">
<%}%>
<input type="hidden" name="value" value="<%=value%>">
<input type="submit">then in your other jsp
int value=Integer.parseInt(request.getParameter("value"));
for (int i=0; i<value; i++)
request.getParameter("first_name"+i) + request.getParameter("last_name"+i);
//write to db -
JSF datatable to get multiple row values
I want to get values of SelectBooleanCheckbox and SelectOneMenu in jsf bean from datatable for multiple rows?
You can find an example here: http://balusc.blogspot.com/2006/06/using-datatables.html
-
Multiple default values for Selection type variable
Hi all,
I am using Bex 3.5. I have a fundamental doubt while creating a User Entry, Selection Option, Optional type variable. I am trying to include multiple single variables in the default section, but it accepts only one. Is it possible to add multiple default values to the variable so that they show up in the selection screen when we run the report via Bex Analyzer ?
Thanks for the inputs !
Regards
Snehith.Hi,
In one of my bi7 reports, i remember i have given multiple default values in a single variable. For example i wanted to have multiple material types in my selection screen.
But i have to check out the type of that user entry variable.
Hope the above reply was helpful.
Kind regards,
Ashutosh singh -
How can I map last of the repeating records into a single record?
I have a following input schema, I need to take only one of the <Student> records and map that to a single record in output. Doesn't matter if the first, second or last one of the records get mapped, I only need one in the output. Any idea how can
this be accomplished?
Input:
<Students>
<Student id="1">
<Name>
A
</Name>
<Roll>
1
</Roll>
</Student>
<Student id="2">
<Name>
A
</Name>
<Roll>
1
</Roll>
</Student>
<Student id="3">
<Name>
A
</Name>
<Roll>
1
</Roll>
</Student>
</Students>
Expected Output:
<Candidate>
<Student>
<Name>
A
</Name>
</Student>
</Candidate>Sounds rather complex for something that could be done very simple in custom XSLT like this:
<?xml version="1.0" encoding="utf-16"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Students">
<Candidate>
<Student>
<Name>
<xsl:value-of select="Student/Name" />
</Name>
</Student>
</Candidate>
</xsl:template>
</xsl:stylesheet>
Morten la Cour
Maybe you are looking for
-
Please help error -9808 when downloading apps in itunes store anyone can help me out
please help error -9808 when downloading apps in itunes store anyone can help me out
-
How to update a ListBox binding when a toast message arrives in windows phone
I have a MVVM windows phone application and it has a Home page where after entering login data it goes to "Posts" page. Posts page has PostsModel with the following data : class MyClass public string NewPostText { get; set; } public string NewPostSen
-
This morning I wanted to create a new user account for some tests. When I logged in to that new account there was a long pause before the desktop appeared, but when it showed up it looked like it should - except that its user folder was completely em
-
Macbook wakes up from sleep mode on its own
Hey, bought my 13 inch unibody mb last year and it has always been working properly. However, as soon as I installed Snow Leopard, a strange thing occurs which has already almost killed my mb by overheating... When I close my mb, it turns to sleep mo
-
Is there any way to just sync parts of songs to my itpod touch from itunes? A couple of songs I want to delete a portion of them and just sync over from the 2:00 minute mark to the 6:00 minute mark of the song for example.