Rows to columns in sql
Hi,
How can i convert rows to column in sql
I have table with the two columns child_table_name and parent_table_name as below. How can convert the below table to the expected output. show all the child and corresponding parent_table in one row. Please help to write sql
Child_table_Name Parent_Table_name
abc bbb
abc aaa
def ccc
def ttt
Expected Output
abc bbb aaa
def ccc ttt
Thanks,
Ch
Hi,
That's called a Pivot, and here's one way to do it:
WITH got_r_num AS
SELECT child_table_name
, parent_table_name
, ROW_NUMBER () OVER ( PARTITION BY child_table_name
ORDER BY parent_table_name
) AS r_num
FROM table_x
SELECT *
FROM got_r_num
PIVOT ( MAX (parent_table_name)
FOR r_num IN ( 1 AS parent_1
, 2 AS parent_2
, 3 AS parent_3
The forum FAQ has a page devoted to pivots:
https://forums.oracle.com/message/9362005#9362005
The query above can show up to 3 parents per child. If you know you'll never have more than 2 (as in your message) then you don't need the line that defines parent_3. On the other hand, if you might need more than 3 parents, you can add as many more as you need.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Point out where the statement above is getting the wrong results, and explain, using specific examples, how you get the right results from the given data in those places. Remember that there is no built-in order to the rows in a table, so if your explanationuses words like "first" or "latest", define what they mean in terms of the data in your table.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002
Similar Messages
-
How to convert rows to columns in sql server 2008
How to convert rows to columns in sql server 2008 using the GROUP BY function? (only one query allowed)
Lookup the Pivot transformation. From BOL:
The Pivot transformation makes a normalized data set into a less normalized
but more compact version by pivoting the input data on a column value. For
example, a normalized Orders data set that lists customer name, product, and quantity purchased typically has multiple rows for any customer who purchased multiple products, with each row for that customer showing order
details for a different product. By pivoting the data set on the product column, the Pivot transformation can output a data set with a
single row per customer. That single row lists all the purchases by the customer, with the product names shown as column names, and the quantity shown as a value in the product column. Because not every customer purchases every product, many columns may contain
null values.
When a dataset is pivoted, input columns perform different roles in the pivoting process. A column can participate in the following ways:
The column is passed through unchanged to the output. Because many input rows
can result only in one output row, the transformation copies only the first
input value for the column.
The column acts as the key or part of the key that identifies a set of
records.
The column defines the pivot. The values in this column are associated with
columns in the pivoted dataset.
The column contains values that are placed in the columns that the pivot
creates.
Paul -
Selecting rows as columns in sql table
i have sql table like
currcode currdesc mth yr rate
SGD SINGAPORE DOLLAR 01 2013 .02
SGD SINGAPORE DOLLAR 09 2013 .02 (suppose have rates only for jan and sept )
RMB CHINESE RENMINBI 01 2013 .206
RMB CHINESE RENMINBI 02 2013 .207
For each currency rates for 12 months for every year
i want to show like (user will select the year)
currcode currdesc Jan Feb Mar Apr May Jun Jul Aug
Sept oct nov Dec
SGD SINGAPORE DOLLAR .02
.02
RMB CHINESE RENMINBI .206 .207
h2007you can use either of the below
1. Using PIVOT operator
SELECT currcode,
currdesc,
Yr,
[01] AS Jan,
[02] AS Feb,
[03] AS Mar,
[11] AS Nov,
[12] AS Dec
FROM Table t
PIVOT (MAX(rate) FOR mth IN ([01],[02],[03],[04],..,[11],[12]))p
2. using classical cross tab logic
SELECT currcode,
currdesc,
yr,
MAX(CASE WHEN mth = '01' THEN rate END) AS Jan,
MAX(CASE WHEN mth = '02' THEN rate END) AS Feb,
MAX(CASE WHEN mth = '03' THEN rate END) AS Mar,
MAX(CASE WHEN mth = '11' THEN rate END) AS Nov,
MAX(CASE WHEN mth = '12' THEN rate END) AS Dec
FROM table
GROUP BY currcode,currdesc,yr
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
Thank u for helping. Your 2nd solution working great. But using Pivot table giving me 2 rows,
RMB CHINESE RENMINBI
2013 NULL
NULL NULL
0.206 NULL NULL
RMB CHINESE RENMINBI
2013 NULL
NULL NULL
NULL NULL
0.207
h2007
Do you've any additional columns you've not shown in the post above?
to change NULLs to 0 use this
SELECT currcode,
currdesc,
yr,
MAX(CASE WHEN mth = '01' THEN rate ELSE 0.00 END) AS Jan,
MAX(CASE WHEN mth = '02' THEN rate ELSE 0.00 END) AS Feb,
MAX(CASE WHEN mth = '03' THEN rate ELSE 0.00 END) AS Mar,
MAX(CASE WHEN mth = '11' THEN rate ELSE 0.00 END) AS Nov,
MAX(CASE WHEN mth = '12' THEN rate ELSE 0.00 END) AS Dec
FROM table
GROUP BY currcode,currdesc,yr
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Convert rows to columns in sql database
Hi Team,
I have a table called as ABC in test schema which have got 3 columns
ABC
COL1 VARCHAR2(10)
COL2 VARCHAR2(10)
COL3 VARCHAR2(10)
The dat in ABC table is as follows
ABC
COL1 COL2 COL3
A B C
I wanted to write a sql query which will give me
COL
A
B
C
Appreciate your help on the above?
Thanks & Regards,
Thakur Manoj RGurjeet wrote:
with t as ( select deptno ||',' || dname || ',' || loc as abc from dept where deptno =10)
select regexp_substr(abc,'[^,]+', 1, level) from t
connect by regexp_substr(abc, '[^,]+', 1, level) is not null
That is a completely wrong answer.
The OP was not asking how to split a comma seperated string, he was asking how to unpivot individual columns to a single column.
That can be achieved using the UNPIVOT functionality in SQL, if the database version supports it, or if not something as simple as:
SQL> ed
Wrote file afiedt.buf
1 with t as (select 'A' as col1, 'B' as col2, 'C' as col3 from dual union all
2 select 'X','Y','Z' from dual)
3 --
4 -- end of test data
5 --
6 select decode(rn,1,col1,2,col2,col3) as col
7 from t
8* cross join (select rownum rn from dual connect by rownum <= 3)
SQL> /
C
A
X
B
Y
C
Z
6 rows selected. -
Convert Rows to Columns In Sql Server
If my Table look something like this
Create Table #Temp(Id Int, Name VarChar(20), Value VarChar(20))
Insert Into #Temp Values(1, 'Name','George')
Insert Into #Temp Values(1, 'ShoeSize','9.5')
Insert Into #Temp Values(1, 'Name','Gkjdk')
Insert Into #Temp Values(1, 'ShoeSize','8.9')
Insert Into #Temp Values(2, 'Name','Bill')
Insert Into #Temp Values(2, 'ShoeSize','10.5')
Insert Into #Temp Values(3, 'Name','John')
Insert Into #Temp Values(3, 'ShoeSize','9')
Insert Into #Temp Values(4, 'Name','Greg')
Insert Into #Temp Values(4, 'ShoeSize','9')
and its output is like this
id name value
1 Name George
1 Shoesize 9.5
1 Name Gkjdk
1 Shoesize 8.9
2 Name Bill
2 Shoesizr 10.5
I want my result in this format
id Name Shoesize
1 George 9.5
1 Gkjdk 8.9
2 Bill 10.5
I tried pivot function but it will not work it only first row for id 1 bcoz of aggregate function used and i also used group by that also nt work if any one has suggesstions plz help.
Select Id,
Min(Case When Name = 'Name' Then Value End) As Name,
Min(Case When Name = 'ShoeSize' Then Value End) As ShoeSize
From #Temp
Group By Id
Id is not the primary key my scenario is something like that but that actual data is not like thatHello ,
A common scenario where PIVOT can be useful is when you want to generate cross-tabulation reports to summarize data. For example, suppose you want to query the
PurchaseOrderHeader table in the
AdventureWorks2008R2 sample database to determine the number of purchase orders placed by certain employees. The following query provides this report, ordered by vendor.
Copy
USE AdventureWorks2008R2;
GO
SELECT VendorID, [250] AS Emp1, [251] AS Emp2, [256] AS Emp3, [257] AS Emp4, [260] AS Emp5
FROM
(SELECT PurchaseOrderID, EmployeeID, VendorID
FROM Purchasing.PurchaseOrderHeader) p
PIVOT
COUNT (PurchaseOrderID)
FOR EmployeeID IN
( [250], [251], [256], [257], [260] )
) AS pvt
ORDER BY pvt.VendorID;
Here is a partial result set.
VendorID Emp1 Emp2 Emp3 Emp4 Emp5
1492 2 5 4 4 4
1494 2 5 4 5 4
1496 2 4 4 5 5
1498 2 5 4 4 4
1500 3 4 4 5 4
The results returned by this subselect statement are pivoted on the
EmployeeID column.
Ref : MSDN
Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/ -
How to convert rows into columns in sql server?
Hi All,
I have table called table1 which contains the below information
Projectname Weeks Work
p1 w5 200
p1 w6 300
p1 w7 234
p2 w5 765
p2 w6 987
p3 w1 976
p3 w2 231
I need to pivot this table. I need the info like below
Projectname w1 w2 w5 w6
w7
p1
200 300 234
p2
765 987
p3 976 231
How can I make like this?One more way,
create table #temp(Projectname varchar(10),Weeks varchar(10), Work int)
insert into #temp values('p1','w5',200)
insert into #temp values('p1','w6',300)
insert into #temp values('p1','w7',234)
insert into #temp values('p2','w5',765)
insert into #temp values('p2','w6',987)
insert into #temp values('p3','w1',976)
insert into #temp values('p3','w2',231)
Select ProjectName,
Sum(Case when Weeks = 'W1' Then Work Else NULL End) W1,
Sum(Case when Weeks = 'W2' Then Work Else NULL End) W2,
Sum(Case when Weeks = 'W3' Then Work Else NULL End) W3,
Sum(Case when Weeks = 'W4' Then Work Else NULL End) W4,
Sum(Case when Weeks = 'W5' Then Work Else NULL End) W5,
Sum(Case when Weeks = 'W6' Then Work Else NULL End) W6,
Sum(Case when Weeks = 'W7' Then Work Else NULL End) W7
From #temp
Group by ProjectName
Drop table #temp -
Transposing SQL rows to columns
Hi All -
I have a query which returns result set as follows:
year amt_type amount
2001 vacation 1000
2001 medical 1000
2001 college 15000
2002 vacation 800
2002 medical 1000
2002 college 10000
2003 vacation 400
2003 medical 2000
2003 college 80000.
I am trying to make the years 2001, 2002, and 2003 as columns and trying to
achieve the below output
Amt type 2001 2002 2003
vacation 1000 800 400
medical 1000 1000 2000
college 15000 10000 8000
I am able to achieve this perfectly on client side. Right now I am trying to
achieve the same through using SQL. I am using
DECODE to achieve but my result set looks like below
Amt type 2001 2002 2003
vacation 1000
vacation 800
vacation 400
medical 1000
medical 1000
medical 2000
college 15000
college 10000
college 8000
I am trying this on oracle. I am new to this concept. can anyone who worked in
similar situation help me. Also, the years may change depending upon the dropdown
selection on client page. Can I transpose rows to columns in SQL for dynamic
values
Thankswith t as (
select 2001 year,'vacation' amt_type,1000 amount from dual union all
select 2001,'medical',1000 from dual union all
select 2001,'college',15000 from dual union all
select 2002,'vacation',800 from dual union all
select 2002,'medical',1000 from dual union all
select 2002,'college',10000 from dual union all
select 2003,'vacation',400 from dual union all
select 2003,'medical',2000 from dual union all
select 2003,'college',80000 from dual
select amt_type,
sum(case year when 2001 then amount end) "2001",
sum(case year when 2002 then amount end) "2002",
sum(case year when 2003 then amount end) "2003"
from t
group by amt_type
AMT_TYPE 2001 2002 2003
medical 1000 1000 2000
college 15000 10000 80000
vacation 1000 800 400
SQL> SY. -
Convert rows into columns nad vice versa in 10g
how to convert rows into columns in 10g??
Qwerty wrote:
see below for rows to column case
SQL> WITH t as
2 (
3 SELECT 'US' test_string FROM DUAL UNION
4 SELECT 'AMERICA' FROM DUAL UNION
5 SELECT'HOLLYWOOD' FROM DUAL UNION
6 SELECT 'WASHINGTON' FROM DUAL
7 )
8 select ltrim (sys_connect_by_path(test_string,','),',') test_string
9 from (
10 SELECT row_number() over(order by test_string) rno, test_string
11 FROM t)
12 WHERE connect_by_isleaf = 1 and rownum=1
13 connect by rno = prior rno+1;
TEST_STRING
AMERICA,HOLLYWOOD,US,WASHINGTONI hope you can do it for column to rows now.That's not really rows to columns. That's rows to a column, which is more commonly called string aggregation.
Rows to columns (or pivot) is more like:
SQL> ed
Wrote file afiedt.buf
1 WITH t as
2 (
3 SELECT 'US' test_string FROM DUAL UNION
4 SELECT 'AMERICA' FROM DUAL UNION
5 SELECT'HOLLYWOOD' FROM DUAL UNION
6 SELECT 'WASHINGTON' FROM DUAL
7 )
8 --
9 select max(decode(rn,1,test_string)) as col_1
10 ,max(decode(rn,2,test_string)) as col_2
11 ,max(decode(rn,3,test_string)) as col_3
12 ,max(decode(rn,4,test_string)) as col_4
13* from (select test_string, row_number() over (order by test_string) as rn from t)
SQL> /
COL_1 COL_2 COL_3 COL_4
AMERICA HOLLYWOOD US WASHINGTON
SQL>And columns to rows (or unpivot) is like:
SQL> ed
Wrote file afiedt.buf
1 WITH t as
2 (
3 SELECT 'US' col_1, 'AMERICA' col_2, 'HOLLYWOOD' col_3, 'WASHINGTON' col_4 FROM DUAL
4 )
5 --
6 select col_1 as col from t union all
7 select col_2 from t union all
8 select col_3 from t union all
9* select col_4 from t
SQL> /
COL
US
AMERICA
HOLLYWOOD
WASHINGTONor...
SQL> ed
Wrote file afiedt.buf
1 WITH t as
2 (
3 SELECT 'US' col_1, 'AMERICA' col_2, 'HOLLYWOOD' col_3, 'WASHINGTON' col_4 FROM DUAL
4 )
5 --
6 select decode(rownum,1,col_1,2,col_2,3,col_3,4,col_4) as col
7* from t, (select * from dual connect by rownum <= 4)
SQL> /
COL
US
AMERICA
HOLLYWOOD
WASHINGTON
SQL> -
User require a report having the following column data should be populated in column instead of row.
how can i modify or where should i modify to get the required output below. the following query is in XML file
select awd.award_id,
award_number,
bond_name,
p2b.bond_id bond_id,
nvl(b.par_amount,0)+nvl(b.premium,0)+nvl(b.original_issue_discount,0)+nvl(b.bic,0) Total_proceeds,
p2b.earnings_proceeds earning_procs,
nvl(b.original_issue_discount,0)+nvl(b.bic,0) issuance_cost
FROM xxdl.xxdl_cd_bond_setup_new b,
(select bond_id,
effective_date,nvl(earnings_proceeds,0) earnings_proceeds
from (
select s.*,
row_number() over(partition by bond_id order by effective_date desc) rn
from XXDL.xxdl_cd_bond_schedk_p2b s
where rn = 1) p2b,
gms_awards_all awd
WHERE b.bond_id= p2b.bond_id(+)
AND b.award_id = awd.award_id(+)
AND b.award_id = decode(:P_award_num,null,b.award_id,:P_award_num)
Actual output
award_id award_number bond_name bond_id Total_proceeds issuance_cost
345 XI ABC null 100 40
234 XIIA DEF null 86 100
Expected output
345 234
XI XIIA
ABC DEF
null null
100 86
40 100Edited by: 893185 on Nov 9, 2011 4:14 PM4. How do I convert rows to columns?
SQL and PL/SQL FAQ -
Can anybody help....SQL to display row as column and column as rows
Can anybody help in writing a SQL to display row as column and column as rows?
Thankscheck this link:
Re: Creating Views - from rows to a new column? -
Converting rows to columns using t-sql
Hi All,
I have a table with 3 columns, let say ID1 , ID2, Flag
My Source data looks like this..
ID1 ID2 Flag
1 1 0
1 2 0
1 3 0
2 7 0
2 8 1
2 9 0
4 5 0
Now My output should look like this..
ID1 Newcol1 NewFlag1 Newcol2 NewFlag2 Newcol3 NewFlag3
1 1 0
2 0 3
0
2 7 0
8 1 9
0
4 5 0
null null null null
Basically I want to convert rows to columns and to get above output I need t-SQL query.
Thanks in advance
RH
sqlYou can do it by this query:
declare @table table ( ID1 int, ID2 int, Flag int)
insert @table values ( 1,1,0 ),( 1,2,0 ),( 1,3,0 ),( 2,7,0 ),( 2,8,1 ),( 2,9,0 ),( 4,5,0 )
WITH cte1
AS ( SELECT Id1 ,
ROW_NUMBER() over (partition by ID1 order by ID1 ) as Sequence ,
ID2 ,
Flag
FROM @table
cte2
AS ( SELECT Id1 ,
ColumnTitle + LTRIM(RTRIM(STR(Sequence))) AS ColumnTitle ,
ColumnData
FROM cte1 UNPIVOT ( ColumnData FOR ColumnTitle IN ( [ID2], [Flag] ) ) AS UP
SELECT Id1 ,
[ID21] FirstID2 ,
[Flag1] FirstFlag ,
[ID22] SecondID2 ,
[Flag2] SecondFlag ,
[ID23] ThirdID2 ,
[Flag3] ThirdFlag
FROM cte2 PIVOT ( MAX(ColumnData) FOR ColumnTitle IN ( [ID21],
[Flag1],
[ID22],
[Flag2],
[ID23],
[Flag3] ) ) PV
If you want to know more detail, please visit my old article about this method:
T-SQL: PIVOT Ordered pair Columns
T-SQL e-book by TechNet Wiki Community
My Blog
My Articles -
Referring to Cursor Row and Column in Dynamic SQL
I have a procedure that dynamically reads a schema name and table name from an input table. The code then needs to loop through all rows and columns of each table and output the data. I'm 95% done with what I want to accomplish, but there is one small bug. The line dbms_output.put(*col.column_name* || '',''); ' ||
should refer to something like rec.col.column_name so that it gets the column of the current record. Right now it just displays the column name for each record instead of the actual value. Can anyone help me tweak the code to get the actual value?
CREATE OR REPLACE PACKAGE BODY some_proc IS
-- Function and procedure implementations
PROCEDURE create_files IS
CURSOR c_tbls IS
SELECT * FROM tbl_list;
l_sql VARCHAR2(4000);
BEGIN
--Loop through all tables
FOR tbl IN c_tbls LOOP
l_sql := 'DECLARE ' || ' CURSOR c_tbl_recs IS ' || ' SELECT * ' ||
' FROM ' || tbl.schema_name || '.' || tbl.table_name || '; ' ||
' t_tbl_rowtype c_tbl_recs%ROWTYPE; ' || 'BEGIN ' ||
' FOR rec IN c_tbl_recs LOOP ' ||
' FOR col IN (SELECT column_name ' ||
' FROM dba_tab_cols ' ||
' WHERE owner = ''' || tbl.schema_name || '''' ||
' AND table_name = ''' || tbl.table_name || '''' ||
' ORDER BY column_id) LOOP ' ||
*' dbms_output.put(col.column_name || '',''); ' ||* ' END LOOP; dbms_output.put_line(''''); END LOOP; ' ||
'END; ';
--dbms_output.put_line(l_sql);
EXECUTE IMMEDIATE l_sql;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line(SQLERRM);
END;
END;Is it this what you are looking for?
(it took some minutes)
create or replace
package some_proc is
procedure create_files;
end;
CREATE OR REPLACE
PACKAGE BODY some_proc
IS
-- Function and procedure implementations
PROCEDURE create_files
IS
CURSOR c_tbls
IS
SELECT * FROM tbl_list;
CURSOR c_cols (p_table_owner VARCHAR2, p_table_name VARCHAR2)
IS
SELECT column_name
FROM all_tab_columns
WHERE owner =p_table_owner
AND table_name=p_table_name
ORDER BY all_tab_columns.column_id;
l_sql VARCHAR2(32000);
separator VARCHAR2(1):=';';
BEGIN
--Loop through all tables
FOR tbl IN c_tbls
LOOP
dbms_output.put_line('TABLE: '||tbl.schema_name||'.'||tbl.table_name);
l_sql := 'DECLARE ' ;
l_sql := l_sql|| ' CURSOR c_tbl_recs IS ' ;
l_sql := l_sql||' SELECT * FROM ' || tbl.schema_name || '.' || tbl.table_name || '; ' ;
l_sql := l_sql||' linenr number:=1; ';
l_sql := l_sql||'BEGIN ' ;
l_sql := l_sql|| ' FOR rec IN c_tbl_recs LOOP ';
FOR c IN c_cols(tbl.schema_name,tbl.table_name)
LOOP
l_sql:=l_sql ||' if linenr=1 then dbms_output.put('''||c.column_name||''||separator||'''); end if; ' ;
END LOOP;
l_sql :=l_sql||' dbms_output.put_line(''''); linenr:=linenr+1; ';
FOR c IN c_cols(tbl.schema_name,tbl.table_name)
LOOP
l_sql:=l_sql ||' dbms_output.put(rec.'||c.column_name||'||'''||separator||'''); ' ;
END LOOP;
l_sql:=l_sql||' end loop; ';
l_sql:=l_sql||' dbms_output.put_line(''''); ';
l_sql:=l_sql||' dbms_output.put_line(''''); ';
l_sql:=l_sql||'end;';
EXECUTE IMMEDIATE l_sql;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line(SQLERRM);
END;
END;
/ -
Row Selector column on Interactive Report
Hi all,
I have an interactive report based on a custom SQL query. How do I add a row selctor column so I cans select individual rows? I have also tried using a tabular form which also does not display a row selctor column. This is odd as my other tabular forms display a row selctor column.
Many thanks for you help,
ChrisChris,
Usually when someone wants a row selector, it's to choose a few rows by clicking a checkbox, then doing something with them. I'm guessing that's what you're looking for?
Martin Giffy D'Souza's [blog post|http://apex-smb.blogspot.com/2009/01/apex-report-with-checkboxes-advanced.html] explains one way to do that which should work for you. I haven't tried, it, but it looks pretty comprehensive.
Good luck,
Stew -
Hit the exception when editing the value of row key column in a new created row in a table
1. I created a view object with 2 entity objects (parent table: YARD_FIXED_SLOT - child table: YARD_FIXED_SLOT_DETAIL) and the primary key of child table composes of 2 columns ( one of them is FK: YardFixedSlotDetail.FIXED_SLOT_ID REFERENCES YARD_FIXED_SLOT(FIXED_SLOT_ID)
SQL queries:
SELECT YardFixedSlotDetail.FIXED_SLOT_ID,
YardFixedSlotDetail.MODIFIED_DT,
YardFixedSlotDetail.SLOT_FROM_N,
YardFixedSlotDetail.SLOT_TO_N,
YardFixedSlotDetail.USER_ID,
YardFixedSlot.BLOCK_M,
YardFixedSlot.BLOCK_N,
YardFixedSlot.FIXED_SLOT_ID AS FIXED_SLOT_ID1,
YardFixedSlot.SECTION_N,
YardFixedSlot.STATUS_C,
YardFixedSlot.TERMINAL_C
FROM YARD_FIXED_SLOT_DETAIL YardFixedSlotDetail, YARD_FIXED_SLOT YardFixedSlot
YardFixedSlotDetail.FIXED_SLOT_ID = YardFixedSlot.FIXED_SLOT_ID
2. I dragged this view object into JSF page as an ediable table and add 'add' button to add a new row to the table. and the handling logic in managed bean is as followed. now one new row can be added succesfully in the table.
public void processSlotDetailCreation(ActionEvent ae)
DCBindingContainer bindings = (DCBindingContainer)getBindings();
DCIteratorBinding dciter = bindings.findIteratorBinding("YardFixedSlotDetailFindAllByBlock1Iterator");
Row row = dciter.getCurrentRow();
//get the last row for the index and create a new row for the //user to edit
Row lastRow = dciter.getNavigatableRowIterator().last();
YardFixedSlotDetailFindAllByBlockRowImpl newRow = (YardFixedSlotDetailFindAllByBlockRowImpl)dciter.getNavigatableRowIterator().createRow();
newRow.setFixedSlotId(new Integer(21));
newRow.setUserId("adftest");
newRow.setModifiedDt(new Timestamp(System.currentTimeMillis()));
//bug exist here
newRow.setSlotFromN(new Integer(1));
//newRow.setSlotToN(new Integer(1));
newRow.setNewRowState(Row.STATUS_INITIALIZED);
int lastRowIndex = dciter.getNavigatableRowIterator().getRangeIndexOf(lastRow);
dciter.getNavigatableRowIterator().insertRowAtRangeIndex( lastRowIndex+1, newRow);
// make the new row the current row of the table
dciter.setCurrentRowIndexInRange(lastRowIndex);
dciter.setCurrentRowWithKey(newRow.getKey().toStringFormat(true));
//table should have its displayRow attribute set to //"selected"
// AdfFacesContext.getCurrentInstance().addPartialTarget(slotDetailsTable);
3. When filling in a new value for SlotFromN column (note that SlotFromN column and FixedSlotId column are the rowKey), hit the exception below:
[2013-12-04T13:04:28.866+08:00] [DefaultServer] [ERROR] [] [oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter] [tid: [ACTIVE].ExecuteThread: '14' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: <anonymous>] [ecid: eb5e281b-6b07-4c17-987e-049792c97dda-000001bf,0] [APP: YPCApp] [DSID: 0000KAvzIaA5qYWFLzmJOA1IbdqZ000003] ADF_FACES-60096:Server Exception during PPR, #7[[
oracle.jbo.InvalidOperException: JBO-29114 ADFContext is not setup to process messages for this exception. Use the exception stack trace and error code to investigate the root cause of this exception. Root cause error code is JBO-34014. Error message parameters are {0=oracle.jbo.Key[21 null ], 1=root}
at oracle.jbo.uicli.binding.JUCtrlHierBinding.bringNodeToRangeKeyPath(JUCtrlHierBinding.java:859)
at oracle.adfinternal.view.faces.model.binding.FacesCtrlHierBinding.bringNodeToRangeKeyPath(FacesCtrlHierBinding.java:122)
at oracle.adfinternal.view.faces.model.binding.RowDataManager.setRowKey(RowDataManager.java:131)
at oracle.adfinternal.view.faces.model.binding.FacesCtrlHierBinding$FacesModel.setRowKey(FacesCtrlHierBinding.java:951)
at org.apache.myfaces.trinidad.component.UIXCollection.setRowKey(UIXCollection.java:527)
at org.apache.myfaces.trinidad.component.UIXTable.setRowKey(UIXTable.java:760)
at oracle.adfinternal.view.faces.renderkit.rich.TableRendererUtils._processStampedChildrenForActiveRow(TableRendererUtils.java:2950)
at oracle.adfinternal.view.faces.renderkit.rich.TableRendererUtils.processFacetsAndChildrenForClickToEdit(TableRendererUtils.java:1604)
at oracle.adfinternal.view.faces.renderkit.rich.TableRenderer.processFacetsAndChildrenForClickToEdit(TableRenderer.java:352)
at oracle.adfinternal.view.faces.renderkit.rich.TableRenderer.decodeChildren(TableRenderer.java:193)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1347)
at org.apache.myfaces.trinidad.component.UIXCollection.processDecodes(UIXCollection.java:226)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXComponentBase.processDecodes(UIXComponentBase.java:1124)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXComponentBase.processDecodes(UIXComponentBase.java:1124)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXComponentBase.processDecodes(UIXComponentBase.java:1124)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXComponentBase.processDecodes(UIXComponentBase.java:1124)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXComponentBase.processDecodes(UIXComponentBase.java:1124)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXComponentBase.processDecodes(UIXComponentBase.java:1124)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXComponentBase.processDecodes(UIXComponentBase.java:1124)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXComponentBase.processDecodes(UIXComponentBase.java:1124)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXComponentBase.processDecodes(UIXComponentBase.java:1124)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at oracle.adf.view.rich.component.fragment.UIXRegion.decodeChildrenImpl(UIXRegion.java:605)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXComponentBase.processDecodes(UIXComponentBase.java:1124)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXComponentBase.processDecodes(UIXComponentBase.java:1124)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXComponentBase.processDecodes(UIXComponentBase.java:1124)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXComponentBase.processDecodes(UIXComponentBase.java:1124)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXComponentBase.processDecodes(UIXComponentBase.java:1124)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXComponentBase.processDecodes(UIXComponentBase.java:1124)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXForm.processDecodes(UIXForm.java:75)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildrenImpl(UIXComponentBase.java:1365)
at org.apache.myfaces.trinidad.component.UIXComponentBase.decodeChildren(UIXComponentBase.java:1351)
at org.apache.myfaces.trinidad.component.UIXComponentBase.processDecodes(UIXComponentBase.java:1124)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:933)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl$ApplyRequestValuesCallback.invokeContextCallback(LifecycleImpl.java:1574)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:416)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:225)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:341)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:192)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:106)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:478)
at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:478)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:303)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:208)
at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:137)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)
at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:460)
at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:120)
at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:217)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:81)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:225)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3367)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3333)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2220)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2146)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2124)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1564)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:295)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)
4. I think problem maybe is related with row key, but I need end user to change rowkey column value. does it allow changing the value of column as row key? I found this problem maybe only occur for new created row. For those existing rows, even I change the value of row key column, no such problem occurred, how do I handle this situation?
Appriciate if anybody can help.Hi Bangaram,
Thank you for your reply.
The error: "Root cause error code is JBO-34014. Error message parameters are {0=oracle.jbo.Key[21 null ], 1=root} "
I didn't create master records, I just used joint queries for information display of both master and detail. I am trying to create a row in the UI table to create a new detail record and master record already exists.
The row key for new added row in UI rich table is [21 null ], row key of detail records table composes of 2 columns. 21 is for FixedSlotId and null is for SlotFromN. when I provide a new value for SlotFromN column in UI rich table, problem will occur. -
Need help in displaying Rows to Columns
Hi,
I am facing problem in displaying Rows to Columns
I am using pivot function:
select *
from
(select vendor_name
from tablea)
pivot
(count(vendor_name)
for vendor_name in ('a,b,'c'));
its working fine showing vendor_name and count
but when i want to display the output as:(How to include the Salalry column in the query?)
Name:{a b c}
Sal Total:(400,600,800}
Any help will be needful for meNot sure what you mean:
select *
from (select deptno,sal from emp)
pivot(sum(sal) for deptno in (10,20,30))
10 20 30
8750 10875 9400
SQL> SY.
Maybe you are looking for
-
My iPad mini won't connect to wifi. Well it does but very sporadically.
-
How to implement If and then logic in Numbers?
Having looked in the formulas section of both teh Help and User guides I can see that it is possible to compare using the IF function...and that produces a True or False output...but any further than that and I am lost. i can't seem to find the 'THEN
-
Doubt on 'default' access modifier
How JRE access the main method even if the class has 'default' access. ie, following run without declaring the class as public. As per my understanding only classes in the same package access the method. Is the 'default' package belong to JRE ? class
-
Captivate 8: How to add a button onto a question slide to invoke some java script?
I have some question slides where the user has to guess an item on a picture. Because the picture is very small, I want to add a zoom button which calls a function in my LMS to popup the picture in a bigger window. I could not find a way to add a but
-
Help needed - JavaBeans in forms
Hi there - can anyone out there help me with this? As part of a new project, I'll be trying to implement a JavaBean in a form; specifically, I'll be implementing the multi-select tlist bean. This is not something I've done before, so I'd be grateful