Skip to main content

Posts

Simulate Mutating table error

/** Pre-requisite : Understanding on Triggers Mutating table error occurs when update action in trigger is processed and the records are fetched by a SELECT statement for validation. Because the inconsistency is on Select statement values.... **/ create or replace trigger emp_update after insert or update of sal,ename on emp for each row declare dummy number; begin if :new.ename is not null and ( :new.sal > :old.sal or :old.ename :new.ename ) then begin select sal into dummy from emp where ename= :new.ename and sal > :new.sal; exception when no_data_found then dbms_output.put_line('sdfsdfsdfdsfsdfsdf'); end; end if; end; / Select * from emp; insert into emp values('SUSIL',9000); commit; update emp se...

More on CAT, LS, FINGER in UNIX flavours

1. cat -b filename --Number the file output excluding blank lines 2. cat -n filename --Number the file output irrespective of blank lines it has 3. finger username --List more information about the user specified 4. ls -hl --List directory contents ( files, directories ) in human readable format ( for ex. size in KB, MB ,GB ) 5. cat -s filename --Shrinks blank lines

See difference between IMPLICIT cursor and EXPLICIT cursor (Programmatically)

set serveroutput on Declare cursor cur1 is Select * from employee; c1 cur1%rowtype; begin --IMPLICIT cursor -- a Cursor with name SQL is auto-created whenever an SQL is processed update employee set emp_id='' where 1=2; --Explicit cursor --A programmer explicitly declares it and loops through it for processing open cur1; loop fetch cur1 into c1; exit when cur1%notfound; end loop; dbms_output.put_line('EXPLICIT cursor has processed '||cur1%ROWCOUNT||' row(s)'); close cur1; dbms_output.put_line('IMPLICIT cursor has processed '||SQL%ROWCOUNT||' row(s)'); end; / anonymous block completed EXPLICIT cursor has processed 1005 row(s) IMPLICIT cursor has processed 0 row(s)

Must-know SQLs as a beginner

--To list the privileges you have in your session SELECT * FROM session_privs; --Active users connected to Database Select Username, machine, osuser, process, program Third_Party_tool from v$session where audsid !=0 and status='ACTIVE'; --To view the role granted to you select * from dba_role_privs where grantee=user; or Select * from user_role_privs; --To list Segment statistics Select statistic_name, tablespace_name, value from v$segment_statistics; --To view SGA components statistics Select * from v$buffer_pool_statistics; Select * from v$shared_server_monitor; Select * from v$pgastat;

Tricky question an Interviewer can ask you in PLSQL

Question: I am writing a block of code. I am inserting the statement 'Select * from employee' in PLSQL block. Is this possible? If yes, how can you do it? If no, What is the error thrown during compilation? Answer: Answer is both YES and NO. Dont get confused. If you are to say 'YES', go with the below answer. Yes. It can be done using DYNAMIC SQL concept. You can either use DBMS_SQL or EXECUTE IMMEDIATE set serveroutput on begin execute immediate 'Select * from dual'; end; / If you are to say 'NO', justify as below. No. Because a Select statement should have INTO clause with statement structure. set serveroutput on begin Select * from dual; end; / Error report: ORA-06550: line 2, column 1: PLS-00428: an INTO clause is expected in this SELECT statement 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action: