Skip to main content

Posts

Showing posts with the label begin

Create or replace trigger before insert on field in sql

1.Create  or replace trigger before insert on field in sql Create or replace trigger t1 Before insert on Employee For each row declare v_firstname Employee.firstname%type; v_lastname Employee.lastname%type; Begin DBMS_OUTPUT.PUT_LINE('You inserted the first Name:'|| :NEW.FIRSTNAME); DBMS_OUTPUT.PUT_LINE('You inserted the first Name:'|| :NEW.LASTNAME); Begin select distinct firstname into v_firstname from Employee where firstname=:NEW.FIRSTNAME; IF(:NEW.FIRSTNAME = v_firstname) THEN DBMS_OUTPUT.PUT_LINE('This first name exists already in the table Employee.'); end if; exception when no_data_found then DBMS_OUTPUT.PUT_LINE('This first name does not exist in the table Employee.'); End; Begin select distinct lastname into v_lastname from Employee where lastname=:NEW.lastNAME; IF(:NEW.LASTNAME = v_lastname) THEN DBMS_OUTPUT.PUT_LINE('This last name exists already in the table Employee.

How to Set Default Limit in Store Procedure in SQL

This is stored procedure which show you rows return as per mention in stored procedure. CREATE PROCEDURE get_categories( IN p_action_flag VARCHAR(50), IN p_firstrow int, IN p_lastrow int) BEGIN IF p_action_flag = 'all' THEN SELECT top 50 u.*, d.name, d.image FROM user u, member gu, detail d WHERE u.user_id = gu.user_id AND u.user_id = d.user_id AND u.status = '1' AND gu.group_id IN (1, 7) GROUP BY u.user_id ORDER BY d.name LIMIT p_firstrow,p_lastrow; ELSEIF p_action_flag = 'Most Viewed' THEN SELECT top 50 u.*, d.name, d.image FROM user u, member gu, detail d WHERE u.user_id = gu.user_id AND u.user_id = d.user_id AND u.status = '1' AND gu.group_id IN (1, 7) GROUP BY u.user_id ORDER BY u.views DESC, d.name ASC LIMIT p_firstrow,p_lastrow ; END IF END

skip a record in a cursor and continue with the next record in oracle

To skip a record in a cursor and continue with the next record you can try below code in oracle or sql. declare cursor cur1 is select * from emp; rec cur1%rowtype; begin open cur1; loop fetch cur1 into rec; dbms_output.put_line(rec.ename||' '||rec.sal); fetch cur1 into rec; exit when cur1%notfound; end loop; close cur1; end;