Wednesday, October 20, 2010

PL-SQL program for calculating wheather a number is amstron or not

DECLARE
A NUMBER := &ENTER_THE_NUMBER;
B NUMBER := 0;
C NUMBER;
D NUMBER;
BEGIN
c := A;
WHILE(a!=0)
LOOP
D := MOD(A,10);
DBMS_OUTPUT.PUT_LINE(D);
B := B + (D*D*D);
DBMS_OUTPUT.PUT_LINE(B);
A := FLOOR(A/10);
DBMS_OUTPUT.PUT_LINE(A);
END LOOP;
IF (B = C) THEN DBMS_OUTPUT.PUT_LINE(' THIS IS A AMSTRON NUMBER');
ELSE
DBMS_OUTPUT.PUT_LINE('THIS IS NOT A AMSTRONG NUMBER' || B);
END IF;
END;
/
Please Comment on this

2 comments:

  1. 1 create or replace trigger product_history_update
    2 after update
    3 of unit_price on product
    4 for each row
    5 begin
    6 insert into product_history
    7 values(
    8 :old.product_id,
    9 :old.product_name,
    10 :old.supplier_name,
    11 :old.unit_price
    12 );
    13* end
    SQL> /

    Warning: Trigger created with compilation errors.

    SQL> update product set unit_price = 400
    2 where product_id = 2;
    update product set unit_price = 400
    *
    ERROR at line 1:
    ORA-04098: trigger 'SCOTT.PRODUCT_TRIGGER' is invalid and failed re-validation


    please tell the correct trigger, i am getting error

    ReplyDelete
    Replies
    1. YOU CANT USE .OLD IN THIS CODE ..

      PLEASE TRY again
      and let me know if you have ANY QUERY

      Delete