Home » Developer & Programmer » Forms » updating a record in a cursor issue (Oracle 10g)
updating a record in a cursor issue [message #545917] Sat, 03 March 2012 08:56 Go to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
when I updated a record in my form
pls. check my screenshot:
http://i39.tinypic.com/sff8ev.jpg

and clicked save button

the result was:
http://i39.tinypic.com/vsc5y8.png

as you can see in the message at the bottom, it has 18 records. And since my original data(subjects) are just 9. And also the grades that I input didn't display all.

This is my code in when-new-block-instance trigger:
DECLARE
	
   CURSOR studgrade_cur IS
     SELECT  e.student_id, s.subject_code --, g.grade
        FROM tblEnrolled e, tblStudgrades g, tblSubjectSection s
          WHERE e.section = s.section 
          and e.student_id = g.student_id
            --AND e.section = s.section
            	AND e.student_id = :studprofile.stud_id
           		 	ORDER BY s.subject_code;
           	
BEGIN   

GO_BLOCK('addgrade');

FOR studgrade_rec IN studgrade_cur 
LOOP
		:addgrade.studid := studgrade_rec.student_id;
	 	:addgrade.subjcode := studgrade_rec.subject_code; 
	
  	
NEXT_RECORD;
END LOOP;
END;


and the code in my when-button-pressed trigger:
UPDATE tblStudgrades
SET grade = :addgrade.grades1
WHERE student_id = :addgrade.studid;

Message('');
:studprofile.GRADE := :ADDGRADE.GRADES1;
:studprofile.SUBJECTS := :ADDGRADE.SUBJCODE;
standard.commit;

HIDE_VIEW('CV_STACKEDaddgrade'); 
SET_VIEW_PROPERTY('CV_STACKEDaddgrade', VISIBLE, PROPERTY_FALSE);
GO_BLOCK('studprofile');



any help would highly be appreciated. thanks
Re: updating a record in a cursor issue [message #545928 is a reply to message #545917] Sat, 03 March 2012 10:20 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
So you populate the block from a cursor in when-new-block-instance.
That fires whenever you enter the block.
So what happens the 2nd time you enter the block?
Re: updating a record in a cursor issue [message #545931 is a reply to message #545928] Sat, 03 March 2012 10:37 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
My records doubled themselves.

And I changed my code into this:

BEGIN  

FOR studgrade_rec IN studgrade_cur 
LOOP

INSERT INTO tblStudgrades(studgrade_rec.student_id, studgrade_rec.grade, studgrade_rec.subject_code)
VALUES (:ADDGRADE.studid, :ADDGRADE.subjcode, :ADDGRADE.grades1);
  	
NEXT_RECORD;
END LOOP;
  
:studprofile.GRADE := :ADDGRADE.GRADES1;
:studprofile.SUBJECTS := :ADDGRADE.SUBJCODE;
--standard.commit;

COMMIT;
HIDE_VIEW('CV_STACKEDaddgrade'); 
SET_VIEW_PROPERTY('CV_STACKEDaddgrade', VISIBLE, PROPERTY_FALSE);
GO_BLOCK('studprofile');

END;


'coz my previous code only updates one record at a time, since I have to save all records(student_id, grade and subject_code) into my table, i changed to INSERT. I can only insert one record, I don't have any idea how to make loop here.
Re: updating a record in a cursor issue [message #545934 is a reply to message #545931] Sat, 03 March 2012 10:45 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
baliberde wrote on Sat, 03 March 2012 16:37
My records doubled themselves.

Of course they are. You've got code that adds records to the block every time you enter the block. What did you expect was going to happen?


As for your update. If you tried using forms default functionality then you wouldn't have this issue. Base the block on a table. Use execute query to populate it, make changes and click on the standard save button. Forms will do all necessary updates for you.
Re: updating a record in a cursor issue [message #545936 is a reply to message #545931] Sat, 03 March 2012 10:48 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
But is it possible to do it in a cursor?
Re: updating a record in a cursor issue [message #545942 is a reply to message #545936] Sat, 03 March 2012 11:24 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
Possible to do what exactly in a cursor? You're doing multiple things here.
Re: updating a record in a cursor issue [message #545949 is a reply to message #545942] Sat, 03 March 2012 11:49 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
I mean to insert new records in a cursor?
Re: updating a record in a cursor issue [message #545951 is a reply to message #545949] Sat, 03 March 2012 11:57 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
What I'm trying to do is to add new records, I switched from update to add records.
Re: updating a record in a cursor issue [message #545959 is a reply to message #545951] Sat, 03 March 2012 13:38 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
Yes you can do an insert inside a cursor loop.
What precise code you need I have no idea, because once again your explanation of what you are trying to do is less than clear.
You need to tell us what data you want inserted into what table under what conditions.

The next_record in your current for loop is pointless. Insert inserts directly into the DB table. It does not add values to the form.
Re: updating a record in a cursor issue [message #545993 is a reply to message #545959] Sun, 04 March 2012 08:45 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
I have to insert new records, those subjects with its grades, into my DB. As you say, yes, it only inserted one record into my DB, but what I want is to insert ALL records at the same time. How can I do that? Thanks
Re: updating a record in a cursor issue [message #546013 is a reply to message #545993] Sun, 04 March 2012 10:20 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
By looping over all the records.
Or doing the sensible thing and letting forms default functionality do the work.
Re: updating a record in a cursor issue [message #546014 is a reply to message #545993] Sun, 04 March 2012 10:23 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Really, why do you insist on such an approach? Why do you refuse to use Forms built-in features?

Cookiemonster told you to base block on a table. COMMIT would save records you entered (new ones) as well as values you changed (in records you fetched from a table using EXECUTE QUERY). You don't have to code it, Forms is smart enough to do the "dirty" job for you.

You are just making your life more complicated than it should be.
Re: updating a record in a cursor issue [message #546022 is a reply to message #546013] Sun, 04 March 2012 11:30 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
i tried to loop to no avail. i searched for new records in sqlplus, but there were no records found.

this is the code i used:
DECLARE
   CURSOR studgrade_cur IS
     SELECT  e.student_id, s.subject_code
        FROM tblEnrolled e, tblSubjectSection s, tblStudgrades g
          WHERE e.section = s.section
          	AND e.student_id = g.student_id
            	AND e.student_id = :studprofile.stud_id
           		 	ORDER BY s.subject_code;
BEGIN  
GO_BLOCK('studprofile');
FOR studgrade_rec IN studgrade_cur 
LOOP

INSERT INTO tblStudgrades(student_id, subject_code,grade)
VALUES (:STUDPROFILE.STUD_ID, :STUDPROFILE.SUBJECTS, :STUDPROFILE.grade); 

END LOOP;
standard.commit;
END;

[Updated on: Sun, 04 March 2012 11:51]

Report message to a moderator

Re: updating a record in a cursor issue [message #546026 is a reply to message #546022] Sun, 04 March 2012 12:12 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Are you sure that cursor's SELECT returned at least one record?

Did you not learn by now that including the MESSAGE built-in lets you know what's going on? If you are using Forms 10g, you can even run the form in debug mode (which is really helpful while ... well, debugging your programs).

[Updated on: Sun, 04 March 2012 12:13]

Report message to a moderator

Re: updating a record in a cursor issue [message #546029 is a reply to message #546026] Sun, 04 March 2012 12:37 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
yup it returned all records that the student has. I run it already in Debug mode, but it didn't tell me what's going on with inserting my records.
Re: updating a record in a cursor issue [message #546033 is a reply to message #546022] Sun, 04 March 2012 15:05 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
baliberde wrote on Sun, 04 March 2012 17:30

this is the code i used:
DECLARE
   CURSOR studgrade_cur IS
     SELECT  e.student_id, s.subject_code
        FROM tblEnrolled e, tblSubjectSection s, tblStudgrades g
          WHERE e.section = s.section
          	AND e.student_id = g.student_id
            	AND e.student_id = :studprofile.stud_id
           		 	ORDER BY s.subject_code;
BEGIN  
GO_BLOCK('studprofile');
FOR studgrade_rec IN studgrade_cur 
LOOP

INSERT INTO tblStudgrades(student_id, subject_code,grade)
VALUES (:STUDPROFILE.STUD_ID, :STUDPROFILE.SUBJECTS, :STUDPROFILE.grade); 

END LOOP;
standard.commit;
END;


In the code above, do :STUDPROFILE.STUD_ID, :STUDPROFILE.SUBJECTS and :STUDPROFILE.grade change value each time you go round the loop?
Re: updating a record in a cursor issue [message #546072 is a reply to message #546033] Mon, 05 March 2012 03:54 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
No! They don't change every time I go round the loop. I'm wondering why, but the only thing that was inserted on my table is the last subject.
Re: updating a record in a cursor issue [message #546074 is a reply to message #546072] Mon, 05 March 2012 04:00 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
I'm wondering why you expect them to change. Obviously they need to, but you've written no code that would make them change.
Re: updating a record in a cursor issue [message #546081 is a reply to message #546074] Mon, 05 March 2012 04:37 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
So, how will I do that? That's just my problem, I can insert all records but they aren't saving though I have commit there.
Re: updating a record in a cursor issue [message #546084 is a reply to message #546014] Mon, 05 March 2012 04:40 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
@LittleFoot - but in my case I have 3 tables, can I base 3 tables on my block?
Re: updating a record in a cursor issue [message #546088 is a reply to message #546084] Mon, 05 March 2012 04:46 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
baliberde wrote on Mon, 05 March 2012 10:37
So, how will I do that? That's just my problem, I can insert all records but they aren't saving though I have commit there.

You do understand that there is a difference between records in tables in the database and records in datablocks in a form?
Your cursor is selecting records from tables in the DB.
As far as I can tell you want to insert data that is in different records in the datablock in the form.
You need to loop over the records in the datablock, not the records in the database.
To loop over records in a datablock you need to use first_record/nect_record.

baliberde wrote on Mon, 05 March 2012 10:40
@LittleFoot - but in my case I have 3 tables, can I base 3 tables on my block?

You're only inserting into one table though, so the block should only need to be based on that table.
Re: updating a record in a cursor issue [message #546093 is a reply to message #546088] Mon, 05 March 2012 05:37 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
I tried to add first_record, but it's still doing the same, or is it wrong?


DECLARE
   CURSOR studgrade_cur IS
     SELECT  e.student_id, s.subject_code
        FROM tblEnrolled e, tblSubjectSection s, tblStudgrades g
          WHERE e.section = s.section
          	AND e.student_id = g.student_id
            	AND e.student_id = :studprofile.stud_id
           		 	ORDER BY s.subject_code;
BEGIN  
  
GO_BLOCK('addgrade');
FOR studgrade_rec IN studgrade_cur 
LOOP

[b]FIRST_RECORD;[/b]
INSERT INTO tblStudgrades(student_id, subject_code,grade)
VALUES (:ADDGRADE.STUDID, :ADDGRADE.subjcode, :ADDGRADE.grades1); 

END LOOP;
standard.commit;


HIDE_VIEW('CV_STACKEDaddgrade'); 
SET_VIEW_PROPERTY('CV_STACKEDaddgrade', VISIBLE, PROPERTY_FALSE);
  GO_BLOCK('studprofile');
END;
Re: updating a record in a cursor issue [message #546095 is a reply to message #546093] Mon, 05 March 2012 05:40 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
And how exactly does that code loop over the records in the addgrade block?
And what exactly is that cursor loop there for?
Re: updating a record in a cursor issue [message #546101 is a reply to message #546095] Mon, 05 March 2012 06:07 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
it doesn't loop over my addgrade block, so i decided to just insert students' grades in studprofile block. But when I did, oracle unable to perform Insert record
Re: updating a record in a cursor issue [message #546103 is a reply to message #546101] Mon, 05 March 2012 06:14 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
Don't you need to loop over the addgrade block? It can have more than one record can't it?
As for the error - use Display error on the runtime help menu to see what the exact error is?
Re: updating a record in a cursor issue [message #546106 is a reply to message #546103] Mon, 05 March 2012 06:25 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
this is the error message:

Quote:
FRM-40508: ORACLE error: unable to INSERT record.

Cause:  A fatal error occurred while trying to insert a record. The table associated with the current block of the form might not exist, your username might not have authority to perform the specified action on the table, or some other reason might have caused the fatal error.

Action:  Contact your DBA.


So I don't have to remove my loop over addgrade block?
Re: updating a record in a cursor issue [message #546109 is a reply to message #546106] Mon, 05 March 2012 06:36 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
When you run the form there is a help menu. One of the options on the help menu is display error. If you get an error when running the form like FRM-40508 then you can click on display error and it'll show you the underlying oracle error that caused it.

And you can't remove a loop you don't have. You are not looping over the addgrade block with that code. That was my point.
You are looping over some records in the DB and using the exact same record in the addgrade block each time.
Re: updating a record in a cursor issue [message #546111 is a reply to message #546109] Mon, 05 March 2012 06:41 Go to previous messageGo to next message
owais_baba
Messages: 289
Registered: March 2008
Location: MUSCAT
Senior Member
FRM-40508: ORACLE error: unable to INSERT record.


A fatal error occurred while trying to insert a record. The table associated with the current block of the form might not exist, your username might not have authority to perform the specified action on the table, or some other reason might have caused the fatal error.

Action: Contact your DBA.

Level: >25

Type: Error

cookiemonster is right


Re: updating a record in a cursor issue [message #546113 is a reply to message #546109] Mon, 05 March 2012 06:45 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
Ok i will click help menu.

This is the code I used in when-new-block-instance trigger in addgrade block:

DECLARE
	
   CURSOR studgrade_cur IS
     SELECT  e.student_id, s.subject_code, g.grade
        FROM tblEnrolled e, tblSubjectSection s, tblStudgrades g
          WHERE e.section = s.section
          --	AND e.student_id = g.student_id
            	AND e.student_id = :studprofile.stud_id
           		 	ORDER BY s.subject_code;
           	
BEGIN   

GO_BLOCK('addgrade');
FOR studgrade_rec IN studgrade_cur 
LOOP
		:addgrade.studid := studgrade_rec.student_id;
	 	:addgrade.subjcode := studgrade_rec.subject_code; 
NEXT_RECORD;
END LOOP;

END;


I have loop, but when I modified it, it doesn't display on my items

[Updated on: Mon, 05 March 2012 06:47]

Report message to a moderator

Re: updating a record in a cursor issue [message #546115 is a reply to message #546113] Mon, 05 March 2012 06:48 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
DATABASE ERROR: INSERT INTO tblStudgrades(student_id,LNAME,MNAME,FNAME,COURSE,YEARSTATUS,TYPE,Subject_Code,tblStudgrades,grade) VALUES (:1,:2,:3,:4,:5,:6,:7,:8,:9,:10)


ERROR:
ORA-00904: "TBLSTUDGRADES": invalid identifier
Re: updating a record in a cursor issue [message #546116 is a reply to message #546115] Mon, 05 March 2012 06:52 Go to previous messageGo to next message
owais_baba
Messages: 289
Registered: March 2008
Location: MUSCAT
Senior Member
ORA-00904: string: invalid identifier

Cause: The column name entered is either missing or invalid.
Action: Enter a valid column name. A valid column name must begin with a letter, be less than or equal to 30 characters, and consist of only alphanumeric characters and the special characters $, _, and #. If it contains other characters, then it must be enclosed in double quotation marks. It may not be a reserved word.
Re: updating a record in a cursor issue [message #546117 is a reply to message #546113] Mon, 05 March 2012 06:55 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
What doesn't display on what items?
[rant]
We do not have your form.
We do not have your tables.
We do not have your data.
We do not have your requirements.
We don't know what assumptions you are making.
We only have a very vague idea of what you are trying to do.

We can't possibly know how to fix your code unless we know exactly what you are trying to do.
We can't know exactly what you are trying to do unless you explain it clearly.

You don't get charged by the word to post here.
So try posting more words of explanation.

And what the heck happened to the insert?
[/rant]

[Updated on: Mon, 05 March 2012 06:57]

Report message to a moderator

Re: updating a record in a cursor issue [message #546120 is a reply to message #546115] Mon, 05 March 2012 07:00 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
baliberde wrote on Mon, 05 March 2012 12:48
DATABASE ERROR: INSERT INTO tblStudgrades(student_id,LNAME,MNAME,FNAME,COURSE,YEARSTATUS,TYPE,Subject_Code,tblStudgrades,grade) VALUES (:1,:2,:3,:4,:5,:6,:7,:8,:9,:10)


ERROR:
ORA-00904: "TBLSTUDGRADES": invalid identifier


Do you have a table called tblStudgrades?
Does it have a column called tblStudgrades?
Re: updating a record in a cursor issue [message #546122 is a reply to message #546120] Mon, 05 March 2012 07:03 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
Yes I have a table tblStudgrades, that where I'm going to save students grade. I don't have tblstudgrade column. I don't know what happened to it.
Re: updating a record in a cursor issue [message #546125 is a reply to message #546117] Mon, 05 March 2012 07:09 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
Quote:
What doesn't display on what items?



my records from studprofile don't display on my items in addgrade block specifically(:addgrade.studid, :addgrade.subjcode, :addgrade.grades1)

this is the code that I used in when-new-block-instance addgrade block:

DECLARE
	
   CURSOR studgrade_cur IS
     SELECT  e.student_id, s.subject_code, g.grade
        FROM tblEnrolled e, tblSubjectSection s, tblStudgrades g
          WHERE e.section = s.section
          --	AND e.student_id = g.student_id
            	AND e.student_id = :studprofile.stud_id
           		 	ORDER BY s.subject_code;
           	
BEGIN   

GO_BLOCK('addgrade');
FOR studgrade_rec IN studgrade_cur 
LOOP
		:addgrade.studid := studgrade_rec.student_id;
	 	:addgrade.subjcode := studgrade_rec.subject_code; 
NEXT_RECORD;
END LOOP;

END;



and on my :addgrade.save button when-button-pressed trigger:
DECLARE
   CURSOR studgrade_cur IS
     SELECT  e.student_id, s.subject_code
        FROM tblEnrolled e, tblSubjectSection s, tblStudgrades g
          WHERE e.section = s.section
          	AND e.student_id = g.student_id
            	AND e.student_id = :studprofile.stud_id
           		 	ORDER BY s.subject_code;
BEGIN  
  
GO_BLOCK('addgrade');
FOR studgrade_rec IN studgrade_cur 
LOOP

INSERT INTO tblStudgrades(student_id, subject_code,grade)
VALUES (:ADDGRADE.STUDID, :ADDGRADE.subjcode, :ADDGRADE.grades1); 
NEXT_RECORD;
END LOOP;
standard.commit;


HIDE_VIEW('CV_STACKEDaddgrade'); 
SET_VIEW_PROPERTY('CV_STACKEDaddgrade', VISIBLE, PROPERTY_FALSE);
  GO_BLOCK('studprofile');
END;


[Updated on: Mon, 05 March 2012 07:10]

Report message to a moderator

Re: updating a record in a cursor issue [message #546126 is a reply to message #546117] Mon, 05 March 2012 07:09 Go to previous messageGo to next message
owais_baba
Messages: 289
Registered: March 2008
Location: MUSCAT
Senior Member
Example----

INSERT INTO tblStudgrades(student_id) VALUES ('1') if numeric (1)


yes cookiemonster is right

we dont have anything related to what your doing in your programming

Re: updating a record in a cursor issue [message #546129 is a reply to message #546126] Mon, 05 March 2012 07:17 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
This is my requirement:
I have 2 blocks, studprofile and addgrade. In studprofile block, I have a cursor that joins 3 tables, namely(tblEnrolled, tblSubjectSection, tblStudgrades) to display the record of the newly enrolled student. In this studprofile block, I'm going now to input his, the student's, grades. This block has a button named ADD GRADES. When I'm going to click that button: in when-button-pressed trigger

BEGIN
	show_view('cv_stackedaddgrade');
	
:addgrade.grades1 := :studprofile.grade;
:addgrade.subjcode:= :studprofile.subjects;
:addgrade.studid := :studprofile.stud_id;
		
		
	go_block('addgrade');
END;



, that would immediately direct me to ADDGRADE BLOCK, to add grades. I have included cursor in when-new-block-instance trigger:

DECLARE
	
   CURSOR studgrade_cur IS
     SELECT  e.student_id, s.subject_code, g.grade
        FROM tblEnrolled e, tblSubjectSection s, tblStudgrades g
          WHERE e.section = s.section
          --	AND e.student_id = g.student_id
            	AND e.student_id = :studprofile.stud_id
           		 	ORDER BY s.subject_code;
           	
BEGIN   

GO_BLOCK('addgrade');
FOR studgrade_rec IN studgrade_cur 
LOOP
		:addgrade.studid := studgrade_rec.student_id;
	 	:addgrade.subjcode := studgrade_rec.subject_code; 
NEXT_RECORD;
END LOOP;

END;


... Also, in that block I have a save button, when I'm done adding grades I'd click on that to commit to database.
this is the code for my when-button-pressed trigger in save button:

DECLARE
   CURSOR studgrade_cur IS
     SELECT  e.student_id, s.subject_code
        FROM tblEnrolled e, tblSubjectSection s, tblStudgrades g
          WHERE e.section = s.section
          	AND e.student_id = g.student_id
            	AND e.student_id = :studprofile.stud_id
           		 	ORDER BY s.subject_code;
BEGIN  
  
GO_BLOCK('addgrade');
FOR studgrade_rec IN studgrade_cur 
LOOP

INSERT INTO tblStudgrades(student_id, subject_code,grade)
VALUES (:ADDGRADE.STUDID, :ADDGRADE.subjcode, :ADDGRADE.grades1); 
NEXT_RECORD;
END LOOP;
standard.commit;


HIDE_VIEW('CV_STACKEDaddgrade'); 
SET_VIEW_PROPERTY('CV_STACKEDaddgrade', VISIBLE, PROPERTY_FALSE);
  GO_BLOCK('studprofile');
END;

.

My problem is that it doesn't save my records directly into the database though I have commit statement.

[Updated on: Mon, 05 March 2012 07:19]

Report message to a moderator

Re: updating a record in a cursor issue [message #546143 is a reply to message #546129] Mon, 05 March 2012 08:08 Go to previous messageGo to next message
owais_baba
Messages: 289
Registered: March 2008
Location: MUSCAT
Senior Member
First how r working opening and fetching records

    
   GO_BLOCK('B');
       clear_block(no_commit);
  declare 
       cursor c1 is select * from a WHERE NO=:A.NO ;
       a_record c1%rowtype;
  begin
       open c1;
  loop
       fetch c1 into a_record;
  exit when c1%notfound;
       :b.no:=a_record.no;
       :b.name:=a_record.name;
  next_record;
      ---insert into b values(a_record.no,a_record.name);
  end loop;
     close c1;
  end;
     first_Record;
--EXECUTE_QUERY;
--go_block('a');
--clear_form;


hope it should work for u

[Updated on: Mon, 05 March 2012 08:09]

Report message to a moderator

Re: updating a record in a cursor issue [message #546144 is a reply to message #546143] Mon, 05 March 2012 08:11 Go to previous messageGo to next message
baliberde
Messages: 201
Registered: January 2012
Location: outer space
Senior Member
Thanks is it going to save multiple records?
Re: updating a record in a cursor issue [message #546146 is a reply to message #546122] Mon, 05 March 2012 08:17 Go to previous messageGo to previous message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
baliberde wrote on Mon, 05 March 2012 13:03
Yes I have a table tblStudgrades, that where I'm going to save students grade. I don't have tblstudgrade column. I don't know what happened to it.


Forms default behavior 101:

When you have a datablock with the Database Data Block property set to Yes, oracle will do all appropriate inserts and updates for you.

When you enter data in a blank record forms will assume it's a new record and try to insert it.

When you query a record, with execute_query (not populate the block manually with a cursor, that's a new record as far as forms is concerned) and then change the values, forms will assume it's a changed record and will do the appropriate update.
The insert/update are done when you issue a commit.

Forms works out which columns to use in the insert/update by checking all the items in the block and seeing what their Database Item property is set to. All items with that property set to yes are included in the insert/update.


So you've got a database datablock with an item called tblstudgrade which has it's Database Item property set to Yes.

Forms is doing an automatic insert and assumes that item must correspond to a column in the database table because that's what the properties tell it.

If you're going to use default functionality you need to stop writing manual insert statements.

If you're going to do it manually you need to set all database properties to No at item and block level.

Either way you have properties set incorrectly.

I strongly recommend you use the default functionality as your knowledge of how forms works is nowhere near strongly enough to allow you to do it the hard way.
Previous Topic: problem with finding a node in a tree
Next Topic: how to insert and update with single statement...?
Goto Forum:
  


Current Time: Sat Jul 06 00:04:01 CDT 2024