How to check if record exists? [message #84505] |
Wed, 24 March 2004 23:00 |
Solveiga
Messages: 36 Registered: March 2003
|
Member |
|
|
I enter a new value into combobox, witch is a data base item, and I want to check is there such recors in DB.
What is wrong in my code?
declare
LVal NUMBER;
LLab VARCHAR2(200);
listAero ITEM := find_item('CMB_AERO');
yra number;
n number;
statAero NUMBER;
begin
Llab := :T_DAL.cmb_aero;
select count(*) into yra from dual
where exists (select * from T_AERO where AERO_PAV = Llab);
If yra = 0 then
select s_aero.nextval into LVal from dual;
insert into T_AERO(aero_id, aero_pav) values (Lval, Llab);
end if;
end if;
end;
|
|
|
Re: How to check if record exists? [message #84510 is a reply to message #84505] |
Thu, 25 March 2004 02:34 |
Sven Thaemar
Messages: 1 Registered: March 2004
|
Junior Member |
|
|
Hello,
i hope my English ist good enought.
Please check the result from the Statement "SELECT count(*)..." when there are no records in the Table. Is the result NULL or 0.
Is it possible that the Items from a different typ.
LLab = VARCHAR2(200); AERO_PAV = NUMBER(..) ???
Please don't use a SELECT COUNT(*) ... . That's the worst way for the Database. Use SELECT COUNT(pk) .... pk = Primary Key.
Another Tip:
Your wrote LLab VARCHAR2(200).
Better is: LLab <owner>.T_AERO.AERO_PAV&TYPE.
Best regards
Sven
|
|
|
Re: How to check if record exists? [message #84520 is a reply to message #84510] |
Thu, 25 March 2004 21:30 |
Solveiga
Messages: 36 Registered: March 2003
|
Member |
|
|
Hello,
you see, when I select value from a combobox, my LLab is a record's ID. then I convert it to number and do fast select (look up for record's ID)
select(AERO_ID) into yra from T_AERO where exists (select * from T_AERO where AERO_ID = Llab);
But if I accept a user's enterd value when I need to look up in record's names:
select(AERO_ID) into yra from T_AERO where exists (select * from T_AERO where AERO_PAV = LLab);
AERO_ID Number;
AERO_PAV VARCHAR2;
LLab is VARCHAR2 and = :Block.cmb_AERO...
When I select value from list Llab = (e.g.) 42
but when I accept user's entered value
LLab = UsersEnteredText
Please help me how to designate is value selected or entered!!!!
Solveiga
|
|
|