Skip to main content

Posts

Showing posts with the label end

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;

procedure to Insert image using sql by using LOB ,BLOB,CLOB data types

Insert image using sql create or replace procedure load(filename varchar2) as f_lob bfile; b_lob blob; begin insert into images values(filename,substr(filename,instr(filename,'.')+1),empty_blob()) return content into b_lob; f_lob:=BFILENAME('PAVAN',filename); dbms_lob.fileopen(f_lob,dbms_lob.file_readonly); dbms_lob.loadfromfile(b_lob,f_lob,dbms_lob.getlength(f_lob)); dbms_lob.fileclose(f_lob); commit; end;