How to write the pl/sql code for this scenario
Hi,
Here is the data in a Table with below colums
id firstname lastname code
1 scott higgins 001
2 Mike Ferrari 001
3 Tom scottsdale 002
4 Nick pasquale 003
1 scott higgins 004
I want to trap the following exceptions into an error table using pl/sql
1. same person having multiple code
example
id first last Code
1 scott higgins 001
1 scott higgins 004
2. Multiple persons having same code
id first last Code
1 scott higgins 001
2 Mike Ferrari 001
Could you please help me how to capture the exceptions above using pl/sql
and what will be the structure of error table. it should capture eff date & end date
or using analytic functions like this:
select id, fname, lname, code from (
with t as(
select 1 id, 'scott' fname, 'higgins' lname, 001 code from dual
union all
select 2 id,'Mike ' fname, 'Ferrari' lname, 001 code from dual
union all
select 3 id,'Tom' fname, 'scottsdale' lname, 002 code from dual
union all
select 4 id,'Nick' fname, 'pasquale' lname, 003 code from dual
union all
select 5 id,'scott' fname, 'higgins' lname, 004 code from dual
select t.*, count(*) over (partition by fname) row_count from t)
where row_count > 1;
select id, fname, lname, code from (
with t as(
select 1 id, 'scott' fname, 'higgins' lname, 001 code from dual
union all
select 2 id,'Mike ' fname, 'Ferrari' lname, 001 code from dual
union all
select 3 id,'Tom' fname, 'scottsdale' lname, 002 code from dual
union all
select 4 id,'Nick' fname, 'pasquale' lname, 003 code from dual
union all
select 5 id,'scott' fname, 'higgins' lname, 004 code from dual
select t.*, count(*) over (partition by code) row_count from t)
where row_count > 1;
Similar Messages
-
How to get the restriction pass code for iPhone ?
How to get the restriction pass code for iPhone ?
if you forgot it you have to restore your phone to get past that code
-
Hi,
I need a PL/SQL code for this one...
Let me know if something is not clear...
1) The table CLOB_CLOBJECT_CDA has the columns described below...
Explaining only those fields which are important in this context
-- CDA_STEP_ID : Basically a Sequence
-- CLOBJECT_SOURCE1_ID : Every id has got a set of records
-- CLOBJECT_SOURCE2_ID : Every id has got a set of records
-- LVL : There are total 8 levels..
This is the main aim :
1) There are total 16 million rows..(limited to 10 rows here)
2) We need to go through level by level (LVL column) & insert the intersection records (CLOBJECT_SOURCE1_ID intersect CLOBJECT_SOURCE2_ID)
into another table...but this is how it goes..
Level (LVL column) 3's basically have CLOBJECT_SOURCE1_ID as level (LVL column) 2 CDA_STEP_ID's..
(consider the statement --** where CLOBJECT_SOURCE1_ID = 285 which is same as 1st insert statement step id)..
The above process goes for next levels until 8..(so have to use loops)
So for ex :
We go through the first insert statement and insert the insertion records only when both CLOBJECT_SOURCE1_ID & CLOBJECT_SOURCE2_ID has got records ..
If we don't find any records for both of them we should skip the corresponding step id when we go to the next levels...
Let's go through the 1st insert statement...
-- We have CDA_STEP_ID = 285 & two sources CLOBJECT_SOURCE1_ID as 19 & CLOBJECT_SOURCE2_ID as 74...
-- We see the table CLOBJECT_COUNTS & check whether we have counts for both 19 & 74 ..(In fact we insert counts into this table only if they have records)
-- If so, we insert the intersection records into CDA_MRN_RESULTS ( we do have counts for both of them..) with CDA_STEP_ID 285...
-- Then we insert the step id which is 285 along with the count into CLOBJECT_COUNTS..
Let's go through another insert statement...
-- Consider CDA_STEP_ID = 288 which has two sources CLOBJECT_SOURCE1_ID as 19 & CLOBJECT_SOURCE2_ID as 92...
-- We see the table CLOBJECT_COUNTS & check whether we have counts for both 19 & 92 ..(we have records for 19 but not for 92)
-- So we should not proceed with this..& also skip all those records (future records with increasing levels..basically level 3's) which have got 288 as CLOBJECT_SOURCE1_ID..
(As said earlier that the present CDA_STEP_ID will always be CLOBJECT_SOURCE1_ID in the next level)...
I wrote the following code which is after the statement...
Let me have the create & insert statements here..
create table CLOB_CLOBJECT_CDA
CDA_STEP_ID NUMBER,
CDA_ID NUMBER,
CDA_SEQ_NUMBER NUMBER,
CLOBJECT_SOURCE1_TYPE VARCHAR2(3000),
CLOBJECT_SOURCE1_ID NUMBER,
CLOBJECT_OPERATOR VARCHAR2(3000),
CLOBJECT_SOURCE2_TYPE VARCHAR2(3000),
CLOBJECT_SOURCE2_ID NUMBER,
LVL NUMBER
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (285, 285, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 74, 2);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (286, 286, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 75, 2);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (287, 287, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 91, 2);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (288, 288, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 92, 2);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4869, 4869, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 91, 3); -- **
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4870, 4870, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 92, 3);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4871, 4871, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 93, 3);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4880, 4880, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 91, 3);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4881, 4881, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 92, 3);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4882, 4882, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 93, 3);
create table CDA_MRN_RESULTS
CDA_STEP_ID NUMBER,
MRN NUMBER,
INSERT_DATE_TIME DATE
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (19, 1, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (19, 2, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (19, 3, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (74, 1, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (74, 2, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (74, 4, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (75, 1, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (75, 2, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (75, 6, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (91, 2, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (91, 3, to_date('19-10-2011', 'dd-mm-yyyy'));
create table CLOBJECT_COUNTS
CDA_STEP_ID NUMBER,
CLOBJECT_COUNT NUMBER,
DATE_TIME DATE
Insert into CLOBJECT_COUNTS values (19,3, to_date('19-10-2011', 'dd-mm-yyyy'));
Insert into CLOBJECT_COUNTS values (74,3, to_date('19-10-2011', 'dd-mm-yyyy'));
Insert into CLOBJECT_COUNTS values (75,3, to_date('19-10-2011', 'dd-mm-yyyy'));
Insert into CLOBJECT_COUNTS values (91,2, to_date('19-10-2011', 'dd-mm-yyyy'));The output goes into two tables...
CDA_MRN_RESULTS : O/p of intersection records between source1 & source2 id
CLOBJECT_COUNTS : Step id with counts ...(useful for skipping next level step id's if either of source id has "0" counts)
Any help is appreciated..
Thanks..I tried to code this..but looping takes a lot of time..I want to skip certain rows where source1_step_id & source_2_step_id are not in clobject_counts table as we proceed to the next levels..Not sure how to skip the rows..
declare
cursor c1 (p_level varchar2 ) is
Select * from clob_clobject_cda
where lvl = p_level ;
TYPE V_TT IS TABLE OF C1%ROWTYPE INDEX BY PLS_INTEGER;
L_TT V_TT;
v1 number;
v2 number;
v_step_id number;
v_operator varchar2(100) := '';
begin
for i in 2..8 loop
open c1(i);
LOOP
FETCH C1 BULK COLLECT INTO L_TT LIMIT 500;
FOR indx IN 1 .. L_TT.COUNT
LOOP
v1 := L_TT(indx).clobject_source1_id;
v2 := L_TT(indx).clobject_source2_id;
v_step_id := L_TT(indx).cda_step_id;
v_operator := L_TT(indx).clobject_operator;
Execute Immediate ('Insert into cda_mrn_results Select --+ parallel (cm 128)
distinct ' || v_step_id || ', mrn, trunc(sysdate) dt from cda_mrn_results cm
where cda_step_id = ' || v1 || '
and cda_step_id in (Select cda_step_id from clobject_counts) ' ||
v_operator ||
' Select --+ parallel (cm 128)
distinct ' || v_step_id || ', mrn, trunc(sysdate) dt from cda_mrn_results cm
where cda_step_id = ' || v2 || '
and cda_step_id in (Select cda_step_id from clobject_counts) ' );
Insert --+ Append
into clobject_counts Select cda_step_id, count(distinct mrn),
insert_date_time dt from cda_mrn_results where cda_step_id = v_step_id group by cda_step_id,insert_date_time;
COMMIT;
END LOOP;
EXIT WHEN L_TT.COUNT = 0;
END LOOP;
CLOSE C1;
End Loop;
Commit;
End; -
How to capture the exact SQL exception for failure to connect to database
Hi, i would like to capture the exact exception for failure to connect to a Oracle 9i database (via JDBC). I learnt that there is specific code or exception that can be captured, so that a more proper error message can be thrown out like "Failure to connect to database" can be displayed. Anyone know how to go about doing it? thanks
That depends on your database vendor, I believe. (Unless there's a SQL standard for states and codes that I'm unaware of.)
Personally, I wouldn't worry about "catching" a particular code. (You've already caught the exception - that's the best you can do.) I'd report the error code and state and just look up what it means when I got one.
Hopefully you won't be catching exceptions. They're supposed to be rare. - MOD -
How to compile the DB lookup code for XI:
Dear All,
i am very new to java and XI. Please let me know how to compile a Java Code for DB lookup and put in the imported Archive in IR. is there a seperate way to do it? Please guide me step by step. for performing Communication channel DB lookup.
I have gone through the Communication channel lookup of siva,
/people/siva.maranani/blog/2005/08/23/lookup146s-in-xi-made-simpler
but i am not understanding how to compile the given code in Advanced user functions area without any mandetory .jar files and header files. and put it into XI .
please guide me.
I mean i use a jdk1.4.2 Compiler as my XI server has 1.4.2 compiler.
Regards,
prakash
Edited by: senthilprakash selvaraj on Jun 17, 2008 4:03 AM
Edited by: senthilprakash selvaraj on Jun 17, 2008 4:04 AMHi,
You don't have to worry about compliation. XI will automatically comple it when you create the udf, activate it and test your mapping. In case of any error it will give compliation error there itself.
Regarding all the mandatory jar files which are required for compilation is already available in XI server.
If you are using any third party libraries(jar files) you just need to add the jar file in your external definition and need to import the necessary packages in User Define Function. I hope it answers all your questions.
Thanks
Amit
Reward point if answer is helpful -
How to edit the html source code for my site
I have just started a blog, and am VERY new to it. I am trying to edit the html source code on my site (ie, to insert google adsense search bars). I go to my blog site, get to page source and see the html but I am not able to edit it. Not sure what I am doing wrong. Thanks!
You can use any editor you want mine is set up for notepad.exe
:see http://dmcritchie.mvps.org/firefox/firefox.htm#notepad
:to invoke use "Ctrl+U" or View > Page Source
:this is for sites that you maintain on your local drives or servers, and copy over to a website. -
How to get the embed html code for my webpage so I can use it on eBay listings?
Hi, I already created a Muse webpage, but when i export it as html I get a code that is not compatible with eBay because eBay won't allow "cookies" nor "iFrame" on a listing.. is there a way around so I can get a working html code for eBay? I'm new at this, I don't have coding knowledge. I've never use Dreamweaver either, Muse is appealing since is user friendly, so any good explanation would be greatly appreciated. Thank you.
Hi, muse is an application made for create websites without coding skills, not to replace any possible use of HTML. If you would like to adapt your code for other uses, like CMS integration, Newsletters, build mobile apps, and other, you will need some coding skills.
-
Kindly write some sample code for this scenario
Kindly write some sample code for the below Logic.
For a set of Deliveries entered on the selection screen get the relevant data from LIKP & LIPS.
for all the deliveries selected get the sales order data from VBAK & VBAP based on the VGBEL & VGPOS in LIPS.
The Output internal table should contain only deliveries which are created with reference to a sales order.
Thanx in Advance.
Akshitha.Hi,
Select avbeln bposnr bmatnr blfimg bvgbel bvgpos into table ITAB
from likp as a join lips as b on Avbeln = bvbeln
where a~vbeln in s_vbeln..
if not itab[] is initial.
select avbeln bposnr b~matnr ... into table itab1 from vbak as a join vbap as b
on avbeln = bvbeln
for all entries in itab where avbeln = itab-vgbel and bposnr = itab-vgpos.
endif.
loop at itab.
read table itab1 with key vbeln = itab-vgbel posnr = itab-vgpos.
if sy-subrc <> 0.
delete itab index sy-tabix.
endif.
endloop.
Now ITAB will have only deliveries created against Sales orders.
reward points if useful
regards,
Anji -
How to solve the error "Ref Count for this object is greater then 0"
Hi,
I'm trying to add UDF at runtime to an already created UDT which is of No Object Type.
my code is as follows:
dim oUserFieldsMD As SAPbobsCOM.UserFieldsMD
oUserFieldsMD = ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
oUserFieldsMD.TableName = "@TI_ADDCODES"
oUserFieldsMD.Name = codetoinsert
oUserFieldsMD.Description = desctoinsert
'Add the field to the table
lRetCode = oUserFieldsMD.Add
If lRetCode <> 0 Then
ocompany.GetLastError(lErrCode, sErrMsg)
MsgBox(sErrMsg)
Else
MsgBox("Field: '" & oUserFieldsMD.Name & "' was added successfuly to " & oUserFieldsMD.TableName & " Table")
End If
I got error msg as "Ref Count for this object is greater then 0" and error code is -1120
how to rectify it?
Thanks in advance!!!Hi,
Have you searched the forum? You may check this first: error -1120 when adding UserTableMD.
Thanks,
Gordon -
Any description on how to use the Text Editor used for this Forum?
I am very frustrated when trying to use the text Editing functions (without use of HTML, that I do not undertstand) that can be used to create Posts in this Forum .
Can somebody point me to a good description of the Text Editor used to enter/edit Posts in this Forum? Thanks a lot in advance.Ian,
Thank You very much for your answer.
Based on your answer, I guess and fear, that there exist no "user guide" for this Text Editor.
I will wait a little bit more to see whether I get more information/answers. If not, i will probably write a "Feature Request" to request that Adobe provides us or point us to a reasonable User-Guide for this Text Editor. -
How to undo the "never store password for this site"?
A friend did this on my computer on a site where I'm very frequently logging in.
How can I erase this preference just for this site, i.e. I want Safari to ask me again whether I want my password stored and then answer yes.Safari > Preferences > AutoFill > User names and passwords: Edit...
-
Want help in deciding the method of development for this scenario
Hi,
My requirement is to create one screen where customer enters shipment #, and ship-to information and say continue, he will be shown another screen with shipment details, and combo box to select appointment time. when he clicks on Make Appointment button of this screen, he needs to be shown confirmation screen with the appointment information being stored in sap tables. I want to know the best method of creating this peice of application. If you have any question, please feel free to ask them.
Thank you,
SuryaHi Surya,
Just develop a small ALV for this application. It will best suite to your scenario.If you know to develop ALV using OO then its very simple, or you can just search throgh the SDN you will find lots of sample code to do the same.
Regards,
Atish -
What is the best Skype setup for this scenario?
I live in the United States and about to be deployed to Afghanistan for about one year. I will have a laptop and an International capable Android phone, both with Skype software installed. I want to be able to use Skype to Skype via the laptop, and also be able to call both landlines and cell phones in the United States while I am in Afghanistan. What would be the best Skype subscription plan in this scenario to keep costs to a minimum.
Hi,
As you probably know, Skype to Skype calls are free, but if you wish to call phones then you would need a subscription that covers calling destination.
You might find Unlimited US&Canada subscription from: http://www.skype.com/go/subscriptions
Fair usage policy applies, but 6hours per day should be more than enough to call your family and friends back home in US.
http://www.skype.com/go/terms.fairusage
Skype also offers Online Numbers for US. For example if you purchase an Online Number in US then your friends who don't have Skype can call that number. They will be charged with local rates and call will be directed to your Skype account when you are online on your phone or laptop.
Tip: If you do decide to purchase an Online Number for 12months then purchase calling subscription first and you will get 50% discount on Online Number.
https://support.skype.com/en/faq/FA331/What-is-an-Online-Number
Andre
If answer was helpful please mark it with Kudos and if issue is resolved mark it with solution. This will help other users find this answer more easily. Thanks in advance! -
Cannot write the suitable source codes for running program
I want to write a program that help student to compile program and run program by using some test cases. For the compiled part, i have been wrote it successfully, but for the run part, i cannot pass the test cases to the program for running. Could any ppl help me to find the problem on the followng codes, why the error will on there? how do i change it? Thanks!
//<!--start get Program Test Case File-->
java.io.BufferedReader TestCaseBuf = null;
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:compas", "sa", "password");
stmt = con.createStatement();
String strSQL = "SELECT testValue FROM TEST_CASE WHERE progID='"+progID+"'";
stmt = con.createStatement();
rs = stmt.executeQuery(strSQL);
try
while (rs.next())
TestCaseBuf = new java.io.BufferedReader(new java.io.InputStreamReader(rs.getBinaryStream("testValue")));
finally
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
//<!--end get Program Test Case File-->
//<!--start run program -->
String[ ] args2 = new String[ ]
"java", "-cp", System.getProperty("user.dir"), FileName
try
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(args2);
java.io.BufferedReader ireader = new java.io.BufferedReader(new java.io.InputStreamReader(proc.getInputStream()));
java.io.PrintWriter pwriter = new java.io.PrintWriter(proc.getOutputStream());
String atestcase = null;
String line= null;
try
while ((atestcase = TestCaseBuf.readLine()) != null) <------------I found that error seems on here!!!!
pwriter.write(atestcase+"\r");
pwriter.flush();
if (atestcase != null)
if ((line = ireader.readLine()) != null)
FileOutput = FileOutput + line +"\r\n";
else {break; }
} //while
catch (java.io.IOException e)
out.println("[IOException]. Printing Stack Trace");
e.printStackTrace();
pwriter.close();
ireader.close();
catch (java.io.IOException e)
out.println("[IOException]. Printing Stack Trace");
e.printStackTrace();
//<!--end run program -->Whats the error message??
Just a guess, but could be (without seeing the error) that you've already closed the TestCaseBuf reader by closing the result set, hence when you go to read it, you're reading on closed reader.
Give this a go...Put the //<!--run program --> code into the result set while loop
while (rs.next())
TestCaseBuf = new java.io.BufferedReader(new java.io.InputStreamReader(rs.getBinaryStream("testValue")));
//<!--start run program -->
...some code
//<!--end run program -->
} Hard to tell without the error message -
How to understand the Vector source code for function elements()?
hello all:
This following code snippet is extracted from java.util.Vector source code.
who can tell me how i can understand what the function nextElement does?
thank you
public Enumeration elements() {
return new Enumeration() {
int count = 0;
public boolean hasMoreElements() {
return count < this.num_elem;
public Object nextElement() {
synchronized (Vector.this) { //???
if (count < elementCount) {//???
return elementData[count++];
throw new NoSuchElementException("Vector Enumeration");
}Perhaps code would help more. This codeimport java.util.Vector;
import java.util.Enumeration;
import java.util.Iterator;
public class Test {
public static void main(String[] arghs) {
Vector v = new Vector();
Integer two = new Integer(2);
// Fill the Vector
v.add("One");
v.add(two);
v.add(new StringBuffer("Three"));
// Enumerate through the objects in the vector
System.out.println("---- Enumeration ----");
Enumeration e = v.elements();
while (e.hasMoreElements()) System.out.println(e.nextElement());
// Loop through the objects in the vector
System.out.println("---- Loop ----");
for (int i=0; i<v.size(); i++) System.out.println(v.get(i));
// Iterate through the objects in the vector
System.out.println("---- Iterator ----");
Iterator i = v.iterator();
while (i.hasNext()) System.out.println(i.next());
}produces this output
---- Enumeration ----
One
2
Three
---- Loop ----
One
2
Three
---- Iterator ----
One
2
Three
So, for a Vector, all three do the same thing. However, Iterator is part of the Collection Framework (see [url http://java.sun.com/j2se/1.4.2/docs/guide/collections/index.html]here). This allows you to treat a whole bunch of [url http://java.sun.com/j2se/1.4.2/docs/guide/collections/reference.html]objects which implement the Collection interface all the same way. I know this is way more than you were asking, but I hope it at least clears up what you were asking.
Maybe you are looking for
-
Four bug fixes in, how can iTunes still not be displaying movies properly? When I look at the movies in my playlist in Grid View (sort by Title), the movies display at random. Plus, what does "Title" mean? There's no "title" listing in the Get Info.
-
Monday November 11,2013-Dear firefox,I have several questions and several complaints also.-) why am I receiving 3 party emails and it states on this download if you don't want them to have a check Mark by this. I have done away with 3 party emails,no
-
how do I get my mbox to work with garage band? Ive got my mic, mixer, and mbox interface. how should i hook everything up??? the only way i can get the interface working is through mono and it is horrible.. someone please HELP!!!
-
PS CS6 Extended student edition recognizing Nikon D610 NEF (raw) files
I am considering purchasing the PS CS6 Extended Student edition (this is the licensed program, NOT the subscription CC version). Can anyone verify that this will recognize Nikon D610 NEF files? Thanks
-
Will I be able to keep my current data plan when I buy the new iPhone 5.
Will I be able to keep my current data plan when I buy the new iPhone 5.