How to add cursor and for loop
PROCEDURE "TEST" is
bala number;
ins1 number;
ins2 number;
BEGIN
select sum(bal) into bala from (select sum(acp.acp_totbal) bal,acp_instruid from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and c_srm_prncplinsid=acp_instruid
and acp_acntnum!='SG030001'
group by acp_instruid
union
select sum(acp.acp_totbal) bal,acp_instruid from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and acp_acntnum!='SG030001'
and acp_instruid=c_srm_prntinsid
group by acp_instruid)view1;
dbms_output.put_line(bala);
select acp_instruid into ins1 from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and c_srm_prncplinsid=acp_instruid
and acp_acntnum='SG030001';
dbms_output.put_line('principal'||ins1);
select acp_instruid into ins2 from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and acp_acntnum='SG030001'
and acp_instruid=c_srm_prntinsid;
dbms_output.put_line('parent'||ins2);
update cs_acpos_bkp
set acp_totbal=-bala
where acp_instruid=ins2
and acp_acntnum='SG030001';
END;
i have written this code,i need to use cursor and for loops to get more than one rows and update also.
if there are more than 1 rows in cs_strmap_t,then the procedure throws an error stating that it cannot take 2 rows.
Edited by: 850836 on Apr 7, 2011 11:43 PM
PROCEDURE "TEST" is
bala number;
ins1 number;
ins2 number;
CURSOR cur_1 IS
select sum(bal) bala from (select sum(acp.acp_totbal) bal,acp_instruid from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and c_srm_prncplinsid=acp_instruid
and acp_acntnum='SG030001'
group by acp_instruid
union
select sum(acp.acp_totbal) bal,acp_instruid from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and acp_acntnum='SG030001'
and acp_instruid=c_srm_prntinsid
group by acp_instruid)view1;
BEGIN
select acp_instruid into ins1 from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and c_srm_prncplinsid=acp_instruid
and acp_acntnum='SG030001';
dbms_output.put_line('principal'||ins1);
select acp_instruid into ins2 from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
where c_int_instruid=c_srm_prncplinsid
and acp_acntnum='SG030001'
and acp_instruid=c_srm_prntinsid;
dbms_output.put_line('parent'||ins2);
for var_for in cur_1
loop
update cs_acpos_bkp
set acp_totbal=var_for.bala
where acp_instruid=ins2
and acp_acntnum='SG030001'
and abs(acp_totbal)>abs(bala);
dbms_output.put_line(bala);
end loop;
END;
i wrote the following procedure,but the balance is not getting updated.
Getting this errors when there are more than 1 row in cs_strmap_t table
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: line 22
ORA-06512: at line 2
Similar Messages
-
Help with if statement in cursor and for loop to get output
I have the following cursor and and want to use if else statement to get the output. The cursor is working fine. What i need help with is how to use and if else statement to only get the folderrsn that have not been updated in the last 30 days. If you look at the talbe below my select statement is showing folderrs 291631 was updated only 4 days ago and folderrsn 322160 was also updated 4 days ago.
I do not want these two to appear in my result set. So i need to use if else so that my result only shows all folderrsn that havenot been updated in the last 30 days.
Here is my cursor:
/*Cursor for Email procedure. It is working Shows userid and the string
You need to update these folders*/
DECLARE
a_user varchar2(200) := null;
v_assigneduser varchar2(20);
v_folderrsn varchar2(200);
v_emailaddress varchar2(60);
v_subject varchar2(200);
Cursor c IS
SELECT assigneduser, vu.emailaddress, f.folderrsn, trunc(f.indate) AS "IN DATE",
MAX (trunc(fpa.attemptdate)) AS "LAST UPDATE",
trunc(sysdate) - MAX (trunc(fpa.attemptdate)) AS "DAYS PAST"
--MAX (TRUNC (fpa.attemptdate)) - TRUNC (f.indate) AS "NUMBER OF DAYS"
FROM folder f, folderprocess fp, validuser vu, folderprocessattempt fpa
WHERE f.foldertype = 'HJ'
AND f.statuscode NOT IN (20, 40)
AND f.folderrsn = fp.folderrsn
AND fp.processrsn = fpa.processrsn
AND vu.userid = fp.assigneduser
AND vu.statuscode = 1
GROUP BY assigneduser, vu.emailaddress, f.folderrsn, f.indate
ORDER BY fp.assigneduser;
BEGIN
FOR c1 IN c LOOP
IF (c1.assigneduser = v_assigneduser) THEN
dbms_output.put_line(' ' || c1.folderrsn);
else
dbms_output.put(c1.assigneduser ||': ' || 'Overdue Folders:You need to update these folders: Folderrsn: '||c1.folderrsn);
END IF;
a_user := c1.assigneduser;
v_assigneduser := c1.assigneduser;
v_folderrsn := c1.folderrsn;
v_emailaddress := c1.emailaddress;
v_subject := 'Subject: Project for';
END LOOP;
END;
The reason I have included the folowing table is that I want you to see the output from the select statement. that way you can help me do the if statement in the above cursor so that the result will look like this:
emailaddress
Subject: 'Project for ' || V_email || 'not updated in the last 30 days'
v_folderrsn
v_folderrsn
etc
[email protected]......
Subject: 'Project for: ' Jim...'not updated in the last 30 days'
284087
292709
[email protected].....
Subject: 'Project for: ' Kim...'not updated in the last 30 days'
185083
190121
190132
190133
190159
190237
284109
286647
294631
322922
[email protected]....
Subject: 'Project for: Joe...'not updated in the last 30 days'
183332
183336
[email protected]......
Subject: 'Project for: Sam...'not updated in the last 30 days'
183876
183877
183879
183880
183881
183882
183883
183884
183886
183887
183888
This table is to shwo you the select statement output. I want to eliminnate the two days that that are less than 30 days since the last update in the last column.
Assigneduser....Email.........Folderrsn...........indate.............maxattemptdate...days past since last update
JIM......... jim@ aol.com.... 284087............. 9/28/2006.......10/5/2006...........690
JIM......... jim@ aol.com.... 292709............. 3/20/2007.......3/28/2007............516
KIM......... kim@ aol.com.... 185083............. 8/31/2004.......2/9/2006............. 928
KIM...........kim@ aol.com.... 190121............. 2/9/2006.........2/9/2006.............928
KIM...........kim@ aol.com.... 190132............. 2/9/2006.........2/9/2006.............928
KIM...........kim@ aol.com.... 190133............. 2/9/2006.........2/9/2006.............928
KIM...........kim@ aol.com.... 190159............. 2/13/2006.......2/14/2006............923
KIM...........kim@ aol.com.... 190237............. 2/23/2006.......2/23/2006............914
KIM...........kim@ aol.com.... 284109............. 9/28/2006.......9/28/2006............697
KIM...........kim@ aol.com.... 286647............. 11/7/2006.......12/5/2006............629
KIM...........kim@ aol.com.... 294631............. 4/2/2007.........3/4/2008.............174
KIM...........kim@ aol.com.... 322922............. 7/29/2008.......7/29/2008............27
JOE...........joe@ aol.com.... 183332............. 1/28/2004.......4/23/2004............1585
JOE...........joe@ aol.com.... 183336............. 1/28/2004.......3/9/2004.............1630
SAM...........sam@ aol.com....183876.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183877.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183879.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183880.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183881.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183882.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183883.............3/5/2004.........3/8/2004.............1631
SAM...........sam@ aol.com....183884.............3/5/2004.........3/8/2004............ 1631
SAM...........sam@ aol.com....183886.............3/5/2004.........3/8/2004............ 1631
SAM...........sam@ aol.com....183887.............3/5/2004.........3/8/2004............ 1631
SAM...........sam@ aol.com....183888.............3/5/2004.........3/8/2004............ 1631
PAT...........pat@ aol.com.....291630.............2/23/2007.......7/8/2008............ 48
PAT...........pat@ aol.com.....313990.............2/27/2008.......7/28/2008............28
NED...........ned@ aol.com.....190681.............4/4/2006........8/10/2006............746
NED...........ned@ aol.com......95467.............6/14/2006.......11/6/2006............658
NED...........ned@ aol.com......286688.............11/8/2006.......10/3/2007............327
NED...........ned@ aol.com.....291631.............2/23/2007.......8/21/2008............4
NED...........ned@ aol.com.....292111.............3/7/2007.........2/26/2008............181
NED...........ned@ aol.com.....292410.............3/15/2007.......7/22/2008............34
NED...........ned@ aol.com.....299410.............6/27/2007.......2/27/2008............180
NED...........ned@ aol.com.....303790.............9/19/2007.......9/19/2007............341
NED...........ned@ aol.com.....304268.............9/24/2007.......3/3/2008............ 175
NED...........ned@ aol.com.....308228.............12/6/2007.......12/6/2007............263
NED...........ned@ aol.com.....316689.............3/19/2008.......3/19/2008............159
NED...........ned@ aol.com.....316789.............3/20/2008.......3/20/2008............158
NED...........ned@ aol.com.....317528.............3/25/2008.......3/25/2008............153
NED...........ned@ aol.com.....321476.............6/4/2008.........6/17/2008............69
NED...........ned@ aol.com.....322160.............7/3/2008.........8/21/2008............4
MOE...........moe@ aol.com.....184169.............4/5/2004.......12/5/2006............629
[email protected]/27/2004.......3/8/2004............1631
How do I incorporate a if else statement in the above cursor so the two days less than 30 days since last update are not returned. I do not want to send email if the project have been updated within the last 30 days.
Edited by: user4653174 on Aug 25, 2008 2:40 PManalytical functions: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/functions2a.htm#81409
CASE
http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/02_funds.htm#36899
http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/04_struc.htm#5997
Incorporating either of these into your query should assist you in returning the desired results. -
The query below will return values in the form of
bu seq eligible
22 2345 Y
22 2345 N
22 1288 N
22 1458 Y
22 1458 N
22 1234 Y
22 1333 N
What I am trying to accomplish is to loop through the records returned.
for each seq if there is a 'N' in the eligible column return no record for that seq
eg seq 2345 has 'Y' and 'N' thus no record should be returned.
seq 1234 has only a 'Y' then return the record
seq 1333 has 'N' so return no record.
How would I accomplish this with a ref Cursor and pass the values to the front end application.
Procedure InvalidNOs(io_CURSOR OUT T_CURSOR)
IS
v_CURSOR T_CURSOR;
BEGIN
OPEN v_CURSOR FOR
' select bu, seq, eligible ' ||
' from (select bu, seq, po, tunit, tdollar,eligible,max(eligible) over () re ' ||
' from (select bu, seq, po, tunit, tdollar,eligible ' ||
' from ( ' ||
' select bu, seq, po, tunit, tdollar, eligible, sum(qty) qty, sum(price*qty) dollars ' ||
' from ' ||
' ( select /*+ use_nl(t,h,d,s) */ ' ||
' h.business_unit_id bu, h.edi_sequence_id seq, d.edi_det_sequ_id dseq, ' ||
' s.edi_size_sequ_id sseq, h.po_number po, h.total_unit tUnit, h.total_amount tDollar, ' ||
' s.quantity qty, s.unit_price price,' ||
' (select (case when count(*) = 0 then ''Y'' else ''N'' end) ' ||
' from sewn.NT_edii_po_det_error ' ||
' where edi_det_sequ_id = d.edi_det_sequ_id ' ||
' ) eligible ' ||
' from sewn.nt_edii_purchase_size s, sewn.nt_edii_purchase_det d, ' ||
' sewn.nt_edii_purchase_hdr h, sewn.nt_edii_param_temp t ' ||
' where h.business_unit_id = t.business_unit_id ' ||
' and h.edi_sequence_id = t.edi_sequence_id ' ||
' and h.business_unit_id = d.business_unit_id ' ||
' and h.edi_sequence_id = d.edi_sequence_id ' ||
' and d.business_unit_id = s.business_unit_id ' ||
' and d.edi_sequence_id = s.edi_sequence_id ' ||
' and d.edi_det_sequ_id = s.edi_det_sequ_id ' ||
' ) group by bu, seq, po, tunit, tdollar, eligible ' ||
' ) ' ||
' group by bu, seq, po, tunit, tdollar, eligible)) ';
io_CURSOR := v_CURSOR;
END InvalidNOs;One remark why you should not use the assignment between ref cursor
variables.
(I remembered I saw already such thing in your code).
Technically you can do it but it does not make sense and it can confuse your results.
In the opposite to usual variables, when your assignment copies value
from one variable to another, cursor variables are pointers to the memory.
Because of this when you assign one cursor variable to another you just
duplicate memory pointers. You don't copy result sets. What you do for
one pointer is that you do for another and vice versa. They are the same.
I think the below example is self-explained:
SQL> /* usual variables */
SQL> declare
2 a number;
3 b number;
4 begin
5 a := 1;
6 b := a;
7 a := a + 1;
8 dbms_output.put_line('a = ' || a);
9 dbms_output.put_line('b = ' || b);
10 end;
11 /
a = 2
b = 1
PL/SQL procedure successfully completed.
SQL> /* cursor variables */
SQL> declare
2 a sys_refcursor;
3 b sys_refcursor;
4 begin
5 open a for select empno from emp;
6 b := a;
7 close b;
8
9 /* next action is impossible - cursor already closed */
10 /* a and b are the same ! */
11 close a;
12 end;
13 /
declare
ERROR at line 1:
ORA-01001: invalid cursor
ORA-06512: at line 11
SQL> declare
2 a sys_refcursor;
3 b sys_refcursor;
4 vempno emp.empno%type;
5
6 begin
7 open a for select empno from emp;
8 b := a;
9
10 /* Fetch first row from a */
11 fetch a into vempno;
12 dbms_output.put_line(vempno);
13
14 /* Fetch from b gives us SECOND row, not first -
15 a and b are the SAME */
16
17 fetch b into vempno;
18 dbms_output.put_line(vempno);
19
20
21 end;
22 /
7369
7499
PL/SQL procedure successfully completed.Rgds.
Message was edited by:
dnikiforov -
Why use cursor and for loop?
Hi All
So in general why would we use a cursor and a for loop to do update in a stored procedure?
Why wouldnt we just use a single update statement ?
is there compelling reason for using a cursor and a for loop: I am reading some code from a co-worker that the business logic for the select (set need to be updated) is complex but the update logic is simple (just set a flag to (0 or 1 or 2 or 3 or 4).
But eventually the select come down to a key (row_id) so I re-write it using just a single sql statement.
The size of the main table is about 2.6 to 3million rows
Any thoughts on that??
The code below I just do a google for cursor for update example in case for something to play with
-Thanks for all your input
create table f (a number, b varchar2(10));
insert into f values (5,'five');
insert into f values (6,'six');
insert into f values (7,'seven');
insert into f values (8,'eight');
insert into f values (9,'nine');
commit;
create or replace procedure wco as
cursor c_f is
select a,b from f where length(b) = 5 for update;
v_a f.a%type;
v_b f.b%type;
begin
open c_f;
loop
fetch c_f into v_a, v_b;
exit when c_f%notfound;
update f set a=v_a*v_a where current of c_f;
end loop;
close c_f;
end;
exec wco;
select * from f;
drop table f;
drop procedure wco;
Joining multiple tables
create table numbers_en (
id_num number primary key,
txt_num varchar2(10)
insert into numbers_en values (1, 'one' );
insert into numbers_en values (2, 'two' );
insert into numbers_en values (3, 'three');
insert into numbers_en values (4, 'four' );
insert into numbers_en values (5, 'five' );
insert into numbers_en values (6, 'six' );
create table lang (
id_lang char(2) primary key,
txt_lang varchar2(10)
insert into lang values ('de', 'german');
insert into lang values ('fr', 'french');
insert into lang values ('it', 'italian');
create table translations (
id_num references numbers_en,
id_lang references lang,
txt_trans varchar2(10) not null
insert into translations values (1, 'de', 'eins' );
insert into translations values (1, 'fr', 'un' );
insert into translations values (2, 'it', 'duo' );
insert into translations values (3, 'de', 'drei' );
insert into translations values (3, 'it', 'tre' );
insert into translations values (4, 'it', 'quattro');
insert into translations values (6, 'de', 'sechs' );
insert into translations values (6, 'fr', 'six' );
declare
cursor cur is
select id_num,
txt_num,
id_lang,
txt_lang,
txt_trans
from numbers_en join translations using(id_num)
left join lang using(id_lang)
for update of translations.txt_trans;
rec cur%rowtype;
begin
for rec in cur loop
dbms_output.put (
to_char (rec.id_num , '999') || ' - ' ||
rpad (rec.txt_num , 10 ) || ' - ' ||
rpad(nvl(rec.txt_trans, ' '), 10 ) || ' - ' ||
rec.id_lang || ' - ' ||
rpad (rec.txt_lang , 10 )
if mod(rec.id_num,2) = 0 then
update translations set txt_trans = upper(txt_trans)
where current of cur;
dbms_output.put_line(' updated');
else
dbms_output.new_line;
end if;
end loop;
end;
/Edited by: xwo0owx on Apr 25, 2011 11:23 AMAdding my sixpence...
PL/SQL is not that different from a SQL perspective than any other SQL client language like Java or C# or C/C++. PL/SQL simply integrates the 2 languages a heck of a lot better and far more transparent than the others. But make no mistake in that PL/SQL is also a "client" language from a SQL perspective. The (internal) calls PL/SQL make to the SQL engine, are the same (driver) calls made to the SQL engine when using Java and C and the others.
So why a cursor and loops in PL/SQL? For the same reason you have cursors and loops in all these other SQL client languages. There are the occasion that you need to pull data from the SQL engine into the local language to perform some very funky and complex processing that is not possible using the SQL language.
The danger is using client cursor loop processing as the norm - always pulling rows into the client language and crunching it there. This is not very performant. And pretty much impossible to scale. Developers in this case views the SQL language as a mere I/O interface for reading and writing rows. As they would use the standard file I/O read() and write() interface calls.
Nothing could be further from the truth. SQL is a very advance and sophisticated data processing language. And it will always be faster than having to pull rows to a client language and process them there. However, SQL is not Turing complete. It is not the procedural type language that most other languages we use, are. For that reason there are things that we cannot do in SQL. And that should be the only reason for using the client language, like PL/SQL or the others, to perform row crunching using a client cursor loop. -
Using Cursor and FOR LOOP to INSERT the data into table
Hi all,
I have SELECT statement that returns 3 rows:
PROCESSNAME
PROTDATE
IMM
2013-12-18
Metrology
2013-11-18
CT
2013-12-04
SELECT processName, MAX(NVL(protStartDate, protCreateDate)) AS protDate
FROM TABLE(SEM_MATCH("{
?ipc rdf:type s:Protocol .
?ipc s:protocolNumber ?protNum .
?ipc s:protocolCreateDate ?protCreateDate .
OPTIONAL {?ipc s:protocolSchedStartDate ?protStartDate }
?ipra rdf:type s:ProcessAggregate .
?ipra s:hasProtocol ?iprot .
?iprot s:protocolNumber ?protNum .
?ipra s:processAggregateProcess ?processName.
}",sem_models("PROTS", "LINEARS"),NULL, SEM_ALIASES(SEM_ALIAS("","http://VISION/Data/SEMANTIC#"),SEM_ALIAS("s","http://VISION/DataSource/SEMANTIC#")),NULL))
Group by processName
Now I need to INSERT these values into the table along with the other values.
these other values come from different table.
INSERT INTO MODEL_CLASS_COUNTS (MODEL_NAME, CLASS_NAME, INS_COUNT, COUNT_DATETIME, PROCESS_NAME, PROT_DATE)
VALUES
("$MODEL",
"${i}",
(SELECT COUNT (DISTINCT S) FROM TABLE(SEM_MATCH(
"{?s rdf:type :${i} . }",SEM_Models("$MODEL"),NULL, SEM_ALIASES(SEM_ALIAS("","http://VISION/DataSource/SEMANTIC#")),NULL))),
SYSTIMESTAMP, %%here need to insert PROCESSNAME, PROTDATE%%
t was giving me error:
PL/SQL: ORA-22905: cannot access rows from a non-nested table item
so i enclosed sparql query into single quotes.
The code is as follows:
declare
type c_type is REF CURSOR;
cur c_type;
v_process varchar2(200);
v_pdate varchar2(200);
begin
open cur for
' SELECT processName, MAX(NVL(protStartDate, protCreateDate)) AS protDate <-- it's complaining about this being too long identifier, i think...
FROM TABLE
(SEM_MATCH (
?ipc rdf:type s:Protocol .
?ipc s:protocolNumber ?protNum .
?ipc s:protocolCreateDate ?protCreateDate .
OPTIONAL {?ipc s:protocolSchedStartDate ?protStartDate }
?ipra rdf:type s:ProcessAggregate .
?ipra s:hasProtocol ?iprot .
?iprot s:protocolNumber ?protNum .
?ipra s:processAggregateProcess ?processName.
}",SEM_Models("XCOMPASS", "XPROCESS"),NULL,
SEM_ALIASES(SEM_ALIAS("","http://VISION/Data/SEMANTIC#"),
SEM_ALIAS("s", "http://VISION/DataSource/SEMANTIC#")),NULL))
Group by processName';
loop
fetch cur into v_process, v_pdate;
exit when cur%NOTFOUND;
--here I need to insert v_process , v_pdate into my table along with other values...
dbms_output.put_line('values for process and prod_date are: ' || v_process || v_pdate );
end loop;
close cur;
end;
exit;
Now, I get an error:
ORA-00972: identifier is too long
Does anyone know way around this?Hi,
I tested something similar with insert into select and it worked fine :
insert into t_countries(ID,CITY ,POPULATION, DESCRIPTION, located, insdate )
SELECT 1 id, city, o , city||' is a nice city' description, max(nvl(locatedAt,'unknown')) as located,
SYSTIMESTAMP
FROM TABLE(SEM_MATCH(
'{GRAPH :gCH {<http://www.semwebtech.org/mondial/10/countries/CH/> :hasCity ?cityID .
?cityID :name ?city .
OPTIONAL{?cityID :locatedAt ?locatedAt .}
?cityID :population ?o .
SEM_Models('VIRT_MODEL_MONDIAL'),
SEM_Rulebases(null),
SEM_ALIASES(SEM_ALIAS('','http://www.semwebtech.org/mondial/10/meta#'),
SEM_ALIAS('prv','http://www.semwebtech.org/mondial/10/countries/CH/provinces/')
null))
group by city,o
order by city;
Or with execute immediate :
declare
v_country varchar2(200) :='http://www.semwebtech.org/mondial/10/countries/F/';
v_text varchar2(2000);
begin
v_text := 'insert into t_countries(ID,CITY ,POPULATION, DESCRIPTION, located, insdate )
SELECT 1 id, city, o , city||'' is a nice city'' description, max(nvl(locatedAt,''unknown'')) as located,
SYSTIMESTAMP
FROM TABLE(SEM_MATCH(
''{<'||v_country||'> :hasCity ?cityID .
?cityID :name ?city .
OPTIONAL{?cityID :locatedAt ?locatedAt .}
?cityID :population ?o .
SEM_Models(''VIRT_MODEL_MONDIAL''),
SEM_Rulebases(null),
SEM_ALIASES(SEM_ALIAS('''',''http://www.semwebtech.org/mondial/10/meta#'') ),
null))
group by city,o
order by city';
dbms_output.put_line(v_text);
delete from t_countries;
execute immediate v_text ;
commit;
end;
Marc -
How can I repeat a for loop, once it's terms has been fulfilled???
Well.. I've posted 2 different exceptions about this game today, but I managed to fix them all by myself, but now I'm facing another problem, which is NOT an error, but just a regular question.. HOW CAN I REPEAT A FOR LOOP ONCE IT HAS FULFILLED IT'S TERMS OF RUNNING?!
I've been trying many different things, AND, the 'continue' statement too, and I honestly think that what it takes IS a continue statement, BUT I don't know how to use it so that it does what I want it too.. -.-'
Anyway.. Enought chit-chat. I have a nice functional game running that maximum allows 3 apples in the air in the same time.. But now my question is: How can I make it create 3 more appels once the 3 first onces has either been catched or fallen out the screen..?
Here's my COMPLETE sourcecode, so if you know just a little bit of Java you should be able to figure it out, and hopefully you'll be able to tell me what to do now, to make it repeat my for loop:
Main.java:
import java.applet.*;
import java.awt.*;
@SuppressWarnings("serial")
public class Main extends Applet implements Runnable
private Image buffering_image;
private Graphics buffering_graphics;
private int max_apples = 3;
private int score = 0;
private GameObject player;
private GameObject[] apple = new GameObject[max_apples];
private boolean move_left = false;
private boolean move_right = false;
public void init()
load_content();
setBackground(Color.BLACK);
public void run()
while(true)
if(move_left)
player.player_x -= player.movement_speed;
else if(move_right)
player.player_x += player.movement_speed;
for(int i = 0; i < max_apples; i++)
apple.apple_y += apple[i].falling_speed;
repaint();
prevent();
collision();
try
Thread.sleep(20);
catch(InterruptedException ie)
System.out.println(ie);
private void prevent()
if(player.player_x <= 0)
player.player_x = 0;
else if(player.player_x >= 925)
player.player_x = 925;
private void load_content()
MediaTracker media = new MediaTracker(this);
player = new GameObject(getImage(getCodeBase(), "Sprites/player.gif"));
media.addImage(player.sprite, 0);
for(int i = 0; i < max_apples; i++)
apple[i] = new GameObject(getImage(getCodeBase(), "Sprites/apple.jpg"));
try
media.waitForAll();
catch(Exception e)
System.out.println(e);
public boolean collision()
for(int i = 0; i < max_apples; i++)
Rectangle apple_rect = new Rectangle(apple[i].apple_x, apple[i].apple_y,
apple[i].sprite.getWidth(this),
apple[i].sprite.getHeight(this));
Rectangle player_rect = new Rectangle(player.player_x, player.player_y,
player.sprite.getWidth(this),
player.sprite.getHeight(this));
if(apple_rect.intersects(player_rect))
if(apple[i].alive)
score++;
apple[i].alive = false;
if(!apple[i].alive)
apple[i].alive = false;
return true;
public void update(Graphics g)
if(buffering_image == null)
buffering_image = createImage(getSize().width, getSize().height);
buffering_graphics = buffering_image.getGraphics();
buffering_graphics.setColor(getBackground());
buffering_graphics.fillRect(0, 0, getSize().width, getSize().height);
buffering_graphics.setColor(getForeground());
paint(buffering_graphics);
g.drawImage(buffering_image, 0, 0, this);
public boolean keyDown(Event e, int i)
i = e.key;
if(i == 1006)
move_left = true;
else if(i == 1007)
move_right = true;
return true;
public boolean keyUp(Event e, int i)
i = e.key;
if(i == 1006)
move_left = false;
else if(i == 1007)
move_right = false;
return true;
public void paint(Graphics g)
g.drawImage(player.sprite, player.player_x, player.player_y, this);
for(int i = 0; i < max_apples; i++)
if(apple[i].alive)
g.drawImage(apple[i].sprite, apple[i].apple_x, apple[i].apple_y, this);
g.setColor(Color.RED);
g.drawString("Score: " + score, 425, 100);
public void start()
Thread thread = new Thread(this);
thread.start();
@SuppressWarnings("deprecation")
public void stop()
Thread thread = new Thread(this);
thread.stop();
GameObject.java:import java.awt.*;
import java.util.*;
public class GameObject
public Image sprite;
public Random random = new Random();
public int player_x;
public int player_y;
public int movement_speed = 15;
public int falling_speed;
public int apple_x;
public int apple_y;
public boolean alive;
public GameObject(Image loaded_image)
player_x = 425;
player_y = 725;
sprite = loaded_image;
falling_speed = random.nextInt(10) + 1;
apple_x = random.nextInt(920) + 1;
apple_y = random.nextInt(100) + 1;
alive = true;
And now all I need is you to answer my question! =)package forums;
import java.util.Random;
import javax.swing.Timer;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class VimsiesRetardedAppleGamePanel extends JPanel implements KeyListener
private static final long serialVersionUID = 1L;
private static final int WIDTH = 800;
private static final int HEIGHT = 600;
private static final int MAX_APPLES = 3;
private static final Random RANDOM = new Random();
private int score = 0;
private Player player;
private Apple[] apples = new Apple[MAX_APPLES];
private boolean moveLeft = false;
private boolean moveRight = false;
abstract class Sprite
public final Image image;
public int x;
public int y;
public boolean isAlive = true;
public Sprite(String imageFilename, int x, int y) {
try {
this.image = ImageIO.read(new File(imageFilename));
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Bailing out: Can't load images!");
this.x = x;
this.y = y;
this.isAlive = true;
public Rectangle getRectangle() {
return new Rectangle(x, y, image.getWidth(null), image.getHeight(null));
class Player extends Sprite
public static final int SPEED = 15;
public Player() {
super("C:/Java/home/src/images/player.jpg", WIDTH/2, 0);
y = HEIGHT-image.getHeight(null)-30;
class Apple extends Sprite
public int fallingSpeed;
public Apple() {
super("C:/Java/home/src/images/apple.jpg", 0, 0);
reset();
public void reset() {
this.x = RANDOM.nextInt(WIDTH-image.getWidth(null));
this.y = RANDOM.nextInt(300);
this.fallingSpeed = RANDOM.nextInt(8) + 3;
this.isAlive = true;
private final Timer timer = new Timer(200,
new ActionListener() {
public void actionPerformed(ActionEvent e) {
repaint();
public VimsiesRetardedAppleGamePanel() {
this.player = new Player();
for(int i=0; i<MAX_APPLES; i++) {
apples[i] = new Apple();
setBackground(Color.BLACK);
setFocusable(true); // required to generate key listener events.
addKeyListener(this);
timer.setInitialDelay(1000);
timer.start();
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == e.VK_LEFT) {
moveLeft = true;
moveRight = false;
} else if (e.getKeyCode() == e.VK_RIGHT) {
moveRight = true;
moveLeft = false;
public void keyReleased(KeyEvent e) {
moveRight = false;
moveLeft = false;
public void keyTyped(KeyEvent e) {
// do nothing
public void paintComponent(Graphics g) {
super.paintComponent(g);
//System.err.println("DEBUG: moveLeft="+moveLeft+", moveRight="+moveRight);
if ( moveLeft ) {
player.x -= player.SPEED;
if (player.x < 0) {
player.x = 0;
} else if ( moveRight ) {
player.x += player.SPEED;
if (player.x > getWidth()) {
player.x = getWidth();
//System.err.println("DEBUG: player.x="+player.x);
Rectangle playerRect = player.getRectangle();
for ( Apple apple : apples ) {
apple.y += apple.fallingSpeed;
Rectangle appleRect = apple.getRectangle();
if ( appleRect.intersects(playerRect) ) {
if ( apple.isAlive ) {
score++;
apple.isAlive = false;
g.drawImage(player.image, player.x, player.y, this);
for( Apple apple : apples ) {
if ( apple.isAlive ) {
g.drawImage(apple.image, apple.x, apple.y, this);
g.setColor(Color.RED);
g.drawString("Score: " + score, WIDTH/2-30, 10);
private static void createAndShowGUI() {
JFrame frame = new JFrame("Vimsies Retarded Apple Game");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new VimsiesRetardedAppleGamePanel());
frame.pack();
frame.setSize(WIDTH, HEIGHT);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
public static void main(String[] args) {
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
createAndShowGUI();
}Hey Vimsie, try resetting a dead apple and see what happens. -
How to add ParallelElement and SerialElement in strobe Player
hey frnd,
i'm showing rtmp video from loud api to user and want to add some ads with list of mp3s.
I'm using strobe player but not getting idea to do this .
How can we send more parameters to strobe like xmllist or How to add ParallelElement and SerialElement in strobe Player.
thx in advanced,Ooohh... you mean, like the one mentioned in http://indesignsecrets.com/adding-zoom-and-print-to-indesign-swf-files.php?
But they want to get paid for their hard work, the bastards! -
How to add zooming and printing in e-magazine created by indesign?
Could you please give ma an advise me how to add zooming and printing in e-magazine created by indesign? Many thanks
Ooohh... you mean, like the one mentioned in http://indesignsecrets.com/adding-zoom-and-print-to-indesign-swf-files.php?
But they want to get paid for their hard work, the bastards! -
How to add depreciation and interest in product costing?
how to add depreciation and interest in standard cost estimate and actual costing in product costing ?
Hi,
WHy the admin and sales overhead will be deited to cost of product. The cost of product should include only the factory related direct cost and overhead cost .. not the sales and admin ovehead. exp. for those treat them as period expense and pass on the same to COPa and there those can be analysed there..
I hope i am clear..
Regards
Prabhat -
HOW TO: Add /manipulate columns for a GridControl
HOW TO: Add /manipulate columns for a GridControl when the columns (attributes) are from different entity objects.
This HOWTO describes the basic steps of using attributes from different entity objects for a GridControl.
One way you can create a GridControl which contain attributes from different entity objects is to create a view object and base it on the entity objects which contain
the desired attributes.
Here are the basic steps:
1.Create a new view object (or use an existing view object) by selecting File>New from the menu, clicking the Business Components tab and double-clicking
on the View Object icon.
2.In the View Object wizard change the name to something meaningful.
3.Select the entity objects you will base your view object on.
4.Nivigate to the attribute screen and select the attributes you would like to include in your view object from each entity object. At this point you can also create
a new attribute by clicking the "New" button. The new attribute can be a concatenation of other attributes, derived from a calculation etc.
5.In the query panel of the View Object wizard, click "Expert mode" and enter a query statement. You write complex queries such as decoding a set of attribute
values.
6.Add your newly to your newly created view object to the application module by double-clicking on the application module in the navigation pane and selecting
your view object from the list.
7.Create a new row set.
8.Bind row set to a query by editing their queryinfo property and selecting your view object and its attributes from the queryInfo pane.
9.Create a GridControl and bind it to the row set by editing the dataItemName property of the GridControl. Since the GridControl is bound at the row set level
all of the related attributes are automatically added.
nullMichael,
Are you intending this as a commercial solution or a work around?
To take an existing equivalent, one would build a view in the database tailored for each grid in an Oracle Forms application. Or a separate query layered over tables for each form/grid in a Delphi or Access application? Even if it is ninety nine percent the same over half a dozen forms/grids?
And now you've added a whole slew of "slightly different" rowSetInfos to maintain.
So if you wanted to add a column that needs to appear everywhere... you've just increased the workload multi-fold?
That would be a management nightmare, wouldn't it? Not to mention yet more performance cost and a slower system?
Hmmmm..... I'm not sure I like where this is headed... someone needs to do some convincing...
null -
Hi All how to add new payscale for an employee in sap hr-abap,its urgent
Hi All ,
how to add new payscale for an employee in sap hr-abap,its urgent.
Message was edited by:
bharat kumar
Message was edited by:
bharat kumarHi
If that field which you wants to add is available in one of the structures like EKKO,EKPO then you can add that field just beside the other fields
If that field is not there in the any of the structures then you can define a variable using define command
/: DEFINE &VAR&
/ &VAR& = <some value>
or you can write subroutines to fetch the data from outside tables and can use those fields data in the script
<b>Reward points for useful Answers</b>
Regards
Anji -
How to add a border for Panel (jdk 1.1) ?
how to add a border for Panel (jdk 1.1) ?
Border's are a Swing feature, you will have to draw one by yourself (extend Panel and override paint()).
-
CLM How to add search-help for extension field(New Company Field) in MA.
Hi all,
Based on demand,I need to extend a new field(Company) in Master Agreement.
But I do not know how to add search-help for this field,just like User Accont page.
Anyone can help me ?thank you very muck.
Regards,
JackyChengHello Jacky,
To combine all the answers above and have a topic-based reply please go through the below steps:
#1. Inactivate the current extension field Company (I see it is actually a String value and this is not what you want to have)
#2. Go to Setup -> System Setup -> Extension Reference Types
Check if you already have a Company reference type
If not, create a new Extension Reference Type for Class Company. Fill in all required information.
#3. Create a new Extension Attribute
Select Data Type: Object Reference
Now you can add the Company type as reference
Regards,
Bogdan Toma -
How to add search help for standard field LIKP-TRAID
Hi friends,
How to add search help for standard field LIKP-TRAID ,
refer screen
Program Name SAPMV50A
Screen Number 2108
TrnsIDCode ( LIKP-TRAID ) ..
I need to add a search help, so that i can retrieve data from Ztable.
Thanks.
AbhiHi Abhi,
Try using any one option:
Create a Search Help in SE11.
Now Goto SE11 -> Enter Ztable -> Select that field -> Click Search Help and try to assign the created Search help to that field in your Ztable explicitly
OR
Create a Zdata element in SE11.
In Data Element, under Further Characteristics tab, enter Name Parameters of Search Help.
Assign this data element to that field in ur Ztable.
OR
Create a Zdomain and maintain a Value Table or Fixed Values for it.
Assign this domain to that field in ur Ztable. -
How to add extra options for style of images in pages. iPad version has far more options than Mac version
Thank you, you made me go look again and I realised the ones I use on the iPad are under Borders not style and they are on Mac also. I feel a bit silly but I wouldn't have got there without your prompting. Do you mean by "create your own" using the borders and then saving as a style or can you create something that is not in either?
Thanks again
Maybe you are looking for
-
My iPhone is no longer downloading mail messages
I have both my work e-mail and Gmail on my iPhone. For some reason, my work e-mails are no longer automatically being pushed to my phone unless I click on the Mail icon and wait for it to connect/download. This isn't the case for my Gmail...and my
-
How do you highlight a file or folder in the finder screen?
I have OSX 10.9.2. I would like to be alble to hightlight a folder, so that when I view it I can see the whole line changed to a color. In the previous system I did this by selecting a folder then the dropdown, File-Label, and chose a color. All thi
-
HT1459 Difficulty transfering music to ipod
Purchased, downloaded music, not transfering to my ipod
-
Adobe reader XL 11 crashes everytime I try to open it.
Every time I try to open Adobe reader, it crashes. I have re installed it, re booted the computer and nothing. I get the same message "Adobe reader has stopped working". I am using windows & professional and I do not want goggle chrome.
-
ADF Deployment JDBC Datasource
Hi, I am deploying my ADF application into weblogic server and at my AM , i set the database connection as JDBCDatasource and value is java:...eis/DEV. the JNDI name in the admin console was eis/DEV. When i launch my application, i still get either n