oracle - SQL: Trouble in Check Constraint / Sequence -


so created table, called "exam" 3 columns "name", "rollno" , "result p/f". want following:

when name input (via '&name' syntax), automatically assigns first name roll number (rollno) 1501 , asks result, can enter either "p" or "f", pass or fail, respectively. when input next name, increments rollno 1502.. , on.

about rollno part, have sequence called examsqn. looks like: the first one

about "result p/f" part, have check constraint. , how insert values table:

insert exam (name, rollno, "result p/f") values ('&name', examsqn.nextval, '&result p/f') 

and way, how check constraint goes:

1  alter table exam 2* add constraint exam_result_ck check ("result p/f" in ('p','f')) 

so expect take p or , f, when asks result

i asked name, , result right after error. how whole goes:

enter value name: nikh enter value result: p old   2: values ('&name', examsqn.nextval, '&result p/f') new   2: values ('nikh', examsqn.nextval, 'p p/f') insert exam (name, rollno, "result p/f") * error @ line 1: ora-02290: check constraint (scott.exam_result_ck) violated 

your appreciated.

thank :)

to work need remove 'p/f' '&result p/f'

you can see old, new output trying insert 'p p/f' why constraint fails.

also better off not calling column "result p/f" using alias.

cheers


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -