To display comma separted value into multiple column
Hi,
I want to display value into multiple column like below
data is like this
col1
res_menaHome:MenaHome
res_menaHomeEmp:MenaHome Employee
res_MDSpecialSer:MD Special Services
res_Smart:Smart
now i want to display like
col1 col2
res_menaHome MenaHome
res_menaHomeEmp MenaHome Employee
res_MDSpecialSer MD Special Services
res_Smart Smart
Thanks in advance.
You mean like this?
with q as (select 'res_menaHome:MenaHome' myString from dual)
select substr(myString, 1, instr(myString, ':') - 1) col1,
substr(myString, instr(myString, ':') + 1) col2
from q
COL1,COL2
res_menaHome,MenaHome
Similar Messages
-
How to insert parameter value into multiple columns and rows
Hi All,
I have one procedure insert_tab and I am passing
100~101~102:103~104~105:106~107~108 as a parameter to that procedure. I wanted to insert each numeric value into one column. The output of the table should contain
Table:
Col1 Col2 Col3
100 101 102
103 104 105
106 107 108
Awaiting for your reply..That's not more clear for me...
Anyway, if you really want a procedure for that, try :
SQL> create table tblstr (col1 number,col2 number,col3 number);
Table created.
SQL>
SQL> create or replace procedure insert_fct (p_string IN varchar2)
2 as
3 v_string varchar2(4000):=p_string||':';
4 v_substring varchar2(4000);
5
6 begin
7 while instr(v_string,':') > 0 loop
8 v_substring := substr(v_string,1,instr(v_string,':')-1)||'~';
9 insert into tblstr(col1,col2,col3)
10 values (substr(v_substring,1,instr(v_substring,'~',1,1)-1),
11 substr(v_substring,instr(v_substring,'~',1,1)+1,instr(v_substring,'~',1,2)-instr(v_substring,'~',1,1)-1),
12 substr(v_substring,instr(v_substring,'~',1,2)+1,instr(v_substring,'~',1,3)-instr(v_substring,'~',1,2)-1));
13 v_string:=substr(v_string,instr(v_string,':')+1);
14 end loop;
15 end;
16 /
Procedure created.
SQL>
SQL> show err
No errors.
SQL>
SQL> select * from tblstr;
no rows selected
SQL> exec insert_fct('100~101~102:103~104~105:106~107~108')
PL/SQL procedure successfully completed.
SQL> select * from tblstr;
COL1 COL2 COL3
100 101 102
103 104 105
106 107 108
SQL> exec insert_fct('109~~')
PL/SQL procedure successfully completed.
SQL> exec insert_fct('~110~')
PL/SQL procedure successfully completed.
SQL> exec insert_fct('~~111')
PL/SQL procedure successfully completed.
SQL> select * from tblstr;
COL1 COL2 COL3
100 101 102
103 104 105
106 107 108
109
110
111
6 rows selected.
SQL> Nicolas. -
Pivoting multiple coulmn values into multiple columns dynamically
Hi,
i have found some topics related to 'pivot' in this forum. but my situation is a lit bit different.
I have a table like the below
create
table #temp
(id
int, code
varchar(8),
routing varchar(50))
insert
into #temp(id,code
,routing
values(1,
'code1',
'route1')
,(1,'code11','route11')
,(2,
'code22',
'route22')
,(2,
'code222',
'route222')
,(2,
'code2333',
'route2333')
,(2,
'code2',
'route2')
,(3,
'code3',
'route3'),
(4,
'code4',
'route4'),
(4,
'code44',
'route44')
ID
CODE
ROUTE
1
code1
route1
1
code11
route11
2
code22
route22
2
code222
route222
2
code2333
route2333
2
code2
route2
3
code3
route3
4
code4
route4
4
code44
route44
And I need to display the table below format including column names. And code/routing columns can repeat not more than 10 times.
id
code
routing
code
routing
code
routing
code
routing
1
code1
route1
code11
route11
2
code2
route2
code22
route22
code222
route222
code2333
route2333
3
code3
route3
4
code4
route4
code44
route44
I am using sql server 2012.
i have benefited alot from this forum. a big thank you to the forum.
I would appreciate your help.Refer below solution with PIVOT. You can extend by using Dynamic Pivot.
--create table #temp (id int, code varchar(8), routing varchar(50))
--insert into #temp (id,code ,routing ) values(1,'code1','route1')
--,(1,'code11','route11'),(2,'code22','route22'),(2,'code222','route222'),(2,'code2333','route2333')
--,(2,'code2', 'route2'),(3,'code3', 'route3'),(4,'code4','route4'),(4,'code44','route44')
;with cte1 as (
select *,row_number() over (partition by id order by code) rn
from #temp
),cte2 as (
select *, case
when id=id then 'code_' + cast(rn as varchar) end codeCol, case
when id=id then 'routing_' + cast(rn as varchar) end routingCol
from cte1
),cte3 as (
select id,code_1,routing_1,code_2,routing_2,code_3,routing_3, code_4,routing_4 from cte2
pivot(max(code) for codeCol in (code_1,code_2,code_3,code_4)) pvt
pivot(max(routing) for routingCol in (routing_1,routing_2,routing_3,routing_4) ) pvt1
select id,
max(code_1) code_1,max(routing_1) routing_1,
max(code_2) code_2,max(routing_2) routing_2,
max(code_3) code_3,max(routing_3) routing_3,
max(code_4) code_4,max(routing_4) routing_4
from cte3
group by id
For dynamic pivot technique refer below query sample,
DECLARE
@cols nvarchar(max),
@stmt nvarchar(max)
SELECT @cols = isnull(@cols + ', ', '') + '[' + T.[NAME] + ']' FROM (SELECT distinct [NAME] FROM PIVOTTEST) as T
SELECT @stmt = '
SELECT *
FROM PIVOTTEST as T
PIVOT
max(T.VALUE)
for T.[NAME] in (' + @cols + ')
) as P'
exec sp_executesql @stmt = @stmt
select * from PIVOTTEST
Regards, RSingh -
Displaying single value (Record) into multiple columns
Hi All,
I want to display the single record into multiple columns. Please let me know How to achieve this..
Record:
Lvl Activity Acre
6 Week 4 (Same value to be displayed into 3 columns.)
REquired output:
lvl Activity PH1 PH2 PH3
6 Week 4 4 4
Thanks
Kaviuser533671 wrote:
Hi,
Thanks for immediate reply.
PH1, PH2, PH3, ... will go more columns based on parameter , what we are passing.An single SQL statement cannot have a dynamic number of columns based on the data itself. The projection (columns returned) have to be known before any data is fetched... and that includes some 'parameter' value.
{thread:id=2309172}
You can build a query dynamically, based on a parameter or even on the data, but 99 times out 100 people use dynamic queries where they are not needed.
Perhaps explain to us what you are really trying to achieve and why, and we could suggest some better way. -
Split one column value and insert into multiple columns
hi
am new to plsql .
i want to split a characters from one column and insert into multiple columns
i tried used substr function the symbol ',' vary his place dynamically ,so i can't apply substr function.
for eg: before split
col1 :
col2 :
col3 :
col4 :
colu5: adsdf,fgrty,erfth,oiunth,okujt
after split
col1 :adsd
col2 :fgrty
col3 :erfth
col4 :oiunth
col5 : adsdf,fgrty,erfth,oiunth,okujt
can anyone help me
thanks
Edited by: 800324 on Dec 23, 2010 8:28 AM
Edited by: 800324 on Dec 23, 2010 8:36 AMHow about:
SQL> create table t
2 (col1 varchar2(30)
3 ,col2 varchar2(30)
4 ,col3 varchar2(30)
5 ,col4 varchar2(30)
6 ,col5 varchar2(30)
7 );
Table created.
SQL> insert into t (col5) values ('adsdf,fgrty,erfth,oiunth,okujt');
1 row created.
SQL> insert into t (col5) values ('x,y');
1 row created.
SQL> insert into t (col5) values ('a,b,c,d');
1 row created.
SQL> select * from t;
COL1 COL2 COL3 COL4 COL5
adsdf,fgrty,erfth,oiunth,okujt
x,y
a,b,c,d
3 rows selected.
SQL>
SQL> merge into t a
2 using ( with t1 as ( select col5||',' col5
3 from t
4 )
5 select substr(col5, 1, instr(col5, ',', 1, 1)-1) col1
6 , substr(col5, instr(col5, ',', 1, 1)+1, instr(col5, ',', 1, 2)- instr(col5, ',', 1, 1)-1) col2
7 , substr(col5, instr(col5, ',', 1, 2)+1, instr(col5, ',', 1, 3)- instr(col5, ',', 1, 2)-1) col3
8 , substr(col5, instr(col5, ',', 1, 3)+1, instr(col5, ',', 1, 4)- instr(col5, ',', 1, 3)-1) col4
9 , rtrim(col5, ',') col5
10 from t1
11 ) b
12 on ( a.col5 = b.col5 )
13 when matched then update set a.col1 = b.col1
14 , a.col2 = b.col2
15 , a.col3 = b.col3
16 , a.col4 = b.col4
17 when not matched then insert (a.col1) values (null);
3 rows merged.
SQL> select * from t;
COL1 COL2 COL3 COL4 COL5
adsdf fgrty erfth oiunth adsdf,fgrty,erfth,oiunth,okujt
x y x,y
a b c d a,b,c,d
3 rows selected.
SQL> Assuming you're on 9i... -
Please - immediate help needed parsing csv values into multiple rows
Hello, we have a very immediate need to be able to parse out a field of comma separated values into individual rows. The following is an example written in SQL Server syntax which does not work in Oracle.
The tricky part is that each ROUTES can be a different length, and each CSV can have a different number of routes in it.
Here is an example of the table ("Quotes") of CSV values I want to normalize:
TPNUMBER ROUTES
1001 1, 56W, 18
1002 2, 16, 186, 28
Here is an example of what I need it to look like:
TPNUMBER ROUTES
1001 1
1001 56W
1001 18
1002 2
1002 16
1002 186
1002 28
Here is the "Tally" table for the query below:
ID
1
2
3
4
5
6
7
And finally, here is the query which parses CSV values into multiple rows but which does not work in Oralce:
SELECT TPNUMBER,
NullIf(SubString(',' + ROUTES + ',' , ID , CharIndex(',' , ',' + ROUTES + ',' , ID) - ID) , '') AS ONEROUTE
FROM Tally, Quotes
WHERE ID <= Len(',' + ROUTES + ',') AND SubString(',' + Phrase + ',' , ID - 1, 1) = ','
AND CharIndex(',' , ',' + ROUTES + ',' , ID) - ID > 0
It may be necessary to use a cursor to loop through the CSV table and process each row (a loop within another loop...) but this is beyond my comprehesion of PL/SQL.
Many thanks in advance for your advice/help.
apkNot sure what you are trying to do with the last step, but this should work for the first part. I assume you would use sqlldr but I just did inserts instead. You might need more than 5 "routes" in the csv. You could put some reasonable max on that number of columns:
SQL>create table t_csv
2 (TPNUMBER varchar2(20),
3 ROUTE_1 VARCHAR2(5),
4 ROUTE_2 VARCHAR2(5),
5 ROUTE_3 VARCHAR2(5),
6 ROUTE_4 VARCHAR2(5),
7 ROUTE_5 VARCHAR2(5),
8 ROUTE_6 VARCHAR2(5) );
Table created.
SQL>INSERT INTO t_csv (TPNUMBER,ROUTE_1,ROUTE_2) values( '1001 1', '56W', '18' );
1 row created.
SQL>INSERT INTO t_csv (TPNUMBER,ROUTE_1,ROUTE_2,ROUTE_3) values( '1002 2', '16', '186', '28');
1 row created.
SQL>create table t_quotes(
2 tpnumber NUMBER,
3 routes VARCHAR2(5));
Table created.
SQL>DECLARE
2 L_tpnumber NUMBER;
3 L_route VARCHAR2(5);
4 begin
5 for rec in (select * from t_csv) loop
6 L_tpnumber := SUBSTR(rec.tpnumber,1,INSTR(rec.tpnumber,' ')-1);
7 L_route := SUBSTR(rec.tpnumber,INSTR(rec.tpnumber,' ')+1);
8 insert into t_quotes values( L_tpnumber, l_route );
9 if rec.route_1 is not null then
10 insert into t_quotes values( L_tpnumber, rec.route_1 );
11 end if;
12 if rec.route_2 is not null then
13 insert into t_quotes values( L_tpnumber, rec.route_2 );
14 end if;
15 if rec.route_3 is not null then
16 insert into t_quotes values( L_tpnumber, rec.route_3 );
17 end if;
18 if rec.route_4 is not null then
19 insert into t_quotes values( L_tpnumber, rec.route_4 );
20 end if;
21 if rec.route_5 is not null then
22 insert into t_quotes values( L_tpnumber, rec.route_5 );
23 end if;
24 end loop;
25 end;
26 /
PL/SQL procedure successfully completed.
SQL> select tpnumber, routes from t_quotes;
TPNUMBER ROUTE
1001 1
1001 56W
1001 18
1002 2
1002 16
1002 186
1002 28
7 rows selected. -
How can I separate one column into multiple column?
How can I separate one column into multiple column?
This is what I have:
BUYER_ID ATTRIBUTE_NAME ATTRIBUTE_VALUE
0001 PHONE_NUMBER 555-555-0001
0001 EMAIL [email protected]
0001 CURRENCY USD
0002 PHONE_NUMBER 555-555-0002
0002 EMAIL [email protected]
0002 CURRENCY USD
0003 PHONE_NUMBER 555-555-0003
0003 EMAIL [email protected]
0003 CURRENCY CAD
This is what I would like to have:
BUYER_ID PHONE_NUMBER EMAIL CURRENCY
0001 555-555-0001 [email protected] USD
0002 555-555-0002 [email protected] USD
0003 555-555-0003 [email protected] CAD
Any help would be greatly appreciated.This is another solution. Suppose your actual table's name is test(which has the redundant data). create a table like this:
CREATE TABLE test2 (BUYER_ID number(10),PHONE_NUMBER varchar2(50),EMAIL varchar2(50),CURRENCY varchar2(50));
then you will type this procedure:
declare
phone_number_v varchar2(50);
EMAIL_v varchar2(50);
CURRENCY_v varchar2(50);
cursor my_test is select * from test;
begin
for my_test_curs in my_test loop
select ATTRIBUTE_VALUE INTO phone_number_v from test
where person_id=my_test_curs.person_id
and attribute_name ='PHONE_NUMBER';
select ATTRIBUTE_VALUE INTO EMAIL_v from test
where person_id=my_test_curs.person_id
and attribute_name ='EMAIL';
select ATTRIBUTE_VALUE INTO CURRENCY_v from test
where person_id=my_test_curs.person_id
and attribute_name ='CURRENCY';
INSERT INTO test2
VALUES (my_test_curs.person_id,phone_number_v,EMAIL_v,CURRENCY_v);
END LOOP;
END;
Then you will create your final table like this:
create table final_table as select * from test2 where 1=2;
After that write this code:
INSERT ALL
into final_table
SELECT DISTINCT(BUYER_ID),PHONE_NUMBER,EMAIL,CURRENCY
FROM TEST2;
If you have a huge amount of data in your original table this solution may take a long time to do what you need. -
Split flat file column data into multiple columns using ssis
Hi All, I need one help in SSIS.
I have a source file with column1, I want to split the column1 data into
multiple columns when there is a semicolon(';') and there is no specific
length between each semicolon,let say..
Column1:
John;Sam;Greg;David
And at destination we have 4 columns let say D1,D2,D3,D4
I want to map
John -> D1
Sam->D2
Greg->D3
David->D4
Please I need it ASAP
Thanks in Advance,
RH
sqlImports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Imports System.IO
Public Class ScriptMain
Inherits UserComponent
Private textReader As StreamReader
Private exportedAddressFile As String
Public Overrides Sub AcquireConnections(ByVal Transaction As Object)
Dim connMgr As IDTSConnectionManager90 = _
Me.Connections.Connection
exportedAddressFile = _
CType(connMgr.AcquireConnection(Nothing), String)
End Sub
Public Overrides Sub PreExecute()
MyBase.PreExecute()
textReader = New StreamReader(exportedAddressFile)
End Sub
Public Overrides Sub CreateNewOutputRows()
Dim nextLine As String
Dim columns As String()
Dim cols As String()
Dim delimiters As Char()
delimiters = ",".ToCharArray
nextLine = textReader.ReadLine
Do While nextLine IsNot Nothing
columns = nextLine.Split(delimiters)
With Output0Buffer
cols = columns(1).Split(";".ToCharArray)
.AddRow()
.ID = Convert.ToInt32(columns(0))
If cols.GetUpperBound(0) >= 0 Then
.Col1 = cols(0)
End If
If cols.GetUpperBound(0) >= 1 Then
.Col2 = cols(1)
End If
If cols.GetUpperBound(0) >= 2 Then
.Col3 = cols(2)
End If
If cols.GetUpperBound(0) >= 3 Then
.Col4 = cols(3)
End If
End With
nextLine = textReader.ReadLine
Loop
End Sub
Public Overrides Sub PostExecute()
MyBase.PostExecute()
textReader.Close()
End Sub
End Class
Put this code in ur script component. Before that add 5 columns to the script component output and name them as ID, col1, co2..,col4. ID is of data type int. Create a flat file destination and name it as connection and point it to the flat file as the source.
Im not sure whats the delimiter in ur flat file between the 2 columns. I have use a comma change it accordingly.
This is the output I get:
ID Col1
Col2 Col3
Col4
1 john
Greg David
Sam
2 tom
tony NULL
NULL
3 harry
NULL NULL
NULL -
How to insert an upper value into a column?
Hi!,
I need to insert an upper value into a column.
The data is on a flat file and it could be lowercase or uppercase?
Do I have to create a trigger to solve this problem?
How could the trigger be?
Thanks,
AlexIf you are using SQL*Loader to load the data from flat file into the db table, then you can achieve inserting the UPPER Case of column value in your sqlloader ctl file itself as in below example
LOAD DATA
INFILE *
APPEND INTO TABLE XXX
( field1 position(1:7) char "UPPER(:field1)",
field2 position(8:15) char "UPPER(:field2)"
BEGINDATA
Phil Locke
Jason Durbin
So in this case the Names Phil Locke and Jason Durbin will be inserted as PHIL LOCKE and JASON DURBIN into the target table.
Regards,
Murali Mohan -
How to copy one column BLOB value into another column of another database.
How to copy one column BLOB value into another column of another database.
BLOB value contains word document.
I thought of copy the BLOB value into a text file and then update the new column value by the same text in textfile. Will this work?
Is there any other better way to do this?You're welcome
BLOB fields contains binary data. I don't think you can do this
Also if I view the BLOB as text. Can I copy it and insert into the new database.
I think your options are as I said. Datapump or CTAS
Best Regards -
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 -
Display rows into multiple columns
I have a table in the following format:
id value
a1 0
a2 0
a3 0
a4 0
b1 0
b2 0
b3 0
b4 0
how do I go about displaying it into four columns in the following format:
id1 value1 id2 value2
a1 0 b1 0
a2 0 b2 0
a3 0 b3 0
a4 0 b4 0Hi,
789063 wrote:
I got that error in toad. So now I am testing from command prompt. When you say "command prompt", do you mean SQL*Plus?
Sorry, I don't know much about Toad. If Toad is returning 0 rows, and the same query is returning 8 rows in SQL*Plus, then I suspect you are not connecting to the same database or the same user. ASre you sure you're running the exact same query in both front ends?
Here is the data set that I am testing for:
<pre>
id1 value
smple_val_1 0
smple_val_2 1
smple_val_3 1
smple_val_4 2
smple_other_1 3
smple_other_2 5
smple_other_3 8
smple_other_4 13
some_other_val1 1
some_other_val2 0
some_other_val3 3
some_other_val4 5
</pre>
I am trying to select only 'smple%' in the query, which should display in four columns like:
<pre>
id1 val1 id2 val2
smple_val_1 1 smple_other_1 3
smple_val_2 0 smple_other_2 5
smple_val_3 0 smple_other_3 8
smple_val_4 2 smple_other_4 13
</pre>Is that really the output you want? Why not
ID1 VAL1 ID2 VAL2
smple_val_1 0 smple_other_1 3
smple_val_2 1 smple_other_2 5
smple_val_3 1 smple_other_3 8
smple_val_4 2 smple_other_4 13with the 0's and 1's in the val1 column reversed?
Here is the ddl I used:
<pre>
CREATE TABLE table_x
( id VARCHAR2 (20) PRIMARY KEY
, value NUMBER
INSERT INTO table_x (id, value) VALUES ('smple_val_1', 0);
INSERT INTO table_x (id, value) VALUES ('smple_val_2', 1);
INSERT INTO table_x (id, value) VALUES ('smple_val_3', 1);
INSERT INTO table_x (id, value) VALUES ('smple_val_4', 2);
INSERT INTO table_x (id, value) VALUES ('smple_other_1', 3);
INSERT INTO table_x (id, value) VALUES ('smple_other_2', 5);
INSERT INTO table_x (id, value) VALUES ('smple_other_3', 8);
INSERT INTO table_x (id, value) VALUES ('smple_other_4', 13);
INSERT INTO table_x (id, value) VALUES ('some_other_val1', 1);
INSERT INTO table_x (id, value) VALUES ('some_other_val2', 0);
INSERT INTO table_x (id, value) VALUES ('some_other_val3', 3);
INSERT INTO table_x (id, value) VALUES ('some_other_val4', 5);
</pre>Thanks, that's good.
Where is the explanation of how you get the results you want from that data? There are a lot of different ways to get the same results from the same data, especially from a small set of sample data. I might provide a query that gets the right results for the wrong reasons, and when you run that query on a different set of data, it won't necessarily work. That's exactly what happened before. I guessed at what you wanted, but I guessed wrong. Guessing is not a very efficient or reliable way to solve problems. Don't make people guess: explain what you want.
In particular, explain how you can tell, buy looking at a row and column in the original table, to which row and which column of the output it corresponds. I'm pretty sure that the id column of the table always corresponds to either the id1 or idl2 column of the output, and that value always corresponds to either val1 or val2. From this latest set of sample data, it looks like all the rows in table_x that start with 'smple_val' will correspond to the id1 and val1 columns, and that all therows that start with 'smple_other_' will correspond to the id2 and val2 columns. It also looks like each row of the output represents a unique value of the last character of table_x.id.
If I guessed right this time, then what you want is:
SELECT MIN (CASE WHEN id LIKE 'smple\_val\_%' ESCAPE '\' THEN id END) AS id1
, MIN (CASE WHEN id LIKE 'smple\_val\_%' ESCAPE '\' THEN value END) AS val1
, MIN (CASE WHEN id LIKE 'smple\_other\_%' ESCAPE '\' THEN id END) AS id2
, MIN (CASE WHEN id LIKE 'smple\_other\_%' ESCAPE '\' THEN value END) AS val2
FROM table_x
GROUP BY SUBSTR (id, -1)
ORDER BY SUBSTR (id, -1)
;But this is only a guess. I can't guarrantee that this will work on your real data any better than my last guess did. You'll get better answers faster if you provide an explanation, so that poeple don't have to guess so much. -
Inserting values into multiple tables in one jsf page with single commit op
hi all,
i have two tables ,
one is parent table and other is child record.
record details:
table1:(parent table)
emplid (primary key)
empl_name
table 2:(child table)
empl id ( Foreign key)
empl_name ( Foreign key)
contact_no (primary key)
my senario is , i need insert values into both parent and child table in one save option.
and both the tables will be in one jsf page.
is this possible to do?
thanks all,
regards,
M vijayalakshmihi,
i feel my question is not clear.
let me explain my question clearly.
1. i have two records
*1. emp_names*
attributes of this table is 1.emplid
2.emp_name.
emplid is a primary key.
2. emp_contact
attributes of this table is 1.emplid
2. contact_no
In this table emplid is forigen key from emp_name table
contact_no is primary key.
and my senerio is,
for one emplid there are many contact no.
in database diagram i have created these two entities. and from that i have generated two views objects.
now in jsf page ,
i shd have all fields from both the records.
wn ever i click on add button , i shd be able to insert one complete row of data to both the tables.
means,
emplid
empl_name
contact_no.
and if i click on commit button data shd be insert in both the tables.
so how to achive this?
am very beginner to the jdeveloper tool.
regards,
m vijayalakshmi. -
Find duplication values from multiple columns in a big table
Hi All,
I am working on a 11gR2 database in linux. i want to display record that have duplicate values in 2 columns.
1. Table Structure :-
CREATE TABLE A
ID NUMBER(10),
F_NAME VARCHAR2(100 BYTE),
L_NAME VARCHAR2(100 BYTE)
2. Sample Data:-
Insert into A
(ID, F_NAME, L_NAME) Values (1,'TONY' ,'SUMIT');
Insert into A
(ID, F_NAME, L_NAME) Values (2,'SUMIT' ,'KEITH');
Insert into A
(ID, F_NAME, L_NAME) Values (3,'NORA','SMITH');
Insert into A
(ID, F_NAME, L_NAME) Values (4,'APRIL','TONY');
Insert into A
(ID, F_NAME, L_NAME) Values (5,'ROSS','TAM');
ID F_NAME L_NAME
1 TONY SUMIT
2 SUMIT KEITH
3 NORA SMITH
4 APRIL TONY
5 ROSS TAM
4. My requirement is i need display IDs that it's F_NAME or L_NAME has duplication in F_NAME or L_NAME columns.
The result should be
ID
1 reason: F_NAME (TONY) equals to L_NAME of record 4, L_NAME (SUMIT) equals to F_NAME of record 2
2 reason: F_NAME (SUMIT) equals to L_NAME of record 1
4 reason: L_NAME (TONY) equals to F_NAME of record 1
record 3, 5 aren't in the result because there is no duplication in F_NAME or L_NAME columns for NORA,SMITH, ROSS, TAM
The table contains 10 million records, i really need to consider the performance.
kindly suggest me the solutionNote: Forum members please suggest better approach to this -- below.. convert into SQL :)
I know I will be opposed by many people in this forum for posting such in-efficient solution.
But trying to learn along with you.. its an interesting problem which must deal with all rows vs all rows to get all combinations.
But I am still thinking how to write it in SQL, probably will learn from this post after we receive some good SQL solution for the code what I am currently doing now.
step 1: created a table B similar to table A and added a column reason
CREATE TABLE B
ID NUMBER(10),
F_NAME VARCHAR2(100 BYTE),
L_NAME VARCHAR2(100 BYTE),
REASON VARCHAR2(1000 BYTE) --- ADDED THIS
)Definetely inefficient :(
BEGIN
FOR rec_outer IN (SELECT * FROM A) LOOP
FOR rec_inner IN (SELECT * FROM A) LOOP
IF (rec_outer.f_name = rec_inner.l_name) THEN
UPDATE B
SET reason =
rec_outer.id
|| ' reason: F_NAME ('
|| rec_outer.f_name
|| ') equals to L_NAME of record '
|| rec_inner.id
WHERE b.id = rec_outer.id;
END IF;
END LOOP;
FOR rec_inner IN (SELECT * FROM A) LOOP
IF (rec_outer.l_name = rec_inner.f_name) THEN
UPDATE B
SET reason =
reason
|| CASE
WHEN reason IS NULL THEN
rec_outer.id || ' reason: '
ELSE
END
|| 'L_NAME ('
|| rec_inner.f_name
|| ') equals to F_NAME of record '
|| rec_inner.id
WHERE b.id = rec_outer.id;
END IF;
END LOOP;
END LOOP;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
rollback;
RAISE;
END;OUTPUT:
ID F_NAME L_NAME REASON
1 TONY SUMIT 1 reason: F_NAME (TONY) equals to L_NAME of record 4,L_NAME (SUMIT) equals to F_NAME of record 2
2 SUMIT KEITH 2 reason: F_NAME (SUMIT) equals to L_NAME of record 1
3 NORA SMITH
4 APRIL TONY 4 reason: L_NAME (TONY) equals to F_NAME of record 1
5 ROSS TAM Cheers,
Manik.
Edited : Added rollback -
How to display rows of data into different columns?
I'm new to SQL and currently this is what I'm trying to do:
Display multiple rows of data into different columns within the same row
I have a table like this:
CREATE TABLE TRIPLEG(
T# NUMBER(10) NOT NULL,
LEG# NUMBER(2) NOT NULL,
DEPARTURE VARCHAR(30) NOT NULL,
DESTINATION VARCHAR(30) NOT NULL,
CONSTRAINT TRIPLEG_PKEY PRIMARY KEY (T#, LEG#),
CONSTRAINT TRIPLEG_UNIQUE UNIQUE(T#, DEPARTURE, DESTINATION),
CONSTRAINT TRIPLEG_FKEY1 FOREIGN KEY (T#) REFERENCES TRIP(T#) );
INSERT INTO TRIPLEG VALUES( 1, 1, 'Sydney', 'Melbourne');
INSERT INTO TRIPLEG VALUES( 1, 2, 'Melbourne', 'Adelaide');
The result should be something like this:
> T# | ORIGIN | DESTINATION1 | DESTINATION2
> 1 | SYDNEY | MELBORUNE | ADELAIDE
The query should include the `COUNT(T#) < 3` since I only need to display the records less than 3. How can I achieve the results that I want using relational views???
Thanks!!!T#
LEG#
DEPARTURE
DESTINATION
1
1
Sydney
Melbourne
1
2
Melbourne
Adelaide
1
3
Adelaide
India
1
4
India
Dubai
2
1
India
UAE
2
2
UAE
Germany
2
3
Germany
USA
On 11gr2, you may use this :
SELECT t#,
REGEXP_REPLACE (
LISTAGG (departure || '->' || destination, ' ')
WITHIN GROUP (ORDER BY t#, leg#),
'([^ ]+) \1+',
'\1')
FROM tripleg
where leg#<=3
GROUP BY t#;
Output:
1 Sydney->Melbourne->Adelaide->India
2 India->UAE->Germany->USA
Cheers,
Manik.
Maybe you are looking for
-
Downloaded ios7, but unable to install. Stops at verifying update
I have downloaded ios 7, but after I agree to the terms and conditions, I get an error message that reads " Unable to install"" I have turned phone off and back on. I have deleted almost everything on my phone. This error message is NOT telling me
-
Can we publish to web portal?
hi all, can we publish reports and dashboards to web portal if so how ? please give some information on this. thanks kapil.
-
Material Replication from Backend: DNL_CUST_PROD0 is stuck in SMQ2
Hi Experts, I am getting this error while running R3AS for DNL_CUST_PROD0 adapter and checking the SMQ2 is getting into SYSFAIL status. The detail error says "Incorrect parameter with CALL FUNCTION" for Function Module BAPI_CRM_SAVE Even, adapter DNL
-
Hello, I have deployed the tables, external tables, dimensions and sequences successfully. I was now going to deploy my cube and then my mappings. When deploying my cube I get an error saying: French: ORA-06510: PL/SQL : exception définie par l'utili
-
How to export installed plugins, scripts and preferences from AE CC to AE CC 2014?
There is a method to export installed scripts, plugins (e.g. Red Giant Trapcode Particular) and preferences (e.g. workspace) from After Effects CC to After Effects CC 2014?