0

I've created this procedure

create or replace procedure enrollstudent(
    rno in STUDENTS.ROLL_NUMBER%type,
    sname in STUDENTS.STUDENT_NAME%type,
    cid in STUDENTS.COURSEID%type,
    cfees in STUDENTS.FEES%type,
    spercent in students.percentage%type
)as 
    discount number;
begin 
    discount := spercent*5;
    cfees := cfees-discount;
    insert into STUDENTS values(rno, sname, cid, cfees, spercent);
    commit;
end;

that works with this table

CREATE TABLE STUDENTS(
    ROLL_NUMBER  NUMBER(20)   NOT NULL,
    STUDENT_NAME VARCHAR2(25) NOT NULL,
    COURSEID     NUMBER(20)   NOT NULL,
    FEES         NUMBER(20)           ,
    PERCENTAGE   NUMBER(20)
);

When I run the procedure creation I have a Procedure ENROLLSTUDENT compiled and it gets created but i have the following errors in the compiler log

Error(8,1): PL/SQL: Statement ignored
Error(8,1): PLS-00363: expression 'CFEES' cannot be used as an assignment target

If I try to run the procedure with some data I simple have PLS-00905: object [schema].ENROLLSTUDENT is invalid

2 Answers 2

2

CFEES is an IN parameter. You can't change it. Create a local variable, and use that, example:

cfees2 NUMBER := cfees;
cfees2 := cfees2 - discount;
insert into STUDENTS values(rno, sname, cid, cfees2, spercent);
Sign up to request clarification or add additional context in comments.

Comments

0

You don't need to define and calculate any local variables; you can do the computation of cfees in place (right in the INSERT statement):

create or replace procedure enrollstudent(
    rno in STUDENTS.ROLL_NUMBER%type,
    sname in STUDENTS.STUDENT_NAME%type,
    cid in STUDENTS.COURSEID%type,
    cfees in STUDENTS.FEES%type,
    spercent in students.percentage%type
)as
begin 
    insert into STUDENTS values(rno, sname, cid, cfees-spercent*5, spercent);
    commit;
end;
/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.