Skip to main content

Posts

Showing posts from 2021

Grep in Unix

  Grep  in Unix   Grep is the frequently used command in Unix (or Linux). Most of us use grep just for finding the words in a file. The power of grep comes with using its options and regular expressions. You can analyze large sets of log files with the help of grep command. Grep stands for Global search for Regular Expressions and Print. The basic syntax of grep command is grep [options] pattern [list of files] Let see some practical examples on grep command. 1.  Running the last executed grep command This saves a lot of time if you are executing the same command again and again. !grep This displays the last executed grep command and also prints the result set of the command on the terminal. 2.  Search for a string in a file This is the basic usage of grep command. It searches for the given string in the specified file. grep "Error" logfile.txt This searches for the string "Error" in the log file and prints all the lines that

Sorting a file in unix

  Sorting a file  in Unix Sort command in unix or linux system is used to order the elements or text. Sort command has the capability of sorting numerical values and strings. The sort command can order the lines in a text file. The syntax of sort command is: sort [options] filename The options are: -b : Ignores leading spaces in each line -d : Uses dictionary sort order. Conisders only spaces and alphanumeric characters in sorting -f : Uses case insensitive sorting. -M : Sorts based on months. Considers only first 3 letters as month. Eg: JAN, FEB -n : Uses numeric sorting -R : Sorts the input file randomly. -r : Reverse order sorting -k : Sorts file based on the data in the specified field positions. -u : Suppresses duplicate lines -t : input field separator Sort Command Examples : Before practicing the examples create the below two files in your unix system: > cat order.txt Unix distributed 05 server Linux virtual 3 server

Materialized view

   Materialized view  CREATE MATERIALIZED VIEW EMP_MV       BUILD IMMEDIATE        REFRESH COMPLETE         ENABLE QUERY REWRITE         AS SELECT DEPTNO, SUM(SAL) FROM EMP    GROUP BY DEPTNO refresh method of a Materialized view exec dbms_mview.refresh('MV1');

Trigger :old and :new concept

  CREATE TABLE AUDIT_EMP  (RCD DATE, EMPID NUMBER(4), old_salary NUMBER(7,2), new_salary NUMBER(7,2) ); SELECT * FROM AUDIT_EMP; CREATE OR REPLACE TRIGGER audit_emp_values     AFTER DELETE OR INSERT OR UPDATE ON emp     FOR EACH ROW     BEGIN     INSERT INTO audit_emp     VALUES ( SYSDATE, :OLD.empno,:OLD.sal, :NEW.sal );    END; UPDATE EMP SET SAL = SAL+100 WHERE EMPNO =7369; SELECT * FROM AUDIT_EMP;

Compund Trigger

  Compound Trigger     In Oracle 11g, the concept of compound trigger was introduced. A compound trigger is a single trigger on a table that enables you to specify actions for each of four timing points: 1.    Before the firing statement 2.    Before each row that the firing statement affects 3.    After each row that the firing statement affects 4.    After the firing statement   With the compound trigger, both the statement-level and row-level action can be put up in a single trigger. Plus there is an added advantage: it allows sharing of common state between all the trigger-points using variable.   CREATE OR REPLACE TRIGGER compound_trigger_name FOR [ INSERT | DELETE ] UPDATE [ OF column ] ON table COMPOUND TRIGGER    -- Declarative Section (optional)    -- Variables declared here have firing-statement duration.           --Executed before DML statement      BEFORE STATEMENT IS      BEGIN        NULL ;      END BEFORE STATEMENT ;