plsql - Oracle PL/SQL Trigger to limit orders per customer -
Just working on creating a little trigger What I'm doing to trigger this trigger is making sure that the customer Only one current time can get 10 orders in the order table, in order. Do not ask why my idiot wants me to feel silly.
But originally a trigger placed order is on the table, I am currently selecting a different number on customer_ID and it has a V_count version.
If v_count & lt; Enter 10 INSERT__ ELSE DBMS_OUTPUT.PUT_LINE ('Please wait 10 or more order processing for you') END END This code is the original gist but it will not run if any If so, can I show the full code?
Here's the code - Sorry, I just do not know how to use SQLFeed now.
To change or change the trigger, select each line for the v_count number is put before trg_order_limit before the first INR; SELECT COUNT (DISTINCT FK1_customer_id) from place_order in V_count; If v_count & lt; 10th put order_order (order_dard, order_date, delivery_date, fk1_graher_id, fk-2_morifier_id, fk3_order_type_id) value (new order_id ,: new order_date, new delivery_date, newfac 1_group_id, newfac2 employee - ID ,: NewFK3_Der_type_ID); ELSE v_count & gt; 10 then DBMS_OUTPUT.PUT_LINE ('You currently have 10 or more order processing.'); end if; End; When I run the script in Oracle, I get an error on line 4: PL / SQL: ORA-0933: SQL command did not end properly
lot Thank you very much Richard
Even if there was no syntax error in your trigger, then this work Will not: Only the output "can not order more than 10" message and insertion will still proceed; In addition, if you passed this exam, you would be put in a loop of inserts. In the event of a lot of records, you need to throw exceptions, and you need to catch your application, and it is nothing to go through the test.
For the error, I think the problem is with this line:
from SELECT COUNT (DISTINCT FK1_customer_id) in place_order in v_count; It should be:
placed SELECT COUNT (DISTINCT FK1_customer_id); in the v_count line; However, this question is wrong anyway: it will return the number of unique customers who order it. What you are looking for is:
Select parentheses_elect in the v_count direction where fk1_customer_id =: new.fk1_customer_id that order_id < There is a specificity barrier in / code>; Which seems likely! However, your trigger code should be something like this: Announce the v_count number to trigger or change trg_order_limit before entering the placed_order for each row; Start - get calculation count (order_ID) of the current order count placed in v_count / command where fk1_customer_id =: new.fk1_customer_id; - Increase exception if there are too many if v_count & gt; = 10 raise_application_error (-20000, 'you currently have 10 or more order processing.'); end if; End; However, this approach is probably not a good idea.
Edit The number of orders per customer is completely incorrect. My answer was updated.
Comments
Post a Comment