Divide the values of a single column into multiple values of columns
I want that the values of the "col_val" column to divide into several values in the column
Table1:
Col_val Col1, Col2
Code1 POINT 45
L2 AB 45
L1 POINT 45 OF
Code2 CAB 61
ABC 51 LABORATORY
SSS LAB 45
QQQ BED 123
BBV COT 100
FFF COT 444
Output as expected:
OUT1 out2 out3-out4, out5
Code1 AB SSS
L1
Code2
ABC
QQQ
BBV
FFF
Each line must contain the values corresponding to the Col2 values and each column must have the values in Col1, as illustrated above.
SQL> with t 2 as 3 ( 4 select 'Code1' col_val, 'ITEM' col1, 45 col2 5 from dual 6 union all 7 select 'L2' col_val, 'AB' col1, 45 col2 8 from dual 9 union all 10 select 'L1' col_val, 'ITEM' col1, 45 col2 11 from dual 12 union all 13 select 'Code2' col_val, 'CAB' col1, 61 col2 14 from dual 15 union all 16 select 'ABC' col_val, 'LAB' col1, 51 col2 17 from dual 18 union all 19 select 'SSS' col_val, 'LAB' col1, 45 col2 20 from dual 21 union all 22 select 'QQQ' col_val, 'COT' col1, 123 col2 23 from dual 24 union all 25 select 'BBV' col_val, 'COT' col1, 100 col2 26 from dual 27 union all 28 select 'FFF' col_val, 'COT' col1, 444 col2 29 from dual 30 ) 31 select max(col1) 32 , max(col2) 33 , max(col3) 34 , max(col4) 35 , max(col5) 36 from ( 37 select decode(col1, 'ITEM', col_val) col1 38 , decode(col1, 'AB' , col_val) col2 39 , decode(col1, 'LAB' , col_val) col3 40 , decode(col1, 'CAB' , col_val) col4 41 , decode(col1, 'COT' , col_val) col5 42 , t.col2 col_2 43 , row_number() over(partition by col2, col1 order by 1) rno 44 from t 45 ) 46 group 47 by col_2, rno 48 order 49 by col_2; MAX(C MAX(C MAX(C MAX(C MAX(C ----- ----- ----- ----- ----- Code1 L2 SSS L1 ABC Code2 BBV QQQ FFF 7 rows selected. SQL>
Tags: Database
Similar Questions
-
single request to divide the value
[code]
Hi Experts,
I need help to solve a small problem. I have a table and values as below
1A
1 B
1 C
1 D
Now, I need a single query to return the lines as below
1 A, B
1 A, C
1 A, D
I tried with the list_agg function, but which returns the values as
1 A, B, C, D
Can someone please
Thank you
[/ code]
For your second result, it will work.
SELECT T1.NO, T1. VAL | «, » || T2. STR. VAL OF
TEST10 T1,
T2 OF TEST10
WHERE T1. VAL<>
AND T1.NO = T2.NO
ORDER BY NOT, STR;
OUTPUT:
1 A, B 1 A, C 1 A, D 1 B, C 1 B, D 1 C, D 2 A, B 3 A, B 3 A, C 3 B, C -
Reg exp to divide the values of the variables
Hello all, I use Oracle 11.2 of SOE, the value of the variable C is: numberA:numberB for example, C: = ' 1 B: 5 A: 12 has: B: 43 3A ", I have divided than the values of two Variables A and B with the letters of withdrawal and replacement of: for the comma. Namely, the value of each would be: is: 5,12,43 B is: 1.3 someone could help to come up with the correct Exp Reg for this task. Thanks in advance.
Here's a way (like SQL or PL/SQL):
with t (Spercu))
Select "1 B: 5 A: 12 A: B: 43 3A ' double
)
Select Spercu
, regexp_replace (regexp_replace (regexp_replace(strC||':','\d+B:'),' A:$ '), ':', ',') as strA
, regexp_replace (regexp_replace (regexp_replace(strC||':','\d+A:'),' B:$ '), 'B:', ',') as strB
;SPERCU STRA, STRB
---------------- -------- ------
1 B: 5 A: 12 A: B: 43 3A 1.3 5,12,43or
declare
varA varchar2 (30);
varB varchar2 (30);
varC varchar2 (30): = ' 1 B: 5 A: 12 A: B: 43 3A;
Start
varA: = regexp_replace (regexp_replace (regexp_replace(varC||':','\d+B:'),' A:$ '), ':', ',');
varB: = regexp_replace (regexp_replace (regexp_replace(varC||':','\d+A:'),' B:$ '), 'B:', ',');
dbms_output.put_line (Vara);
dbms_output.put_line (varB);
end;
anonymous block filled
5,12,43
1, 3Replace it after you add a trailing colon varC, Interior removes all the ' nB: "Vara and all the" nA: "from varB. The Middle replace deletes the pair of colon final letter, and replace external converts the other pairs of commas leter-colon.
Kind regards
Bob -
How do I divide the values from the cfselect which allows multiple?
I have a basic form with a drop-down box and a cfselect box which allows the user to select multiples. For each element selected in the cfselect box, I need to fill in a line in the database. How do I "split" the values of the cfselect and fill several lines in the database?Found a large sample... and it works fine now... http://KB.Adobe.com/selfservice/viewContent.do?externalId=tn_17007
INSERT INTO tContentLinks (ContentID, SubSectionID)
VALUES (' #Form.ContentID # ', ' #SubSectionID # ')
-
How do I divide the values in an output of the query?
I have this code:
<cfoutput query="GetResults"> <tr> <td nowrap="nowrap">#csedept_name#</td> <td nowrap="nowrap">#question_1#</td> <td nowrap="nowrap">#question_2#</td> <td nowrap="nowrap">#question_3#</td> <td nowrap="nowrap">#question_4#</td> <td nowrap="nowrap">#question_5#</td> <td nowrap="nowrap">(#question_1#/#question_2#)</td> </tr>
9 I do not get the answert online I would I actually get the value of question_1 and question_2, something like (5/4). How I'd get him show 1.25?
Change to line 9 to:
(question_1 # / question_2 #) -Carl V.
-
How to divide the lines based on two columns...
Hi all...
I have a requirement.
I have the product, sale, purchase price column... (total of three columns) in a data set.
my data set is in such a way that... If the sale price is... There is no purchase price and vice versa...
I need too present in a report, two tables:
Table 1 includes only the elements of retail price
Table 2 should only contain the right elements.
Please see the below photo for good understanding...
Is this feasible? Where do we need to impose a condition? I tried to impose a condition, but it doesn't seem to work
http://i51.Tinypic.com/29xfdc6.jpg
Help, please.Can you send me the xml file and the model of [email protected]? I can try to help.
Have you tried to filter the records by the sale or purchase price is not equal to null column price?
Thank you
Bipuser -
How to divide the request to assign a role to multiple users in several.
Hello
While we are assigning a role to multiple users OIM11g at the same time, demand has cut several queries to get approved by the Manager of beneficiaries. Please let us know ways to apply the composite to divide the application.Why two separate approval process? Instead of two only have a license deal with assignment of dynamic loop based Manager of beneficiary to the owner of the role, and attach it to the level of the operation and you should be good (with auto level template and request approval).
The child requests are generated only at the level of the operation and NOT to any two previous levels. It is the engine of the application for you.-BB
-
divide the value in the column value
Hi all
I have an EMP table with column (NAME varchar2 (100)). It has a full name with name value "«MIDDLE_NAME"»
It should always has 3 words value separated by single spaces.
Value of the sample: FRANKLIN ROOSEVELT OBAMA
I want to create a view EMP2_VW that contains a split each distinct names as MIDDLE_NAME, LAST_NAME, FIRST_NAME
How can I do this?
Thank you very muchSQL> with t as ( 2 select 'FRANKLIN ROOSEVELT OBAMA' fullname from dual 3 ) 4 -- 5 -- actual query: 6 -- 7 select fullname 8 , substr( fullname 9 , 1 10 , instr(fullname, chr(32))-1 11 ) first_name 12 , substr( fullname 13 , instr(fullname, chr(32), 1, 1)+1 14 , instr(fullname, chr(32), 1, 2)-1 - instr(fullname, chr(32), 1, 1) 15 ) middle_name 16 , substr( fullname 17 , instr(fullname, chr(32), 1, 2)+1 18 ) last_name 19 from t; FULLNAME FIRST_NAME MIDDLE_NAME LAST_NAME ------------------------ ------------------------ ------------------------ ------------- FRANKLIN ROOSEVELT OBAMA FRANKLIN ROOSEVELT OBAMA 1 row selected.
-
Divide the value and insert into the table
create table mytab (a tank (25), b Varchar2 (50), Varchar2 (100)) C;
I have a string like
myStr:'A$bggoy#qwewewee@A$Qwe#zcxdf@A$po#xvcvxc@A$sdmy#sfdsdf @'
I need to divide and insert into mytab
That's what I tried
declare p_str varchar2 (4000)
Begin
long l_str p_str default. '$';
number of l_n;
myTableType l_data: = myTabletype();
Start
loop
l_n: = instr (l_str, ",");
When the output (nvl(l_n,0) = 0);
l_data.extend;
l_data (l_data.count): =.
LTRIM (rtrim (substr (l_str, 1, l_n - 1)));
l_str: = substr (l_str, l_n + 1);
-Connect mytab
end loop;
end;
Shows below inf-s:
describe the OBJ_SPLIT ;
recreate
CREATE OR REPLACE TYPE OBJ_SPLIT_table IS TABLE OF OBJ_SPLIT;
to view the result of the compilation
CREATE OR REPLACE Function Fn_get_split (P_str VARCHAR2)
return OBJ_SPLIT_table
PIPELINED is type t_ref_cursor IS REF CURSOR;
rf_c t_ref_cursor;
r_out_rec OBJ_SPLIT: = OBJ_SPLIT (null, null, null, null);
Begin
Open the rf_c for
Select s,.
REGEXP_SUBSTR (str, ' [^ $] +', 1, 1) s1,
REGEXP_SUBSTR (str, ' [^ $#] +', 1, 2) s2,.
REGEXP_SUBSTR (str, ' [^ $#] +' 1, 3) s3
from (select s, REGEXP_SUBSTR (s, "[^ @] +', 1, rownum") str)
(select s P_str of double)
connect by instr (s, ' @', 1, level - 1) > 0)
where str is not null;
LOOP
EXTRACTION rf_c
IN
r_out_rec. Str,
r_out_rec. Delimter1,
r_out_rec. Delimter2,
r_out_rec. Delimter3;
EXIT WHEN rf_c % NOTFOUND;
PIPE ROW (r_out_rec);
END LOOP;
CLOSE Rf_c;
end;
and the result
Select DELIMTER1, DELIMTER2, table DELIMTER3 (Fn_get_split('A$bggoy#qwewewee@A$qwe#zcxdf@A$po#xvcvxc@A$sdmy#sfdsdf@'));
in SQLPLUS
----
Ramin Hashimzade
-
Divide the value of the textfield in 2 parts and put each part var
I have a textfield, which has a text value: Paris France. Now I need to know how I can take this string, cut it into 2 parts (France and Paris) and put them into two parts in a var. So:
< textfield id = 'field1' text = 'Paris, France' >
and somewhere, I should get
var1 = France;
var2 = Paris;
I know there is a separating string command, but I'm not familiar with one of these things.
Thanks for your help!
first place to try is the ActionScript document library - google works as well
in the meantime, something like this will probably work.
var strArray:Array = field1.text.split(' '); var var1:String = strArray(0); var var2:String = strArray(1);
-
Request to divide the value of the field
Hi all
In the employees table, I have data in the column employee_name as follows
Aaron, Ms. Jamie (Jamie)
Aaron, Mrs. Jenette (SEDE)
Abbott, Mrs. Rachel (Rachel)
Breton, Mr. Jean
BRITZ, Ms. Sarie (Hervé)
-> Now I want to display the name of the employee as "Mrs. Jamie" (with out the family name and with some support included text),.
-> How to achieve this goal by the SQL query. Help me please
Thanks in advance
Chantal
WITH t AS
(SELECT "Aaron, Ms. Jamie (Jamie)" DOUBLE str)
UNION ALL
SELECT "Aaron, Mrs. Jenette (SEDE)" DOUBLE
UNION ALL
SELECT "Abbott, Mrs. Rachel (Rachel)" DOUBLE
UNION ALL
SELECT 'Breton, Mr. Jean' DOUBLE
UNION ALL
SELECT "Britz, Ms. Sarie (Sarie)" DOUBLE)
Select
Str
substr (str, instr (str, ' ') + 1
, decode (instr (str, ' (')))
0, length (str)
, instr (str, ' (()) - 2)
)
-instr (str, ' ')
) str2
tSTR STR2 Aaron, Ms. Jamie (Jamie) Ms. Jamie Aaron, Mrs. Jenette (SEDE) Ms. Nicole Abbott, Mrs. Rachel (Rachel) Mrs. Rachel Breton, Mr. Jean Mr. Jean BRITZ, Ms. Sarie (Hervé) Ms. Sarie -
The display of a single line to multiple columns
Hello Oracle gurus,
I am fairly new to the SQL development and hope that someone could help me
I have an ID that repeated several times in 3 different tables based on a condition
For your convenience, you can go
Select a.id,
B.SID,
case when b.state = 1 then 'K' another thing ' n end.
case when c.city = 2 then 'K' another thing ' n end
PRIM one
outer join STATE b left on a.id = b.id
outer join CITY c left on a.id = c.id
Results
ID NAME STATE CITY
1 Peter K N
1 Peter N K
Stewie 2 K N
2 Stewie N K
An additional line is coming because of Peter, his State Y and Y for the city.
Expected results
ID NAME STATE CITY
1 Peter K K
Stewie 2 N N
How can I achieve this? I think I can do a union. but my actual query made 140 columns. so, I'm curious to know if there is another way to address the issue?
Is it possible to use separate?
Thanks in advance.What about
select a.elig_id, max(case when b.part_supp_id= 2 then 'Y' else 'N' end) as A, max(case when b.part_supp_id=21 then 'Y' else 'N' end) as B from Elig_Test a ,Elig_Suppr b where a.elig_id=b.object_id group by a.elig_id
-
How to divide framemaker single file into multiple pages through Robohelp html
Hello, I m Robohelp beginner and I would like to ask how can I split a Framemaker file into several html files. The process must follow the subchapters defined in Framemaker and they must be named with the subchaptername function.
Check out the Forum on the integration of FM - see "paging".
-
How to align the elements in a single column default
Hello
I created the page where I have two regions of default column and I added items under them.
But they come also left aligned. I want that they should be aligned to the Center. Please help me, its urgency.In addition
Please check this thread if it helps!Align to the right numeric field
Thank you
AJ -
How to get the list in a single column in a query
Hello.
I wonder if there is a way to get a query (no pl/sql code) a list of columns with a separator between them.
I know I can get that without separators with an expression of cursor:
But the result I want is (by using the separator ';'):SQL> with test_table as ( 2 select 1 col1, 'a' col2 from dual 3 union 4 select 1 col1, 'b' col2 from dual 5 union 6 select 1 col1, 'c' col2 from dual 7 union 8 select 2 col1, 'a' col2 from dual 9 union 10 select 2 col1, 'c' col2 from dual 11 union 12 select 2 col1, 'd' col2 from dual 13 union 14 select 2 col1, 'z' col2 from dual 15 ) 16 select col1, cursor (select b.col2 from test_table b where b.col1 = a.col1 order by b.col2) col2_list from test_table a 17 group by col1 18 / COL1 COL2_LIST ---------- -------------------- 1 CURSOR STATEMENT : 2 CURSOR STATEMENT : 2 C - a b c 2 CURSOR STATEMENT : 2 CURSOR STATEMENT : 2 C - a c d z
I don't know how to manage a cursor expression without using a pl/sql function block. Can it be done using analytical functions?COL1 COL2_LIST ---------- -------------------- 1 a;b;c 2 a;c;d;z
Thanks in advance.Hello
This is called 'aggregation of chain.
This site:http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:2196162600402
shows different ways to do this, including the SYS_CONNECT_BY_PATH solution which gave Blushadow.
I got a lot of use of the first solution on this page, the function defined by the user STRAGG, that you can copy.
Once you have installed STRAGG, your query is simply
SELECT col1 , STRAGG (col2) AS col2_list FROM test_table GROUP BY col1;
The query above do not put items in a particular order.
On Oracle 10 (and more) you can have a similar function, the WM_CONCAT (property WMSYS), already installed.
WM_CONCAT is not documented, so you can't use it in your Production applications.
Maybe you are looking for
-
Re: Where can I download drivers Toshiba Satellite Pro U300?
This may seem a little silly question, but I'm not able to find drivers for Toshiba laptops online. In this case I'm after a video driver for my Toshiba Satellie Pro U300, but in general, no idea where the complete list of drivers is where they shoul
-
German satellite in Thailand (cable or AC adapter / CC?)
Hello I have a German version of Toshiba Satellite, which shouldn´t be used without grounding. But in most of the hotels or apartments in Southeast Asia, there is absolutely no grounding. Should I buy just the cable here or the whole power adapter? W
-
Problem with graphic framerate with Satellite P100
Hello I searched on several forums but I did not describe my problem as I have, well, I don't know that it is similar to the problems having the most with their Windows Vista and nvidia graphics cards. First heres my system Satellite p-100NVIDIA gefo
-
On using Windows Mail, I ask how to add contracts. The aide said to open Windows contacts. When I do so the contacts that I have everything set up. However, aid also says to click on new Contacts. I can't find the new choice of Contact toolbar. Th
-
Audio HP Envy 3033CI has stopped working
I am running Windows 7 Home Premium 64 bit on a laptop HP Envy 3033. The audio has suddenly stopped working. This happened right after an update of Windows, although that could be a coincidence. I tried to use the troubleshooter in Windows for sound