Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Trigger Problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-01-03, 09:35
burningmoney burningmoney is offline
Registered User
 
Join Date: Sep 2003
Posts: 12
Trigger Problem

I have a problem with a trigger.

The function of the trigger is to check if new items already exists within the database. The problem is that the query returns an error stating that

ORA-01422: exact fetch returns more than requested number of rows


Basically my problem is first I have to identify the newest record and store the title (new_title) (the attribute I will use to compare)

Select MAX(itemno), title into num, new_title from item;

Then I need to take the stored attribute, and use it in another query.
To find a data which correponds to the new variable

select title into old_title from item where title=(new_title) and itemno<>num;

This query looks for titles with the same name but not the same itemno. (so that it doesnt return the new entry)

An If statement is then used to decide the action, when the same entry has been found.

The problem is PL/SQL doesnt seem to allow it.

Any ideas??
Thanks for any help..
Reply With Quote
  #2 (permalink)  
Old 12-01-03, 10:08
cvandemaele cvandemaele is offline
Registered User
 
Join Date: Oct 2003
Location: Switzerland
Posts: 140
First of all, this query cannot work :
Select MAX(itemno), title into num, new_title from item;
=> ORA-00937: not a single-group group function

Rewrite it as :
select itemno, title into num, new_title from item where itemno = (select max(itemno) from items)




About the error message : ORA-01422: exact fetch returns more than requested number of rows. It means exactly what it means. A "SELECT INTO" query can only return 0 or 1 row, not more. Declare your select as a cursor, and process on a row-by-row basis.

Good luck.
Reply With Quote
  #3 (permalink)  
Old 12-01-03, 13:23
burningmoney burningmoney is offline
Registered User
 
Join Date: Sep 2003
Posts: 12
(WOW) I still have a lot to learn.

Thank you cvandemaele
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On