Cursor fetch with multiple rows
I have been given code which, effectively, looks like this:
declare
cursor cTest is select * from (select 'one' from dual union all select 'two' from dual);
lvText varchar2(10);
begin
open cTest;
fetch cTest into lvText;
close cTest;
dbms_output.put_line(lvText);
end;
/That consistently returns just the result "one", even though there are two rows in the cursor.
If I re-write the code like this:
declare
lvText varchar2(10);
begin
select thecol into lvText from (select 'one' as thecol from dual union all select 'two' from dual);
dbms_output.put_line(lvText);
end;
/...then I get the error I expected (ORA-01422: exact fetch returns more than requested number of rows).
I guess I am a bit surprised the "fetch into" syntax (which I haven't used before) works at all. Why doesn't it spot that multiple rows are being loaded into a single variable and explode? I am guessing that which row 'wins' the competition to be assigned to the variable is completely indeterminate? Any doco on this behaviour you can point me at, please? The bit I read (http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/fetch_statement.htm) simply says that "You must use either a cursor FOR loop or the FETCH statement to process a multiple-row query", but it doesn't say "the code will silent grab one of the rows at random if you use the FETCH statement on a multiple-row resultset".
(tested on 11.2.0.3, if it makes a difference)
>
I realise FETCH fetches one row. The problem is that without a loop, doing so is 'wrong', logically. But it's still allowed, and I can't find anywhere in the doco that says "if you use FETCH, you MUST loop through the results, otherwise we will only return the first row, which will then probably be a bug in your code".
I'm asking for something from the doco (or from a website somewhere, maybe) that explains that "fetch without loops will work, but will be wrong". It's not something I expected, put it that way. It's something I would have thought others would have tripped over before now, anyway. In what I've read, like your code example here, you just see fetch-with-loops, with the unstated assumption made that you'd never do it any other way. I've not seen it explicitly said that it's possible to do it without a loop, but would be a dumb thing to do.
>
Oracle has no way to know what a developer is trying to do or how many rows a cursor will return.
It isn't necessarily true that "fetch without loops will work, but will be wrong". My cursor might only return one row.
What about a BULK COLLECT INTO without a LIMIT clause? Should Oracle tell you that if you query too many records you may run out of memory?
What about a BULK COLLECT INTO with a limit clause? Should Oracle tell you that "bulk collect with limit without a loop will work, but will be wrong"? It isn't necessarily wrong either.
Similar Messages
-
How to check if "fetch" returns Multiple rows
I want to know thru some variable (like %found) if the "fetch" returns multiple rows. How can I do it?
My code:
open tab1_rec for
'select fld1 ' ||
'from tab1 f ' ||
'where f.fld3 = :s1 and ' ||
'f.fld4 = :s2 and ' ||
'f.fld5 = 1 '
using fld3_in,
fld4_in;
fetch tab1_rec into var1;
-- If MULTIPLE
if tab1_rec%multiple
ThanksIf returning more than one row is unusual in some way (that is you are expecting only a single row) then you can do it like:
BEGIN
SELECT fld1 INTO var1
FROM tab1 f
WHERE f.fld3 = fld3_in and
f.fld4 = fld4_in and
f.fld5 = 1;
< Do your processing here >
EXCEPTION
WHEN NO_DATA_FOUND THEN
< handle no rows >
WHEN TOO_MANY_ROWS THEN
< handle multiple rows >
END;No need for a cursor here. If you are expecting more than one row, and just want to know the count for information purposes, then you have to loop and fetch the records.
HTH
John -
Web dynpro screen with multiple rows with columns that can be edited
Web dynpro screen with multiple rows with columns that can be edited individually:
Hi
I am busy creating a screen in web dynpro for ABAP which we would like to make available via Portal ESS (Portal 7).
I need to add 'n type of table (or almost something like Excel) or something in which someone can type a few paycode numbers (there should be lets say 10 blank rows in which info can be typed in and if I click on a button or so, more rows must be added if necessary. Then in the other colums stuff like amounts must be entered which one should also be able to edit then and there.
Can anyone assist in what I can use for this? There does not seem to be some existing element that I can use.
Help will be appreciated.
Regards
DebbieHi Debbie,
Whiel Creating table you need to be care full that use chose INPUT FIELD as the CELL EDITOR. Just guessing that if ur table is not editable u might have choosen TextView as default cell editor type.
check link for details on TABLE UI
[http://help.sap.com/saphelp_erp2005/helpdata/EN/b5/ac884118aa1709e10000000a155106/frameset.htm]
easy way is to first add UI ELEMENT TABLE to your VIEW, then right click over it & select create binding from context. After you have a pop up where you can select what columns you want what should be its cell editor etc.
Greetings
Prashant -
Loading xml file with multiple rows
I am loading data from xml files using xsl for transformation. I have created xsl's and loaded some of the data. In an xml file with multiple row, it's only loading one (the first) row. Any idea how I can get it to read and load all the records in the file???
Could some please help me with the above. I desparately need to move forward.
-
TO DRAW A TABLE WITH MULTIPLE ROWS AND MULTIPLE COLOUMNS IN FORM
Hi,
How to draw a table with multiple rows and columns seperated by lines in form printing?check this
http://sap-img.com/ts003.htm
Regards
Prabhu -
I have regisetred a EIT with multiple rows Yes, can we change it NO now.
I have registered a EIT with multiple rows Yes, can we change it NO now.
Hi,
Yes you can change this through back-end.
Register extra information (types) concurrent program run the package HR_REGISTER_EITS and insert definintion of an EIT in respective INFO_TYPES tabel for example if person EIT then definition is stored in PER_PEOPLE_INFO_TYPES.
In this table we have column MULTIPLE_OCCURENCES_FLAG which can have value as Y or N, Y - Multiple entries allowed, N - Multiple entries not allowed.
You need to update the value of this flag to N for your EIT definition and you are done.
Thanks,
Sanjay -
Editable table with multiple rows
Hi All!
We're trying to develop some application in VC 7.0. That application should read data from some R/3 tables (via standard and custom functional modules), then display data to user and allow him/her to modify it (or add some data into table rows), and then save it back to R/3.
What is the best way to do that?
There's no problem with displaying data.
But when I try to add something to table (on portal interface), I'm able to use only first row of the table... Even if I fill all fields of that row, I'm not able to add data to second row, etc.
Second question. Is it possible to display in one table contents of output of several BAPIs? For example we have three bapis, one displaying user, second displays that user's subordinates, and the third one - that user's manager. And we want one resulting table...
And last. What is the best way to submit data from table view in VC (portal) to R/3 table? I understand that we should write some functional module, that puts data to R/3. I'm asking about what should be done in VC itself. Some button, or action...
Any help will be appreciated and rewarded :o)
Regards,
DKHere are some former postings:
Editable table with multiple rows
and
Editable table with multiple rows
Are you on the right SP-level?
Can you also split up your posting: one question, one posting? This way you get faster answers, as people might just browse the headers. -
Hi All,
I am using NWDS 2004
I want to have a table with multiple rows in a row.
Can any one help ?
Thankshi Akhilesh,
Use tree table for your requirement.
[Tree Table Tutorial|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/de59f7c2-0401-0010-f08d-8659cef543ce]
Hope this helps!
Monalisa -
JTable with Multiple Row Header
well, Im do an application thats need formated ISOS Sheets, and most of them have a Table with Multiple Row Header , and Groupable Header, and both of them. I have the .java and in the class MultipleRowHeaderExample calls a class AttributiveCellTableModel for setColumnIdentifiers() and setDataVector() the cue is why this print stack :
Exception in thread "main" java.lang.StackOverflowError
at java.util.Vector.<init>(Unknown Source)
at java.util.Vector.<init>(Unknown Source)
at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:54)
at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
.if in main class, have initialized the data, and column vars
public class MultipleRowHeaderExample extends JFrame {
Object[][] data;
Object[] column;
JTable table;
MultiSpanCellTable fixedTable;
public MultipleRowHeaderExample() {
super( "Multiple Row Header Example" );
setSize( 400, 150 );
data = new Object[][]{
{"SNo." ,"" },
{"Name" ,"1"},
{"" ,"2"},
{"Language","1"},
{"" ,"2"},
{"" ,"3"}};
column = new Object[]{"",""};
AttributiveCellTableModel fixedModel = new AttributiveCellTableModel(data, column) {
public boolean CellEditable(int row, int col) {
return false;
};What's the code in AttributiveCellTableModel?
* (swing1.1beta3)
package jp.gr.java_conf.tame.swing.table;
import java.util.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
* @version 1.0 11/22/98
public class AttributiveCellTableModel extends DefaultTableModel {
protected CellAttribute cellAtt;
public AttributiveCellTableModel() {
this((Vector)null, 0);
public AttributiveCellTableModel(int numRows, int numColumns) {
Vector names = new Vector(numColumns);
names.setSize(numColumns);
setColumnIdentifiers(names);
dataVector = new Vector();
setNumRows(numRows);
cellAtt = new DefaultCellAttribute(numRows,numColumns);
public AttributiveCellTableModel(Vector columnNames, int numRows) {
setColumnIdentifiers(columnNames);
dataVector = new Vector();
setNumRows(numRows);
cellAtt = new DefaultCellAttribute(numRows,columnNames.size());
public AttributiveCellTableModel(Object[] columnNames, int numRows) {
this(convertToVector(columnNames), numRows);
public AttributiveCellTableModel(Vector data, Vector columnNames) {
setDataVector(data, columnNames);
public AttributiveCellTableModel(Object[][] data, Object[] columnNames) {
setDataVector(data, columnNames);
public void setDataVector(Vector newData, Vector columnNames) {
if (newData == null)
throw new IllegalArgumentException("setDataVector() - Null parameter");
dataVector = new Vector();
setColumnIdentifiers(columnNames);
dataVector = newData;
cellAtt = new DefaultCellAttribute(dataVector.size(),
columnIdentifiers.size());
newRowsAdded(new TableModelEvent(this, 0, getRowCount()-1,
TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
@Override
public void setColumnIdentifiers(Vector arg0) {
// TODO Auto-generated method stub
super.setColumnIdentifiers(arg0);
public void addColumn(Object columnName, Vector columnData) {
if (columnName == null)
throw new IllegalArgumentException("addColumn() - null parameter");
columnIdentifiers.addElement(columnName);
int index = 0;
Enumeration enumeration = dataVector.elements();
while (enumeration.hasMoreElements()) {
Object value;
if ((columnData != null) && (index < columnData.size()))
value = columnData.elementAt(index);
else
value = null;
((Vector)enumeration.nextElement()).addElement(value);
index++;
cellAtt.addColumn();
fireTableStructureChanged();
public void addRow(Vector rowData) {
Vector newData = null;
if (rowData == null) {
newData = new Vector(getColumnCount());
else {
rowData.setSize(getColumnCount());
dataVector.addElement(newData);
cellAtt.addRow();
newRowsAdded(new TableModelEvent(this, getRowCount()-1, getRowCount()-1,
TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
public void insertRow(int row, Vector rowData) {
if (rowData == null) {
rowData = new Vector(getColumnCount());
else {
rowData.setSize(getColumnCount());
dataVector.insertElementAt(rowData, row);
cellAtt.insertRow(row);
newRowsAdded(new TableModelEvent(this, row, row,
TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
public CellAttribute getCellAttribute() {
return cellAtt;
public void setCellAttribute(CellAttribute newCellAtt) {
int numColumns = getColumnCount();
int numRows = getRowCount();
if ((newCellAtt.getSize().width != numColumns) ||
(newCellAtt.getSize().height != numRows)) {
newCellAtt.setSize(new Dimension(numRows, numColumns));
cellAtt = newCellAtt;
fireTableDataChanged();
public void changeCellAttribute(int row, int column, Object command) {
cellAtt.changeAttribute(row, column, command);
public void changeCellAttribute(int[] rows, int[] columns, Object command) {
cellAtt.changeAttribute(rows, columns, command);
}that's it -
Downloading .xls file with multiple rows and Columns
Hi ALL,
I need to genarate .xls file with multiple rows and and Columns and sent as an email.Since our customer having Problem with .CSV files need to genarate .XLS file.
Please do the needful.
Thanks
MadhuHi Madhu,
You might also consider using Excel Spreadsheet XML as the target structure (namespace is urn:schemas-microsoft-com:office:spreadsheet). When you double-click the resulting xml on a PC it automatically opens with Excel. So, users don't see a difference. It will open up a lot of options with formatting including creating multiple worksheets if you wanted to. Best of all you can stick with XML.
See my response in this thread:
Re: Convert XML data into XLS
Thanks,
-Russ -
Splitting a message with multiple rows from the JDBC Adapter
Hi,
I'd like to split the resultset message with multiple row elements and process each row separately..
Does someone have this experience?
Thanx, PeterHi Chandrasekhar,
I tried to follow your advise, but I'm not able to complete the process correctly.
Let me explain my process:
First - output from the JDBC adapter goes into the first receive step. Of course, there are multiple ROW elements. (Should be marked the ingoing message marked in the container as Multiline??)
The next should be the transformation:
format of the source message is like
<message>
<row>
<column>w</column>
</row>
<row>
<column>w</column>
</row>
</message>
In the message I have the ROW element as 0..unbounded
and <column> element exactly 1
This message should be mapped to multiple messages of the format:
<message>
<value>w</value>
</message>
How should be the mapping be done?
Is it N:1 or 1:N (because in another thread there was an 1:N mapping advised)
Then (as you say) should follow the Block step:
Which message (container element) should be marked as Multiline? And what does it mean: Current Message?
Can you give me some advise, when and how to use the multiline mark?
Thanx a lot, Peter -
Reg : Concatenation of a column value with multiple rows... URGENT
Hello,
Could any of u help me in concatenating a column value with
multiple rows ???
For ex : I've the following data from emp table :
DEPTNO ENAME
10 KING'S
30 BLAKE
10 CLARK
10 TOM JONES
30 ALLEN
30 JAMES
20 SMITH
20 SCOTT
20 MILLER
10 MILLER
20 rajeev
I want the following output :
deptno Concat_value
10 KING'S,CLARK,TOM JONES,MILLER
20 Rajeev,MILLER,SMITH,SCOTT
30 BLAKE,ALLEN,JAMES
Thanks in Advance,
SriniHello Naveen,
Thanks for ur answer. But I need a single SQL query for getting
what I want. I know the solution in PL/SQL.
Please try it in a single SQL....
Thanks again,
Srini -
Watermark with multiple rows of text, Is it possible?
Hi everyone,
One of our clients want the whole page filled with watermark with multiple rows of text, I cannot find related properties on the watermark configuration page, is it possible?
Thank you in advance.Multi-line Dynamic Watermarks are available from ES3 onwards. You can create multiple Watermark text elements to have more than one line in the Watermarks. Please see http://help.adobe.com/en_US/livecycle/10.0/AdminHelp/WSb96e41f8a4ca47a94897a78313098c91af6 -8000.html
Regards,
Neerav -
Drill Down between 2 stacked column chart with multiple rows.
Hi,
Can anyone please help me.
1) i have to create stacked column chart with Region and cout of calls for previous 3 quarters.
2) the 2nd stacked column should display the priority with the count of calls for the respective selection of region on the 1st chart..
to achieve this,
i'm using 2 stacked column charts and 1 lebel baseb menu.
from this i can able to get the drill down from label based menu to 2nd stacked column chart but i couldn't able to done the same from 1st stacked coumn chart.
Becoz my data is multiple row for each quarter.
please suggest me to achieve the drill down between 2 stacked column charts.
assume that my data like below.:
coulmns for 1st stacked column chart : Region, Q2,Q3 &Q4
Region Q2 Q3 Q4
Other 3658 3497 497
NA - North
America 3 3 1101
APJK 1 4 597
UK 324
EMEA North 1 1 288
CORPORATE 1 5 215
LA -
Latin America1 2 208
EMEA 1 199
EMEA South 1 1 169
Coulmns for 2nd coumn chart: Region, Priority, Q2,Q3,Q4 ()which is derived from 1st table.
Region Priority Q2 Q3 Q4
Other D: End of Next Day 1568 1613 239
Other C: End of Day 983 893 119
Other A: 2 Hour 631 610 70
Other B: 4 Hour 396 318 56
NA -
North AmericaD: End of Next Day 2 2 514
APJK D: End of Next Day 3 297
NA -
North AmericaC: End of Day 284
NA -
North AmericaA: 2 Hour 1 170
UK D: End of Next Day 157
APJK C: End of Day 1 1 152
Other E: 3 - 5 Business Days 68 58 13
EMEA North D: End of Next Day 1 136
CORPORATE D: End of Next Day 4 107
NA - North America B: 4 Hour 1 104
LA - Latin America D: End of Next Day 1 1 86
EMEA D: End of Next Day 86
UK C: End of Day 85
APJK A: 2 Hour 79
EMEA South D: End of Next Day 72
EMEA North A: 2 Hour 69
EMEA North C: End of Day 56
APJK B: 4 Hour 55
EMEA C: End of Day 1 53
LA - Latin America C: End of Day 54
UK A: 2 Hour 49
EMEA South C: End of Day 1 44
CORPORATE A: 2 Hour 1 43
CORPORATE C: End of Day 44
LA - Latin America A: 2 Hour 1 42
EMEA South A: 2 Hour 1 32
EMEA B: 4 Hour 30
UK B: 4 Hour 30
EMEA A: 2 Hour 27
EMEA North B: 4 Hour 1 26
NA -
North AmericaE: 3 - 5 Business Days 25
LA - Latin America B: 4 Hour 23
EMEA South B: 4 Hour 20
CORPORATE B: 4 Hour 17
APJK E: 3 - 5 Business Days 13
Other F: 6 - 10 Business Days 6 4
Other G: 11 - 20 Business Days 6 1Hi Srinivas,
I'm using label based menu "filterd rows" only but i couldn't bind the drill down with the 1st stacked column chart.
for mor details:
1) i'm having 2 stacked coumn charts & 1 lebel based menu but eventhough i couldn't able to achieve.
if i select the lebel based values then the 2nd stacked column charts is giving detailed valus but if i keep my mouse on the 1st stacked column chart the there is no changes on the 2nd chart..
somewhere i'm mising the binding data between 1st stacked coumn chart & lebel based menu on drill down part.
Becoz i'm having multiple rows. so can you please try your and send me the xlf file using your concept. -
INSERT or UPDATE with multiple rows
Hi there!
I want to ask what I should do in the following case: I have to handle mutliple rows of data to insert OR to update into the database.
The first question is about how to decide whether I should take INSERT or UPDATE. I read here in the forum that I could take a SELECT-statement before, and, if it isn't null, I could update the resultset..if it is null I can make an INSERT-statement.
But now I a have multiple rows to update or to insert which I want to handle as a transaction (with a batch), so I don't want to check each row the way I described above. Does anyone has a hint ?
Thanks a lot in advance.This is not a problem with java but rather a problem
with databases in general. The solution generally
depends on the data that is being operated on.
If there is a primary key involved, and most records
were expected to NOT be in the database, then you
could just insert them in blocks (transaction/batch).
Each block would fail when a primary key duplicate.
Then you can process each block as individual
l statements. The ones that fail are done as
inserts.
The reverse of the above is used if you expect most
records to be in the database. Do updates and the
break out the blocks with failures to locate the
inserts.
Keep in mind that queries for keys probably will be
faster, but that requires that your keys are ordered.
If you keys are ordered then you can get a range from
the initial data. Use that to query the database for
keys between that range (only return the keys.)
Using the returned keys you can decide whether each
h record needs to be an update or insert (presort the
data into each group and batch each group for more
speed.)
If the data is really mixed and the database supports
it then you can write a stored proc (MySQL does not)
which decides whether an insert/update is needed.
Finally if you have large amounts of data, bulk
operations especially inserts are better done with
tools supplied by the database vendor. Instead of
using JDBC to do the insert/updates you write the
output to a file and pass the file to the tool. You
might use JDBC (again with the ordered key query) to
decide which operation to do. Although faster for
large sets this is problematic due to the error
handling that you have to add.
Thanks for this, jschell. I look for your answers, because they're on the money and written well. I learn a lot from them. - MOD
Maybe you are looking for
-
How to collect the deleted query in a transport request.
Hi Friends, I have created a query and transported it to the Quality, the data content is all ok, except that i have not used the Project Naming conventions. Now i have a defect against my name for this. I have to copy the same query with the correct
-
Apple TV and Home Sharing "An error occurred loading this content"
Recently I moved and switched my homeshare library from my Mac to a Window8 PC. I'm running the same network equipent, but the bandwidth to the internet was less in the new place then the old one so I wanted to store more on the PC. My bandwidth to t
-
ICal still shows previous day in ical proper, but shows current date in the dock
iCal is open in the MONTH, on my desktop permanently, but it continually shows yesterdays date. It isn't till I actually click on the following day in iCal proper that the date changes to the current date. The iCal icon on the dock works fine with n
-
I have gotten as far as adding a new app, naming the folder and going into CRD, for the report we need online and attempted to enter the settings information for our sharepoint site. The issue is no matter how I enter the credentials it will not auth
-
Creating a photo collage in Iphoto
Does anyone know if it is possible to grab some photos in Iphoto and arrange them or stick them together to make a collage?