PL/SQL muliple row insert for a single row
I need to insert multiple rows based on a single row record. Below are the table structures and sample data
CREATE TABLE TEST_SAMPLE (NAME VARCHAR2(20), ATTR_1 VARCHAR2(20), ATTR_2 VARCHAR2(20), ATTR_3 VARCHAR2(20),ATTR_4 VARCHAR2(20));
CREATE TABLE TRANSACTION (NAME VARCHAR2(20), ATTR VARCHAR2(20))
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('hello','asd','fgh','ert',null);For the above record in table TEST_SAMPLE, three records have to be populated\inserted into table TRANSACTION. In PL/SQL
stored procedure i am inserting records to TRANSACTION when ATTR_1 or ATTR_2 or ATTR_3 or ATTR_4 is not null.
Please help me to find a better way for the above insert to table TRANSACTION?
Thanks for helping me here. For the sample record in table TEST_SAMPLE i mentioned above three records need to be inserted in table TRANSACTION. you have this, or?
CREATE TABLE TEST_SAMPLE (NAME VARCHAR2(20), ATTR_1 VARCHAR2(20), ATTR_2 VARCHAR2(20), ATTR_3 VARCHAR2(20),ATTR_4 VARCHAR2(20));
CREATE TABLE TEST_TRANSACTION (NAME VARCHAR2(20), ATTR VARCHAR2(20));
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 1','asd','fgh','ert',null);
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 2',null,'fgh','ert',null);
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 3','asd',null,'ert',null);
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 4','asd','fgh',null,null);
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 5','asd',null,null,null);
insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('record 6',null,null,null,null);
commit;
insert into TEST_TRANSACTION
select NAME,
ATTR_1
from TEST_SAMPLE
where ATTR_1 is not null
union all
select NAME,
ATTR_2
from TEST_SAMPLE
where ATTR_2 is not null
union all
select NAME,
ATTR_3
from TEST_SAMPLE
where ATTR_3 is not null
union all
select NAME,
ATTR_4
from TEST_SAMPLE
where ATTR_4 is not null
commit;
select *
from TEST_TRANSACTION
order by 1;
Table created.
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
Commit complete.
10 rows created.
Commit complete.
NAME ATTR
record 1 asd
record 1 fgh
record 1 ert
record 2 fgh
record 2 ert
record 3 ert
record 3 asd
record 4 fgh
record 4 asd
record 5 asd
10 rows selected.
Similar Messages
-
How to aggregate a column based date column (for weekly single row)?
How to aggregate a column based date column (for weekly single row)?
Hi,
Consider the below statement for daily bases which is ok
SELECT ID, DATE, SUM(AMOUNT) FROM TABLE_NAME GROUP BY ID, DATE ORDER BY ID, DATE
The same like the above statement, I want output on weekly, fortnightly, and monthly bases, How to do this? Need your help... -
Merging multiple rows in to a single row (when rows meet merging criteria)
Hi
I have a scenario to merge multiple rows in to a single rows when the data in those rows fall in merge criteria .Below is how my data is
Now the merging logic for the above rows is , we need to combine multiple rows in to a single row when the data in those rows permits us to do in that way. Simply saying , its like sandwich where we combine multiple things to a single piece.The output for
the above rows should be
Here we combined Row 1 ,2, 3 in to a single row as the data in those rows permits to merge in to single row. But the row 4 cannot be combined to any of those rows because the data in those rows doesn't permits us do a merge ( As the value of the column
JobSource for the row 4 is different from the other rows ) .
My original data has 56 columns , but for readability i kept only 9 columns.
can you please throw some idea on how to achieve this scenario. I know we need to use CTE for achieving this, but i am not able succeed in doing an iteration on multiple rows.
Appreciate your response .Thanks for your reply .
Rule for merging is simple . First of all there is no unique row identifier for each row , the fact table is not having an identity column in the database . I called row 1 , row 2 etc in my post above only to make better explanation of my scenario.
The rule for merge is below.
1) we can combine only when the data in a column for one row is null & the data in same column for the other row is not null . It should also satisfy the condition where the data in other columns should conflict each other.
2) Data for all columns for the merging rows should not be conflicting (i.e. we should not merge the rows when the data in a column is not equal to the same column in the other row
,considering not null value)
Steps in merging the above source data :
1) Consider the case of row 1 and row 2 in the source, we can combine these rows as the data is satisfying the rule 1 for columns (Jobsource,Flight, Package,Update,Iscancelled
,Result, Severity) and columns (JobID and RuleName ) fall under rule 2. we merge these two rows in to a single row and keep in that in the table.
2) Then the resulting row is again merged with the second row which is present above by applying the rule 1 and rule 2 . Below would be output of merge operation.
Now there would be only two rows in the output . But these rows cannot be merged as the data doesn't satisfy the merge rules 2 . As Jobsource for the row 1 in the above output is "PresubmissionSource" which is not equal
to "PostSubmission" jobSource which is in row 2. So these two rows are left unmerged .So the above two rows would be the output of merge operation on my source data.
This process has to be repeated for all the rows in the table. As of now my table as 92 Million rows with 56 columns which need to be considered for merging rows. I replicated my scenario in 9 columns and 4 rows to understand better. -
SQL*Plus two fetches for getting one row.
Hi all.
I have tested following script.
alter session set events '10046 trace name context forever, level 12';
select * from dual;And achieved such results (extract from .trc file).
SQL*Plus: Release 11.2.0.1.0; (Oracle Version 10.2.0.4.0, 11.2.0.1.0)
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 0.00 0.00 0 0 0 1
total 4 0.00 0.00 0 0 0 1SQL*Plus: Release 8.1.7.0.0; (Oracle Version 8.1.7.0.0)
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 2 0.00 0.00 0 0 0 0
Fetch 2 0.00 0.00 0 1 4 1
total 5 0.00 0.00 0 1 4 1Allround Automations PL/SQL Developer 8.0.4; (Oracle Version 10.2.0.4.0, 11.2.0.1.0)
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 0 0 1
total 3 0.00 0.00 0 0 0 1Allround Automations PL/SQL Developer 8.0.4; (Oracle Version 8.1.7.0.0)
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 1 4 1
total 3 0.00 0.00 0 1 4 11) I can't figure out why sqlplus does TWO fetches for getting ONE row (instead of pl/sql developer).
8i raw trace
PARSING IN CURSOR #1 len=31 dep=0 uid=0 oct=3 lid=0 tim=0 hv=3549852361 ad='4a0155c'
select 'hello world' from dual
END OF STMT
PARSE #1:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=0
BINDS #1:
EXEC #1:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=0
WAIT #1: nam='SQL*Net message to client' ela= 0 p1=1111838976 p2=1 p3=0
FETCH #1:c=0,e=0,p=0,cr=1,cu=4,mis=0,r=1,dep=0,og=4,tim=0
WAIT #1: nam='SQL*Net message from client' ela= 0 p1=1111838976 p2=1 p3=0
FETCH #1:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=0
WAIT #1: nam='SQL*Net message to client' ela= 0 p1=1111838976 p2=1 p3=0
WAIT #1: nam='SQL*Net message from client' ela= 0 p1=1111838976 p2=1 p3=0
STAT #1 id=1 cnt=1 pid=0 pos=0 obj=195 op='TABLE ACCESS FULL DUAL '11g raw trace
PARSING IN CURSOR #3 len=30 dep=0 uid=96 oct=3 lid=96 tim=1581355246985 hv=1158622143 ad='b8a1bcdc' sqlid='5h2yvx92hyaxz'
select 'hello world' from dual
END OF STMT
PARSE #3:c=0,e=130,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=1388734953,tim=1581355246984
EXEC #3:c=0,e=40,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=1388734953,tim=1581355247154
WAIT #3: nam='SQL*Net message to client' ela= 7 driver id=1111838976 #bytes=1 p3=0 obj#=-1 tim=1581355247252
FETCH #3:c=0,e=18,p=0,cr=0,cu=0,mis=0,r=1,dep=0,og=1,plh=1388734953,tim=1581355247324
STAT #3 id=1 cnt=1 pid=0 pos=1 obj=0 op='FAST DUAL (cr=0 pr=0 pw=0 time=0 us cost=2 size=0 card=1)'
WAIT #3: nam='SQL*Net message from client' ela= 193 driver id=1111838976 #bytes=1 p3=0 obj#=-1 tim=1581355247735
FETCH #3:c=0,e=2,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,plh=1388734953,tim=1581355247800
WAIT #3: nam='SQL*Net message to client' ela= 5 driver id=1111838976 #bytes=1 p3=0 obj#=-1 tim=15813552478552) Is there any possibility to view data provided by each fetch?
Thanks in advance!
P.S.
SQL> sho arraysize
arraysize 15Thanks.
I have tested two statements.
select 'hello world' from dual where 1=1;
select 'hello world' from dual where 1=0;When query returns no data, there is only one SQL*Net roundtrip (and one fetch)
SQL> set autot on statistics
SQL> select 'hello world' from dual where 1=1;
'HELLOWORLD
hello world
Statistics
0 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
528 bytes sent via SQL*Net to client
492 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> select 'hello world' from dual where 1=0;
no rows selected
Statistics
0 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
329 bytes sent via SQL*Net to client
481 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processedBut in both cases i found in client trace this sequence of bytes:
] nsprecv: 00 00 36 01 00 00 00 00 |..6.....|
] nsprecv: 00 00 00 00 00 00 00 00 |........|
] nsprecv: 00 00 90 19 43 13 00 00 |....C...|
] nsprecv: 00 00 00 00 00 00 00 00 |........|
] nsprecv: 00 00 00 00 00 00 00 00 |........|
] nsprecv: 00 00 00 00 00 00 00 00 |........|
] nsprecv: 00 00 00 00 00 00 00 00 |........|
] nsprecv: 00 00 00 00 00 00 00 00 |........|
] nsprecv: 00 00 00 00 00 00 00 00 |........|
] nsprecv: 00 00 00 00 00 00 00 00 |........|
] nsprecv: 00 00 19 4F 52 41 2D 30 |...ORA-0|
] nsprecv: 31 34 30 33 3A 20 6E 6F |1403:.no|
] nsprecv: 20 64 61 74 61 20 66 6F |.data.fo|
] nsprecv: 75 6E 64 0A |und. |In first case - it was in 2nd packet and in second case (query returns no data) - part of 1st packet. -
How to add mouse listener for a single row alone
I have a requirement. In a JTable when I double click a particular row the cells in the row should set to the width which I have provided.
The problem with my code is when I click fourth row in the table, the first row gets adjusted.
So how I need help is
only if I click the first row, the first row cell size should get adjusted not when I click fourth row.
Similarly if I give some cell width and height for fourth row cells, then when I double click the fourth row, the fourth should alone get adjusted and not the other rows.
Hope I have explained clearly.
How can it be achieved?
Please find below my code. Everything is hardcoded. So it may look messy. Please excuse.
// Imports
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
class SimpleTableExample extends JFrame {
// Instance attributes used in this example
private JPanel topPanel;
private JTable table;
private JScrollPane scrollPane;
String data1 = "";
String data2 = "123456789ABCDEFGHIJKLMNOPQRSTUVQWXYZabcdefghijklmnopqrstuvwxyzaquickbrownfoxjumpedoverthelazydog";
int size = data2.length();
// Constructor of main frame
public SimpleTableExample() {
// Set the frame characteristics
setTitle("Simple Table Application");
setSize(400, 200);
setBackground(Color.gray);
// Create a panel to hold all other components
topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
getContentPane().add(topPanel);
// Create columns names
String columnNames[] = { "SEL", "DESIGN DATA", "PART NUMBER" };
// Create some data
String dataValues[][] = { { data1, data2, "67", "77" },
{ "", "43", "853" }, { "", "89.2", "109" },
{ "", "9033", "3092" } };
DefaultTableModel model = new DefaultTableModel(dataValues, columnNames);
model.addColumn("PART TITLE");
model.addColumn("SPECIAL INSTRUCTIONS");
table = new JTable(model) {
public boolean isCellEditable(int rowIndex, int colIndex) {
return false;
// set specific row height
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
int colInd = 0;
TableColumn col = table.getColumnModel().getColumn(colInd);
int width = 50;
col.setPreferredWidth(width);
int colInd2 = 1;
TableColumn col2 = table.getColumnModel().getColumn(colInd2);
int width2 = 100;
col2.setPreferredWidth(width2);
int colInd3 = 2;
TableColumn col3 = table.getColumnModel().getColumn(colInd3);
int width3 = 10;
col3.setPreferredWidth(width3);
int colInd4 = 3;
TableColumn col4 = table.getColumnModel().getColumn(colInd4);
int width4 = 10;
col4.setPreferredWidth(width4);
int colInd5 = 4;
TableColumn col5 = table.getColumnModel().getColumn(colInd5);
int width5 = 10;
col5.setPreferredWidth(width5);
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
JTable target = (JTable) e.getSource();
int row = target.getSelectedRow();
int column = target.getSelectedColumn();
TableColumn col1 = table.getColumnModel().getColumn(0);
col1.setPreferredWidth(50);
TableColumn col2 = table.getColumnModel().getColumn(1);
col2.setPreferredWidth(400);
table.getColumnModel().getColumn(1).setCellRenderer(
new TableCellLongTextRenderer());
table.setRowHeight(50);
TableColumn col5 = table.getColumnModel().getColumn(4);
col5.setPreferredWidth(200);
// Create a new table instance
// table = new JTable(dataValues, columnNames);
// Add the table to a scrolling pane
scrollPane = new JScrollPane(table);
topPanel.add(scrollPane, BorderLayout.CENTER);
// Main entry point for this example
public static void main(String args[]) {
// Create an instance of the test application
SimpleTableExample mainFrame = new SimpleTableExample();
mainFrame.setVisible(true);
class TableCellLongTextRenderer extends JTextArea implements TableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
this.setText((String) value);
this.setWrapStyleWord(true);
this.setLineWrap(true);
// set the JTextArea to the width of the table column
setSize(table.getColumnModel().getColumn(column).getWidth(),
getPreferredSize().height);
if (table.getRowHeight(row) != getPreferredSize().height) {
// set the height of the table row to the calculated height of the
// JTextArea
table.setRowHeight(row, getPreferredSize().height);
return this;
Edited by: 915175 on Aug 3, 2012 4:24 AMHi
Try below code. Hope this will help
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
public class SimpleTableExample extends JFrame {
private JPanel topPanel;
private JTable table;
private JScrollPane scrollPane;
String data1 = "";
String data2 = "123456789ABCDEFGHIJKLMNOPQRSTUVQWXYZabcdefghijklmnopqrstuvwxyzaquickbrownfoxjumpedoverthelazydog";
int size = data2.length();
// Constructor of main frame
public SimpleTableExample() {
// Set the frame characteristics
setTitle("Simple Table Application");
setSize(400, 200);
setBackground(Color.gray);
// Create a panel to hold all other components
topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
getContentPane().add(topPanel);
// Create columns names
String columnNames[] = { "SEL", "DESIGN DATA", "PART NUMBER" };
// Create some data
String dataValues[][] = { { data1, data2, "67", "77" },
{ "", "43", "853" }, { "", "89.2", "109" },
{ "", "9033", "3092" } };
DefaultTableModel model = new DefaultTableModel(dataValues, columnNames);
model.addColumn("PART TITLE");
model.addColumn("SPECIAL INSTRUCTIONS");
table = new JTable(model) {
public boolean isCellEditable(int rowIndex, int colIndex) {
return false;
// set specific row height
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
int colInd = 0;
TableColumn col = table.getColumnModel().getColumn(colInd);
int width = 50;
col.setPreferredWidth(width);
int colInd2 = 1;
TableColumn col2 = table.getColumnModel().getColumn(colInd2);
int width2 = 100;
col2.setPreferredWidth(width2);
int colInd3 = 2;
TableColumn col3 = table.getColumnModel().getColumn(colInd3);
int width3 = 10;
col3.setPreferredWidth(width3);
int colInd4 = 3;
TableColumn col4 = table.getColumnModel().getColumn(colInd4);
int width4 = 10;
col4.setPreferredWidth(width4);
int colInd5 = 4;
TableColumn col5 = table.getColumnModel().getColumn(colInd5);
int width5 = 10;
col5.setPreferredWidth(width5);
// Cell Render should apply on each column -- add by Rupali
for(int i=0; i< table.getColumnModel().getColumnCount(); i++){
table.getColumnModel().getColumn(i).setCellRenderer( new TableCellLongTextRenderer());
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
JTable target = (JTable) e.getSource();
int row = target.getSelectedRow();
int column = target.getSelectedColumn();
setTableCellHeight(table,row,column); //Added by Rupali
TableColumn col1 = table.getColumnModel().getColumn(0);
col1.setPreferredWidth(50);
TableColumn col2 = table.getColumnModel().getColumn(1);
col2.setPreferredWidth(400);
TableColumn col5 = table.getColumnModel().getColumn(4);
col5.setPreferredWidth(200);
// Create a new table instance
// table = new JTable(dataValues, columnNames);
// Add the table to a scrolling pane
scrollPane = new JScrollPane(table);
topPanel.add(scrollPane, BorderLayout.CENTER);
* Created By Rupali
* This will set cell's height and column's width
* @param table
* @param row
* @param column
public void setTableCellHeight(JTable table, int row, int column) {
// set the JTextArea to the width of the table column
setSize(table.getColumnModel().getColumn(column).getWidth(),
getPreferredSize().height);
if (table.getRowHeight(row) != getPreferredSize().height) {
// set the height of the table row to the calculated height of the
// JTextArea
table.setRowHeight(row, getPreferredSize().height);
// Main entry point for this example
public static void main(String args[]) {
// Create an instance of the test application
SimpleTableExample mainFrame = new SimpleTableExample();
mainFrame.setVisible(true);
class TableCellLongTextRenderer extends JTextArea implements TableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
this.setText((String) value);
this.setWrapStyleWord(true);
this.setLineWrap(true);
return this;
} -
To make Three row values in a single row
Hi,
Below is the Table Format i have.
Here for the first Mail_ID i have 3 mail addresses.similarly for second ID too.
I want First three rows to be in a single row.and so on...
Plz help in doing this.
Thanks
DeepaDeepa,
Check if this helps.. Does dynamic conersion of data to columns ..
--Your Email table
create table #temp (mailid int,to_mail varchar(100))
insert #temp select 1,'[email protected]'
insert #temp select 1,'[email protected]'
insert #temp select 1,'[email protected]'
insert #temp select 2,'[email protected]'
insert #temp select 2,'[email protected]'
insert #temp select 3,'[email protected]'
--Constructing a temp table to hold data with row_numbers
select *,row_number() over(partition by mailid order by to_mail) as rn
into #t
from #temp
--declaration of variables
declare @n int,@list varchar(max),@sql nvarchar(max)
set @n=(select max(rn) from #t)
--Population of list to form the dynamic query
;with cte
as
select cast(',[email1]' as varchar(max)) as ch,1 as num
UNION ALL
select cast(ch+',[email'+cast((num+1) as varchar(100))+']' as varchar(max)) as ch,num+1 as num
from cte where num<@n
select top 1 @list=stuff(ch,1,1,'')
from cte
order by num desc
--Formulating the complete dynamic query
set @sql='
select mailid,'+@list+'
from
select mailid,to_mail,''email''+cast(rn as varchar) as emailnum from #t
) tab
PIVOT
max(to_mail) for emailnum in ('+@list+')
) pvt'
exec sp_executesql @sql
--clean up
drop table #t
Thanks,
Jay
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'> -
Hi All
I have facing the Single row sub query Error . I tried to resolve , but my condition not working .can please any help to rewrite the query (sub query)
SELECT DISTINCT wdlsv.serial_number
,wdlsv.date_shipped
,wdlsv.inventory_item_id
,wdlsv.organization_id
,wdlsv.lot_number
,(select distinct engine from xxtc_tr_pr_open_data where chassis=wdlsv.serial_number and rownum=1
union
select distinct replace(replace(attribute11,'*',''),' ','')
from xxtc_chassis_scanout_details
where serial_number=wdlsv.serial_number
and operation_line_code ='CHASSIS') "ENGINE_NO"
,oola.attribute1 oh_excise_no
,msi.attribute16 vehicle_type
,bbom.attribute2 model_no
,xxst.tariff_code tariff_code
,substr(xxst.color_type,1,1) color_type
,(SELECT TO_CHAR(trunc(rt.transaction_date),'RRRRMMDD')
FROM rcv_transactions rt,
rcv_shipment_lines rsl,
rcv_shipment_headers rsh
WHERE rsh.shipment_header_id=rsl.shipment_header_id
AND rt.shipment_header_id=rsl.shipment_header_id
AND rsl.attribute1=wdlsv.lot_number
AND rt.organization_id=wdlsv.organization_id
AND rt.organization_id=rsh.organization_id
AND ROWNUM<=1
union
select distinct to_char(xxtp.indent_import_date,'RRRRMMDD')
from xxtc_tr_pr_open_data xxtp
where xxtp.chassis = wdlsv.serial_number) "CKD_IMPORT_DATE_YEAR"
,to_char(xxtp.indent_import_date,'RRRRMMDD') import_date
FROM WSH_DELIVERY_LINE_STATUS_V WDLSV
,oe_order_headers_all ooha
,oe_order_lines_all oola
,mtl_system_items_b msi
,bom_bill_of_materials bbom
,xxtc_sales_tax_cal xxst
WHERE 1=1
AND PICK_STATUS = 'C'
AND delivery_status = 'CL'
AND ooha.header_id = wdlsv.source_header_id
AND ooha.header_id = oola.header_id
AND oola.line_id = wdlsv.source_line_id
AND msi.inventory_item_id = wdlsv.inventory_item_id
AND msi.organization_id = wdlsv.organization_id
AND bbom.assembly_item_id = wdlsv.inventory_item_id
AND bbom.organization_id = wdlsv.organization_id
AND xxst.inventory_item_id = wdlsv.inventory_item_id
AND xxst.organization_id = wdlsv.organization_id
and upper(msi.attribute15) not like 'SUB%'
AND WDLSV.SERIAL_NUMBER IS NOT NULL;
Regards
SanjayThis forum is for questions about working with SQL*Developer. The title is "SQL Developer (Not for general SQL/PLSQL questions)" and yours is a general SQL question. You should get a better answer by re-posting in the SQL and PL/SQL forum in the Oracle Database section. Please mark this tread as answered and re-post there.
-
Merge two rows & show in a single row in table results
Hi, I need to merge 2 rows having 3 columns in a single row in table view
The cols are currently shown as :
Project NO-------(Current_Month) Revenue----------(Prior_Month) Revenue
123123 10000
20000
Revenue is a single column with revenue for diffreent Period.
10000 is for May
20000 is for April
Project NO for both are same, just the periods are different. if I am not displaying Period i need to merge the 2 rows & show as
Project NO-------(Current_Month) Revenue----------(Prior_Month) Revenue
123123 10000 20000
Please let me know how we can acheive this??
thanx
Pankaj123123 is the project number..
the above is not getting displayed properly....as the blank spaces are removed...
Please consider this -
SQL Multiple Columns Displayed in a Single Row
Hello everyone,
I have 2 tables, Product and Product_Name, one Product can have more than one name.
I need to retrieve it in such a way that I show the Product_ID followed by all the names this product has.
I'm not able to make it, every way I try I get the Product ID duplicated and several rows with a different product name on each row as follows:
1, 'Iron Z"
1, 'Iron M'
1, 'Iron N'
2, 'Wood P'
2, 'Wood M'
What I need is:
1, Iron Z, Iron M, Iron N
2, Wood P, Wood M
Thanks and Regards.Hi,
user10103934 wrote:
Thank you for the answer Frank,
Iron Z, Iron M and Iron N would be 3 different entries on the same column.
I'm sure the LISTAGG function would resolve this, the problem is that I was hoping to get a solution on pure SQL or PL/SQL, maybe with a nested Select.
My Oracle version is 10g Express Edition.LISTAGG is pure SQL, but it was only introduced in Oracle 11.2. Everything mentioned below should work in Oracle 10.
The STRAGG function from that page is very useful. You have to copy and install about 60 line of PL/SQL code. Do that once, and then you can use it hundreds of times in hundreds of queries, just as if it was a built-in function. The main problem with STRAGG is that it's hard to get soprted output from it. There's a modified version, designed for sorted output, on this thread:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:15637744429336
Never used it. Can't vouch for it.
SYS_CONNECT_BY_PATH seems to be the most popular way of doing string aggregation in Oracle 10. The example given on the Oracle Base page (which I posted in my last message) is a little clumsy and inefficient. See the following thread for a better example, using CONNECT_BY_ISLEAF:
Re: Concatenate strings from more rows into one row.
or, now that I see it, Pollywog's example above.
Edited by: Frank Kulash on Jun 11, 2010 2:24 PM -
Removing result row value for a single KF rather than all KFs in a query.
Hi,
Is it possible to remove the value in the result row of a query for a particular keyfigure? I want the the values in the result row for all the keyfigures except one. This particular keyfigure should have nothing in the result row. Is it possible in BEx Query Designer? Because my current setup doesnt allow me to use any other BEx tool other than query designer. Would appreciate if someone can provide me a solution for this using query designer. Helpful replies will be rewarded full points.
Regards,
Anurag.u can do that...
enter into query designer
open ur query
go to columns / rows
select ur keyfigure
on right panel u will see properties for that particular keyfigure
go to the Result row option
Select CALCULATE RESULT AS
then select SUPRESS/HIDE OPTION..
that way u can suppress the result rows for ur keyfigure. -
Merge Multiple Rows in to a single Row.
Hi
Tab_A
Col_1
Col_2
Col_3
I want resultant rows to merge on base of Col_1 (i.e. single - delimited merge row for distinct value of Col_1)
Example
Table_A
Col_1 | Col_2 | Col_3
A | 1 | 23
A | 2 | 25
B | 3 | 5
B | 6 | 9
C | 7 | 8
Required Result
Col_1 | Col_2 | Col_3
A | 1-2 | 23-25
B | 3-6 | 5-9
C | 7 | 8
Wishes
JawadYou can try with sys_connect_by_path, but I've found Re: Aggregate function to bring values in list form more performant.
You can write your query like this:
SELECT col_1
, concat_all(concat_expr(col_2,'-')) col_2
, concat_all(concat_expr(col_3,'-')) col_3
FROM yourtableMHE -
Multiple row data in a single row
I have a table like the following:
AGREEMENT_ID SERVICE_CODE SERIAL_NO
22 CV CE095F0011007884F
22 HS 2509b000121373869
22 NG 2509B000121265554
22 SG 2509B00012120278D
22 SM PAFABM0716140704
22 SN G32X2MI808300348
22 SP CE095F00110045416
22 SV 2509B000121363230
22 SW CE095F00110037377
I would like to have it in the following format
Agreement_id CV HS NG SG SM SN SP SV SW --(These are the columns)
22 CE095F0011007884F 2509b000121373869 2509B000121265554 ....
(This is data)
Need to do it in a single Query....
Want an advice
Regards
Chaitanya.S.S.KHi,
SQL> l
1 with tbl as
2 (select 22 id, 'CV' service, 'CE095F0011007884F' serial from dual
3 union all
4 select 22, 'HS','2509b000121373869' serial from dual
5 union all
6 select 22, 'NG','2509B000121265554' serial from dual
7 union all
8 select 22, 'SG','2509B00012120278D' serial from dual
9 union all
10 select 22, 'SM','PAFABM0716140704' serial from dual
11 union all
12 select 22, 'SN','G32X2MI808300348' serial from dual
13 union all
14 select 22, 'SP','CE095F00110045416' serial from dual
15 union all
16 select 22, 'SV','2509B000121363230' serial from dual
17 union all
18 select 22, 'SW','CE095F00110037377' serial from dual
19 union all
20 select 23, 'SW','CE095F00110037377' serial from dual)
21 select id,
22 max(decode(service,'CV',serial)) "CV",
23 max(decode(service,'HS',serial)) "HS",
24 max(decode(service,'NG',serial)) "NG",
25 max(decode(service,'SG',serial)) "SG",
26 max(decode(service,'SM',serial)) "SM",
27 max(decode(service,'SN',serial)) "SN",
28 max(decode(service,'SP',serial)) "SP",
29 max(decode(service,'SV',serial)) "SV",
30 max(decode(service,'SW',serial)) "SW"
31 from tbl
32* group by id
SQL> /
ID CV HS NG SG SM SN SP SV SW
22 CE095F0011007884F 2509b000121373869 2509B000121265554 2509B00012120278D PAFABM0716140704 G32X2MI808300348 CE095F00110045416 2509B000121363230 CE095F00110037377
23 CE095F00110037377
SQL> HTH,
Nicolas. -
Obiee report two rows data present in single row
Hi Experts,
I have facing one problem how to reslove this problem let me know.
In DB Table like this.
Sno **** Value1 **** Value2
10 ******** 100 ******* 0
10 **** *** 0 ******* 200
i want to out put Obiee reports like this ?????????
sno ***** value1 **** value2
10 ****** 100 **** 200
How to achive this please tell me any method
i am using obiee 10.1.3.4.1 version (i am try to create report OBIEE answers )
Thanks
Satya
Edited by: satya vardhan on Jul 11, 2011 6:56 PMTry going it by Sno.
If you are using Pivot Table, try changing measures from columns to rows and see. I vaguely remember doing this would address your need
Thanks,
Vinag -
Merging corresponding coloumns of multiple rows to get a single row
hi,
plz help me in sorting out this problem.this is my query.
select distinct h.ccid,
DECODE(a.prmcd,'ELEREP', sum(d.period_net_dr - d.period_net_cr)) A,
DECODE(a.prmcd,'GENREP', sum(d.period_net_dr - d.period_net_cr)) B
DECODE(a.prmcd,'BLDGREP', sum(d.period_net_dr - d.period_net_cr)) C,
DECODE(a.prmcd,'MCREP', sum(d.period_net_dr - d.period_net_cr)) D,
DECODE(a.prmcd,'SPARES', sum(d.period_net_dr - d.period_net_cr)) E
from fics_prmtrval a,
figl_code_combinations_mview_1 c,
figl_balances_mview_1 d,
fims_comstr e,
FIMS_PCSCMSTR f,
FIMS_CCMSTR g,
FIMS_CODECOMBINATIONS h
where a.prmcd in('ELEREP', 'GENREP', 'MCREP', 'BLDGREP', 'SPARES')
and a.prmval = c.segment4
and c.code_combination_id = d.code_combination_id
and e.cocd = c.segment1
and f.PCSCCD = C.SeGMENT2
and g.CCCD = C.SEGMENT3
and h.COID = e.coid
and h.PCID = f.PCSCID
and h.CCID = g.CCID
and h.stid = 1
and h.coid = 1
and h.pcid = 1
group by h.ccid,
g.ccnm,
a.prmcd
the output of this is :
CCID A B C D E
16 1
16 2
17 3
17 4
17 5
17 6
but i need the out put in the following format:
CCID A B C D E
16 1 2
17 3 4 5 6
plz suggest me a possible solution for thisHi,
Enclose all your decodes by MAX like this MAX( DECODE(...)) and group your result by ccid column only and remove the distinct key word( it is not needed since you will be already grouping on ccid so distinct would be kind of redundant ).
For any furthur clarifications refer this link, it is easy to follow.
http://asktom.oracle.com/pls/ask/f?p=4950:8:8495196364001188355::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:124812348063
Thanks,
Khalid -
Combine multiple rows of table in single row
Hi Experts,
I have a table of below format.
MSDNID
WALL_BAL
WALL_DATE
123
34
06-Sep-13
123
56
07-Sep-13
123
78
08-Sep-13
123
65
09-Sep-13
123
34
10-Sep-13
123
87
11-Sep-13
Now I have to create a new table. which should contain unique MSDNID with WALL_BAL in different column .
Like below
MSDNID
DAY1_BAL
DAY2_BAL
DAY3_BAL
DAY4_BAL
DAY5_BAL
DAY6_BAL
123
87
34
65
78
56
34
How can I write a query for this?in 10g , you can use something like
select MSDNID,
max(decode(WALL_DATE, '11-Sep-13', WALL_BAL, null) day_1_bal,
max(decode(WALL_DATE, '06-Sep-13', WALL_BAL, null) day_6_bal
from t
group by MSDNID;
But it only works if you have limited # of days.
Maybe you are looking for
-
I have a Workflow that sends a mail to an employee in some cases. The employee can see it at SAP Business Workplace, but he has to check it periodically to know if there are or aren't a new message for him. Are there any way to tell him he has a mes
-
Application download is stuck on "loading"
last night, I tried downloading an update for a previous application. However, it was taking longer than it should have, so I decided to reset it. It basically bricked the iphone for more than an hour. Once I got it unbricked, it showed the app stuck
-
Identifier tab in Communication Channel
Hi, When do we populate "Identifier tab in Communication Channel" Thnx Raj
-
Disappearing applications from ipad2
I recently synced my ipad 2 with itunes (after browsing a few days on it), and shortly after the sync was completed, noticed that three applications being, camera, facetime and photobooth disappeared from the ipad. I recenrtly restored the ipad, wher
-
CS 6 Gradient Panel stopped functioning
CS 6 iMac Late 2013 The Gradient Panel seems to have a bug on my iMac but works fine on my MacBook Air. Make a thing and give it a fill of the black to white gradient. As soon as I click on the black (right) stop & move it, the whole gradient line di