Skip to main content

Sample: Oracle Create, Update, Insert, Triggers, Cursors, Procedures



/* IGNOU MCA SOLVED QUESTION PAPER MCSL-045 DEC-2012*/

create table Sales_Person 
(S_id number, S_name varchar2(30), Experience number, S_Designation varchar2(30), S_product varchar2(30));

create table Sales_Record 
(S_id number, S_target number, S_sold number, S_order number);

create table Sales_Salary 
(S_id number, S_basic number, S_grade number, S_salary number);

/* A trigger for auto update SALARY */

CREATE OR REPLACE TRIGGER CL_SALARY 
AFTER INSERT OR DELETE OR UPDATE ON Sales_Person
BEGIN
    UPDATE SALES_SALARY SET S_SALARY=S_BASIC+S_GRADE;
END CL_SALARY;

INSERT INTO Sales_Person VALUES(5, 'TUHIN SUMANTA', 30,'MANAGER','COSMETICS');

INSERT INTO Sales_Record VALUES(4,70,65,22);

INSERT INTO SALES_SALARY VALUES(5,7850,500,0);

UPDATE SALES_SALARY SET S_SALARY=S_BASIC+S_GRADE;

SELECT * FROM SALES_PERSON;
SELECT * FROM SALES_RECORD;
SELECT * FROM SALES_SALARY;

/* Creating View with JOIN */

CREATE OR REPLACE VIEW S_VIEW_EX 
AS 
SELECT S.S_NAME,S.EXPERIENCE,S.S_Designation,S.S_product,L.S_SALARY 
FROM SALES_PERSON S JOIN SALES_SALARY L 
ON S.S_ID=L.S_ID
WHERE L.S_SALARY>7000 AND S.S_DESIGNATION='EXECUTIVE';

SELECT * FROM S_VIEW_EX;

/* Record fetching by JOIN */

SELECT S.S_NAME,L.S_SALARY,T.S_TARGET,T.S_SOLD,ROUND(T.S_SOLD*100/T.S_TARGET,0) || '%' AS PERCENT_SOLD
FROM SALES_PERSON S JOIN SALES_SALARY L 
ON S.S_ID=L.S_ID JOIN SALES_RECORD T ON L.S_ID=T.S_ID
WHERE L.S_SALARY>1000 AND T.S_TARGET>S_SOLD;

/* Record fetching by JOIN */

SELECT S.S_NAME,L.S_SALARY,T.S_TARGET,T.S_SOLD,ROUND(T.S_SOLD*100/T.S_TARGET,0) || '%' AS PERCENT_SOLD
FROM SALES_PERSON S JOIN SALES_SALARY L 
ON S.S_ID=L.S_ID JOIN SALES_RECORD T ON L.S_ID=T.S_ID
WHERE  S.S_DESIGNATION='EXECUTIVE' AND T.S_TARGET=S_SOLD;


/* Employee searching by their designation */


create or replace
PROCEDURE FETCH_EMP_DETAILS(VDESIG CHAR)
AS
  CURSOR F_EMP_DETAILS
      IS
        SELECT S_name,S_Designation FROM SALES_PERSON WHERE S_Designation = VDESIG;
        VSNAME VARCHAR2(50);
        VSDESIG VARCHAR2(15);
  BEGIN
      OPEN F_EMP_DETAILS; 
      LOOP
        FETCH F_EMP_DETAILS INTO VSNAME,VSDESIG;
        EXIT WHEN NOT F_EMP_DETAILS%FOUND;
        DBMS_OUTPUT.PUT_LINE('EMP NAME : ' || VSNAME);
        DBMS_OUTPUT.PUT_LINE('DESIGNATION : ' || VSDESIG);
      END LOOP;
      CLOSE F_EMP_DETAILS;
END FETCH_EMP_DETAILS;


SET SERVEROUTPUT ON
BEGIN
  FETCH_EMP_DETAILS('EXECUTIVE');
END;



Comments

Popular posts from this blog

Hi! I'm Java...

Java is a computer programming language. It enables programmers to write computer instructions using English based commands, instead of having to write in numeric codes. It’s known as a “high-level” language because it can be read and written easily by humans. Like English, Java has a set of rules that determine how the instructions are written. These rules are known as its “syntax”. Once a program has been written, the high-level instructions are translated into numeric codes that computers can understand and execute. Who Created Java? In the early nineties, Java was created by a team led by James Gosling for Sun Microsystems. It was originally designed for use on digital mobile devices, such as cell phones. However, when Java 1.0 was released to the public in 1996, its main focus had shifted to use on the Internet. It provided more interactivity with users by giving developers a way to produce animated webpages . Over the years it has evolved as a successful language for

Comparison over Intel Core 2 duo & Intel Core i3 Processor

A comparison between processors was simple some years ago with a single core processor. All you had to look at was the clocking frequency and the cache size. The entry of multiple core chips changed it all and life became complicated. With dual, quad and even six core processors hitting the market, there are many more factors to be considered, than before. Intel's dual core and core 2 duo processors were the first ones to introduce multi-core processor based computing. The quad core processors created later have given rise to the quad core vs dual core debate, as well as the core i5 vs core i7 comparison which is something that high-end computing market consumers should think about. Prior to that, we only had the 32 bit vs 64 bit processors comparison to worry about. Today, Intel has gone through a lot of designing and planning, to introduce core i3 processors that are an improvement over the core 2 duo line. The following Intel core i3 vs core 2 duo processor comparison wil

I'm the Server Operating System

Server Operating System A server operating system is software that was especially developed to serve as a platform for running multi-user computer programs, applications that are networked and programs critical to business computing. This type of operating system (OS) often comes bundled with the most common types of applications deployed in the client-server model, a term used to indicate the exchange of information between computers. For example, a hypertext transfer protocol (HTTP) or web server hosts or "holds" the text files, images files and scripts that work together to form a website. When someone connects to the Internet and types in a web address, the server that holds the files of the site delivers or "serves" the requested pages to the client computer or the machine that made the request. Frequently used applications in the client-server model handle operations for sharing files and printers across a network, hosting and serving web pages via the