Convert multiple lines in a row
Hello
DB version: 10.2.0.3
It's the entry
NAME | Total | Free |
ITEM1 | 150 | 50 |
ITEM2 | 200 | 175 |
Expected result:
Please tell how to get the result in format (SQL using case or nested case) below
(XXX_utilized columns is on Total - free)
ITEM1_TOTAL | ITEM1_Utilized | ITEM1_Free | ITEM2_TOTAL | ITEM2_Utilized | ITEM2_Free |
150 | 100 | 50 | 200 | 25 | 175 |
Kind regards
Veera
with
the entry like
("ITEM1" select name, 150 total, 100 50 used, free of all the double union)
Select 'ITEM2', 200, 25, 175 double
)
SELECT max (case name when total ' ITEM1' then end) item1_total,.
Max (case name when 'ITEM1' then used end) item1_utilized,.
Max (case name when free ' ITEM1' then end) item1_free,.
Max (case name when total ' ITEM2' then end) item2_total,.
Max (case name when 'ITEM2' then used end) item2_utilized,.
Max (case name when free ' ITEM2' then end) item2_free
Since the entry
ITEM1_TOTAL | ITEM1_UTILIZED | ITEM1_FREE | ITEM2_TOTAL | ITEM2_UTILIZED | ITEM2_FREE |
---|---|---|---|---|---|
150 | 100 | 50 | 200 | 25 | 175 |
Concerning
Etbin
Tags: Database
Similar Questions
-
How to convert multiple lines in 1 row of columns across
Hello
My DB 10g
My data as below,
I've already tilt it by84A8E46E9366 20111008133638 84A8E46E9366 20111112000531 84A8E46E9366 20111212004432 84A8E46E9366 20120127173533 84A8E46E9366 20120226235444
and get the result as below with only 2 columnselect msid, rtrim (xmlagg (xmlelement (e, fee || '|')).extract ('//text()'), '|') fee from aaa_bill where msid='84A8E46E9366' and fee is not null group by msid;
but I need the result to be on multiple columns.84A8E46E9366 20111008133638|20111112000531|20111212004432|20120226235444|20120127173533
so I tried the following
but the result, only the first stringselect msid,REGEXP_SUBSTR ( fee , '^[^|]*' ) from ( select msid, rtrim (xmlagg (xmlelement (e, fee || '|')).extract ('//text()'), '|') fee from aaa_bill where msid='84A8E46E9366' and fee is not null group by msid ) ;
84A8E46E9366 20111008133638
is it possible to get Thos on several columns each string on column separated automatically because I have about 20000 msid separateHello
See the FAQ forum: {message identifier: = 9360005}
In Oracle 10, you can do this:
WITH got_c_num AS ( SELECT msid , fee , ROW_NUMBER () OVER ( PARTITION BY msid ORDER BY fee -- or whatever ) AS r_num FROM aaa_bill WHERE ... ) SELECT msid , MIN (CASE WHEN c_num = 1 THEN fee END) AS col_1 , MIN (CASE WHEN c_num = 2 THEN fee END) AS col_2 , MIN (CASE WHEN c_num = 3 THEN fee END) AS col_3 ... , MIN (CASE WHEN c_num = n THEN fee END) AS col_n FROM got_c_num GROUP BY msid ORDER BY msid -- If wanted ;
Note that you must specify the number of columns in the output. If you are unsure, do a high hypothesis. The query works always; unused columns will be NULL.
Published by: Frank Kulash on 12 March 2012 14:45
-
How to convert multiple lines in a row in oracle?
There is output
status st_nm County
AN OPEN 12
A NARROW 13
B OPEN 1
B CLOSE 2
EXPECTED RESULTS
st_nm OPEN_count CLOSE_COUNT
A 12 13
1 2 B
give the possibility of solutions?
Published by: 886380 on September 30, 2011 05:53
Published by: 886380 on September 30, 2011 05:54
Published by: 886380 on September 30, 2011 05:56Hello
This is called a Pivot .
Here's a way to do it:SELECT st_nm , MIN (CASE WHEN status = 'OPEN' THEN cnt END) AS open_count -- COUNT by itself is not a good column name , MIN (CASE WHEN status = 'CLOSE' THEN cnt END) AS close_count FROM existed GROUP BY st_nm;
The best way depends on your exact requirtements and your version of Oracle. (The query above will work in Oracle 8.1 and higher).
For more information, see the FAQ for the forum page:
SQL and PL/SQL FAQ -
merge multiple lines in a row (but multiple columns)
How to merge multiple lines in a row (but several columns) effectively.
For example
IDVal IDDesc Id_Information_Type Attribute_2 Attribute_3 Attribute_4 Attribute_5 Attribute_1 IdNum
23 asdc 1 location USA NM ABQ four seasons 87106
23 asdc 1 Stats 2300 91.7 8.2 85432
23 asdc 1 Audit 1996 June 17 1200
AAFC 65 2 location USA TX AUS Hilton 92305
65 AAC 2 Stats 5510 42.7 46 9999
AAFC 65 2 Audit 1996 July 172 1100
where different attributes mean different for each Information_type.
For example, for Information_Type = location
Attribute_1: countries
Attribute_2: State and so on.
For example, for Information_Type = Stats
Attribute_1 designates the Population
Attribute_2: percentage of ethnicity American and so on.
I want to create a view that shows as below:
IDVal IDDesc IDNum country state city hotel ZipCode American Population % other % area Audit year Audit AuditMonth Type AuditTime
23 asdc 1 USA NM ABQ reviews 87106 2300 91.7 46 85432 1996 June 17 1200
AAFC 65 2 USA TX AUS Hilton 92305 5510 42.7 46 9999 1996 July 172 1100
Thank youHello
This is called pivoting . The FAQ forum has a section on this subject: {message identifier: = 9360005}
I hope that answers your question.
If not, post your best attempt, as well as some examples of data (CREATE TABLE and INSERT, only relevant columns instructions) and also publish outcomes from these data. (See you the desired results, but they are very difficult to read because they are not formatted. Use \.tags, as described in the forum FAQ, below.) Explain, using specific examples, how you get the results you want from the data given. Always say which version of Oracle you're using (e.g., 11.2.0.2.0). This is always important, but especially so with pivots. See the forum FAQ {message:id=9360002}
-
Convert multiple lines in a single value separated by commas
Is is possible to convert multiple lines in a single value by concatenating the value of each line in OBIEE. I think that IO had seem a blog related to this by I'm not able to find him. Essentially, here's what I would do:
Number of customer location
101
101 NY
101 PA
102 TX
102 CA
This is to convert
101. HE, NY, PA
102 TX, CA
Can you get it someone please let me know if this is possible and how to operate it.
Thanks in advance for the help.You can do this by creating a DB function,
Visit this link
Re: Display of the horizontal valuesThank you
Vino -
convert multiple lines into one
Hi all
We got lines with 'yes/no' ' yes/no' for available deposits and appropriations available:
My need is to show only one line for each client_id in a section. For example, client_id = 1 is 'Yes' for credits and deposits ' yes' in the same division, so it must be displayed in a line:select 1 as client_id, 'yes' as credits, 'no' as deposits, 'A' as division_name from dual union all select 1 as client_id, 'no' as credits, 'yes' as deposits, 'A' as division_name from dual union all select 2 as client_id, 'yes' as credits, 'no' as deposits, 'A' as division_name from dual union all select 2 as client_id, 'no' as credits, 'yes' as deposits, 'B' as division_name from dual
How can I make it?select 1 as client_id, 'yes' as credits, 'yes' as deposits, 'A' as division_name from dual union all select 2 as client_id, 'yes' as credits, 'no' as deposits, 'A' as division_name from dual union all select 2 as client_id, 'no' as credits, 'yes' as deposits, 'B' as division_name from dual
SQL> with t as 2 (select 1 as client_id, 'yes' as credits, 'no' as deposits, 'A' as division_name from dual union all 3 select 1 as client_id, 'no' as credits, 'yes' as deposits, 'A' as division_name from dual union all 4 select 2 as client_id, 'yes' as credits, 'no' as deposits, 'A' as division_name from dual union all 5 select 2 as client_id, 'no' as credits, 'yes' as deposits, 'B' as division_name from dual 6 ) 7 select client_id, max(credits) credits, max(deposits) deposites, division_name 8 from t 9 group by client_id, division_name; CLIENT_ID CRE DEP D __________ ___ ___ _ 1 yes yes A 2 yes no A 2 no yes B
?
-
Convert multiple lines in a single line
Hi friends...
I have a table with the following information
But I need the following output...SQL> select * from tsting; A B C D E ---------- ---------- ---------- --------- ---------- 10 10 10 29-MAY-09 TEST
A B C D E ---------- ---------- ---------- --------- ---------- 10 10 10 29-MAY-09 TEST
Hello
Try:WITH test_data AS ( SELECT 10 A, NULL B, NULL C, NULL D, NULL E FROM DUAL UNION ALL SELECT NULL A, 10 B, NULL C, NULL D, NULL E FROM DUAL UNION ALL SELECT NULL A, NULL B, 10 C, NULL D, NULL E FROM DUAL UNION ALL SELECT NULL A, NULL B, NULL C, TO_DATE('29-MAY-09','DD-MON-YY') D, NULL E FROM DUAL UNION ALL SELECT NULL A, NULL B, NULL C, NULL D, 'TEST' E FROM DUAL) -- end test data SELECT MAX(A) A, MAX(B) B, MAX(C) C, MAX(D) D, MAX(E) E FROM test_data; A B C D E ---------- ---------- ---------- --------- ---- 10 10 10 29-MAY-09 TEST
-
Convert a single column into multiple lines
Hi people,
I have a task to display a single column into multiple lines (for use in LOV)
For Ex:
The column consistes of value such as 98,78,67,68,34,90. -It's a unique column values where none of the values can be ' number that is separated by commas
Then we must view it as
98
78
67
68
34
90
-under the number of lines (no lines can be ' do not number).
Thanks in advanceTry this...
SQL> ed Wrote file afiedt.buf 1 select regexp_substr('98,78,67,68,34,90', '[^,]+',1,level) Value 2 from dual 3* connect by level <= regexp_count('98,78,67,68,34,90',',') + 1 SQL> / VALUE ----------------- 98 78 67 68 34 90 6 rows selected.
Thank you!
-
Display multiple lines of data collection defined by the user in an e-mail message
I created a collection defined by the user that displays several lines of data. I created a custom rule and have linked this collection set by the user to this rule and configure an e-mail action. Variable Seveity, I have defined it in the rule to contain the column values. But it will only contain the first line of data. How can I display multiple lines of data in the alarm itself as well as the e-mail? Any help is appreciated.
The example query in the collection defined by the user is less;
Select the type, status, queuename, count (*) from PSAPMSGPUBHDR
Union
Select the type, status, queuename, count (*) from PSAPMSGPUBCON
Union
Select the type, status, queuename, count (*) from PSAPMSGSUBCON
Result:
Number of status type Queuename
------- ---------------------- ---------- -------------
HDR profil_utilisateur error 1
PUB PERSON_BASIC New 4
PUB WORKFORCE_SYNC error 1
-3 rows
I have defined the variables of gravity and the alarm message is something like this; (It is fetching only the first row of data) how do I loop through to get all the rows of data and display it in the message of alarm/email (alert) action must be written of the groovy script code to achieve this goal? If Yes can you please provide me examples?
Alarm message:
"Request message queue is:
Type: @UDC_type
QueueName: @UDC_queuename
Status: @UDC_status
County: @UDC_count
Thanks in advance
JAI
Hi Jay,.
fine I could help you. Please mark the thread as "Answered" when the issue has been resolved and do not hesitate to open a new thread for questions.
Concerning
Jochen
-
How to add multiple lines when the button is clicked
How to add multiple lines when the click on button now is just add a row .plz give me idea how... waiting for answer
/ public final class screen extends MyScreen
{
/**
* Creates a new object of MyScreen
*/
ObjectChoiceField obj1 obj2, obj3, obj4.
Table of String() = {'101 ', ' 102'};
String of shadow [] = {"Shade1", "Shade2"};
Rolls of string [] = {'101 ', ' 102'};
String cutting [] = {"100-150", "150-200"};
Chain of selectedindex1, selectedindex2, selectedindex3, selectedindex4;
LabelField lbl1 lbl2, lbl3, lbl4;
GFM LinedGridFieldManager;
HFM HorizontalFieldManager, hfm1, hfm2 hfm3;
VerticalFieldManager vfmMain;
public MyScreen()
{
Set the displayed title of the screen
hfm1 = new HorizontalFieldManager (HorizontalFieldManager.NO_VERTICAL_SCROLL |) HorizontalFieldManager.NO_VERTICAL_SCROLLBAR);
hfm2 = new HorizontalFieldManager (HorizontalFieldManager.NO_VERTICAL_SCROLL |) HorizontalFieldManager.NO_VERTICAL_SCROLLBAR);
hfm3 = new HorizontalFieldManager (HorizontalFieldManager.NO_VERTICAL_SCROLL |) HorizontalFieldManager.NO_VERTICAL_SCROLLBAR);
HFM = new HorizontalFieldManager (HorizontalFieldManager.FIELD_RIGHT);
vfmMain = new VerticalFieldManager (Manager.NO_VERTICAL_SCROLL |) Manager.NO_HORIZONTAL_SCROLLBAR);
obj1 = new ObjectChoiceField ("", graph, 0, FIELD_LEFT);
obj2 = new ObjectChoiceField ("", blind, 0, FIELD_LEFT);
Obj3 = new ObjectChoiceField ("", rolls, 0, FIELD_LEFT);
Obj4 = new ObjectChoiceField ("", cuts, 0, FIELD_LEFT);
LBL1 = new LabelField("");
LBL2 = new LabelField("");
lbl3 = new LabelField("");
lbl4 = new LabelField("");
ButtonField btnAdd = new ButtonField ("ADD", FIELD_RIGHT);
GFM = new LinedGridFieldManager (4, LinedGridFieldManager.VERTICAL_SCROLL);
hfm1.setMargin (20, 0, 10, 0);
hfm1. Add (new LabelField ("Chart"));
hfm1. Add (obj1);
hfm1. Add (new LabelField ("Shade"));
hfm1. Add (obj2);
hfm2. Add (new LabelField ("Rolls"));
hfm2. Add (Obj3);
hfm2. Add (new LabelField ("Cuts"));
hfm2. Add (Obj4);
HFM. Add (btnAdd);
GFM. Add (new LabelField ("Chart"));
GFM. Add (new LabelField ("Shade"));
GFM. Add (new LabelField ("Rolls"));
GFM. Add (new LabelField ("Cuts"));
vfmMain.add (hfm1);
vfmMain.add (hfm2);
vfmMain.add (hfm3);
vfmMain.add (hfm);
vfmMain.add (new SeparatorField());
vfmMain.add (gfm);
Add (vfmMain);
btnAdd.setChangeListener (new FieldChangeListener()
{
' Public Sub fieldChanged (field field, int context) {}
TODO self-generating method stub
selectedindex1 = chart [obj1.getSelectedIndex ()];
selectedindex2 = shade [obj2.getSelectedIndex ()];
selectedindex3 = rolls [obj3.getSelectedIndex ()];
selectedindex4 = cuts [obj4.getSelectedIndex ()];
While (LBL1. GetText(). Equals("") | LBL2. GetText(). Equals("") | lbl3. GetText(). Equals("") | lbl4. GetText(). Equals(""))
{
LBL1. SetText (selectedindex1);
LBL2. SetText (selectedindex2);
lbl3. SetText (selectedindex3);
lbl4. SetText (selectedindex4);
GFM. Add (LBL1);
GFM. Add (LBL2);
GFM. Add (lbl3);
GFM. Add (lbl4);
}
}
});
}
}Hi Piya,
I run your code, and according to your logic that it works correctly.
It's adding that line only once because according to your logic that one line can be added to MDT, if you do not want to add line on each click on the button, follow these steps:
selectedindex1 = chart [obj1.getSelectedIndex ()];
selectedindex2 = shade [obj2.getSelectedIndex ()];
selectedindex3 = rolls [obj3.getSelectedIndex ()];
selectedindex4 = cuts [obj4.getSelectedIndex ()];Lbl1 LabelField = new LabelField("");
Lbl2 LabelField = new LabelField("");
LabelField lbl3 = new LabelField("");
LabelField lbl4 = new LabelField("");
If (LBL1. GetText(). Equals("") | LBL2. GetText(). Equals("") | lbl3. GetText(). Equals("") | lbl4. GetText(). Equals(""))
{
LBL1. SetText (selectedindex1);
LBL2. SetText (selectedindex2);
lbl3. SetText (selectedindex3);
lbl4. SetText (selectedindex4);
GFM. Add (LBL1);
GFM. Add (LBL2);
GFM. Add (lbl3);
GFM. Add (lbl4);
} -
View multiple lines inside a loop
Hi all
I have a question.
My table xx_test_table has 10 columns, 3 of which are status, error_message and request_id.
Now, after some validations on querying the table with the request_id it gives 3 rows.
I have to post this in a loop. The code I used is the following.
BEGIN
SELECT COUNT (*)
IN lv_error_count
OF xx_test_table
WHERE request_id = 5920135;
IF(lv_error_count > 0) THEN
fnd_file. Put_line (fnd_file. OUT, 'xx_test_table error information Table');
FOR lv_disp_data in 1... lv_error_count LOOP
SELECT column_name,
ERROR_MESSAGE,
request_id,
table-name
BY lv_column_name,
lv_error_message,
lv_request_id,
lv_table_name
OF po_interface_errors
WHERE request_id = lv_req_id;
fnd_file. Put_line (fnd_file. OUT,' request ID: ' | lv_request_id);
fnd_file. Put_line (fnd_file. OUT,' column name: ' | lv_column_name);
fnd_file. Put_line (fnd_file. OUT, "Error Message: ' |" lv_error_message);
fnd_file. Put_line (fnd_file. OUT,' the name of the Table: ' | lv_table_name);
END LOOP;
END IF;
. This loop is inside a separate procedure and all the variables have been declared. Problem is when the API is run at the front end it illustrates TOO_MANY_ROWS exceptions to this procedure.
Is there another way to display multiple lines of data in a table when we Select in the statement?
This should make the necessary
BEGIN SELECT COUNT(*) INTO lv_error_count FROM xx_test_table WHERE request_id = 5920135; IF(lv_error_count > 0) THEN fnd_file.PUT_LINE(fnd_file.OUTPUT,'Error Information from xx_test_table Table'); FOR rec IN ( SELECT column_name, error_message, request_id, table_name FROM po_interface_errors WHERE request_id = lv_req_id ) LOOP fnd_file.PUT_LINE(fnd_file.OUTPUT,'Request ID: '||rec.column_name); fnd_file.PUT_LINE(fnd_file.OUTPUT,'Column Name: '||rec.error_message); fnd_file.PUT_LINE(fnd_file.OUTPUT,'Error Message: '||rec.request_id); fnd_file.PUT_LINE(fnd_file.OUTPUT,'Table Name: '||rec.table_name); END LOOP; END IF; END; /
Concerning
Arun
-
How to insert multiple lines using a single query
Hi all
How to insert multiple lines using a single query to the emp table?
I have the number of rows to insert into table x. consumes a lot of time. I tried to insert several lines using a single query, but get errors. I know exactly the query to do this.
Thank you
SunilLike this?
SQL> create table test(id number , dt date); Table created. SQL> insert into test values(&a,&b); Enter value for a: 1 --- It asked me and I entered 1 Enter value for b: sysdate --- It asked me and I entered sysdate old 1: insert into test values(&a,&b) new 1: insert into test values(1,sysdate) 1 row created. SQL>
g.
-
Can't understand why this query returns multiple lines with the same data
Hi all
I am a relative novice and self-taught when it comes to SQL. I wrote a query to our reporting tool that returns multiple rows, and I can't understand why. I know that I can use the SELECT DISTINCT option, but it really slows the execution when I do. I'd really rather understand if I can change the code to avoid the multiples. This is the query. I've included a few statements in italics to help explain the break. Any ideas?
SELECT MATSITE, MATPONUM, FIRSTRECPTDATE
Of
Subquery that concludes the first date on which purchase orders have been implemented with ACK State
(SELECT ACKSTAT. PONUM AS 'ACKPONUM', (MIN (ACKSTAT. CHANGEDATE)) AS 'FIRSTACKDATE '.
OF PZMAX. POSTATUS ACKSTAT
WHERE (ACKSTAT. STATE = 'ACK') AND (ACKSTAT.ORGID ='CGSALTUS)
GROUP OF ACKSTAT. PONUM),
Subquery that concludes the first reception against a purchase order transaction for purposes of comparison
(SELECT TRANS. PONUM AS "MATPONUM", TRANS. SITEID AS 'MATSITE', (MIN (TRANS. TRANSDATE)) AS 'FIRSTRECPTDATE '.
OF PZMAX. MATRECTRANS TRANS
WHERE (TRANS.ORGID ='CGSALTUS) AND (TRANS. HOUR > =: startDate and TRANS. TRANSDATE < =: endDate)
TRANS GROUP. SITEID, TRANS. PONUM)
WHERE
(ACKPONUM = MATPONUM AND FIRSTRECPTDATE < FIRSTACKDATE) OR (NOT EXISTS (SELECT 1 FROM PZMAX. POSTATUS ACKSTAT2 WHERE (ACKSTAT2. PONUM = MATPONUM) AND (ACKSTAT2. STATE = 'ACK') AND (ACKSTAT2.ORGID ='CGSALTUS)))
The where the instruction is intended to find when one of two conditions exists. ((1) received happened before the command either in ACK or 2) a reception that's happened, but the purchase order is never in ACK State. It seems that this second condition that creates multiple lines.
Any thoughts will be appreciated geratly.
Dave Teece
-
multiple lines of text on a command button
Is it possible to get multiple lines of text on a command button. Instead of a large button with the text "start the Test System". I would like a big button with 3 lines.
Beginning
Test
System
If you change the label of the button control in IUR editor you can split the text into lines with Ctrl + Enter.
If you programmatically set the label, "\n" code integration in the text of the label.
Both methods work for all types of control, not only for the command buttons.
-
Arrange the tiles in a column, but multiple lines
When you have the tiles on The start screen of Metro , you can set the group / block a tile only, but when you want to add the second tile to this group / block, you can put only horizontally (from left or right tile existed), in other words, you can add the column within that group, but you can put the new Tile vertically , under a tile already existence.
I want to define group / block of tiles with a single column, but multiple lines.For example, instead of this:xx xx xx xxxx xx xxto get this:xx x xx xxxx x xx xxScreenshot:Hi Mike b. II.
It's normal. You cannot have tiles in groups vertically. Now in your case, if you change the tiles to large tiles, they will stack vertically.
Maybe you are looking for
-
My homepage will not stay as my home page. As soon as I close and Open firefox again it goes back to a search like google page, but it's not google. Summer goes for about 5 days now and its really frustrating.
-
Satellite A350-13 a - where to find XP drivers
Hello I´d as change my OS from Windows Vista to Windows XP but I Don t find drivers for windows XP on my laptop Satellite A350-13 has can someone help me?
-
mSata SSD on Lenovo W510 on mPCIe using the WWAN slot
I would like to know if possible my W510 is compatible with mSATA SSD on mPCIe slot. I would like to install this mSATA Crucial 256 GB Internal Solid State Drive on my W510 m4 and load Win7 64 bit Pro as main boot drive. Please notify. Thanks in adva
-
Frequency rate real pulse readings
When I set up a counter to generate pulse train using 'DAQmx Create Channel (CO Pulse Freq)' and provide an arbitrary value at the entrance of the "frequency", I can read the value of the real rate? SampClk.Rate on node DAQmx Timing property returns
-
change the language on photosmart B209a more
I have an all in one printer, copier, scanner Photosmart B209a more - I had machine the language in English but by accident, it was changed to the Korean or Japanese, and now I am unable to return to English - can someone please help me get back to E