Posts

Showing posts from July, 2020

Create view, table, procedure based on some business scenario

Create 2 views, 1 trigger, 2 stored procedures based on some situation. 1.) Create student  and fee table 2.) generate roll number procedure 3.) Insert Procedure 4.) Trigger to audit updatation of address 5.)  Create view to visualize student paid fee and along with student information. 6.)  Create view for old and new address CREATE TABLE STUDENT_NEW(StudentId VARCHAR2(8), FirstName VARCHAR2(20), LastName VARCHAR2(20), Age NUMBER, Address VARCHAR2(50),  Mobile NUMBER, Email VARCHAR2(100), CONSTRAINT PK_StudentId PRIMARY KEY (StudentId)); --drop table student_new INSERT INTO STUDENT_NEW VALUES('00000001', 'Ravi','Shastri', 26, 'Red Cross Marg, Ulhasnagar, Mumbai', '9112340987','Ravi001@gmail.com') To generate new roll no Insert new student information CREATE OR REPLACE PROCEDURE GENERATE_STUDENT_ID(pStudentId OUT VARCHAR2) AS v_StudentId VARCHAR2(8); BEGIN SELECT MAX(STUDENTID) INTO v_StudentId  FROM STUDENT_NEW; --DBMS_OUTPUT.PUT_LINE(v_...

How to convert rows to columns in oracle

We have data of attendance('ab'--> absent, null--> present) on different dates(d1, d2..) select id, value from ( select 1 id, null d1, 'ab' d2, 'ab' d3, 'ab' d4, 'ab' d5 from dual union all select 2 id, null d1, 'ab' d2, 'ab' d3, 'ab' d4, 'ab' d5 from dual union all select 3 id, null d1, 'ab' d2, 'ab' d3, 'ab' d4, 'ab' d5 from dual union all select 4 id, null d1, 'ab' d2, 'ab' d3, 'ab' d4, 'ab' d5 from dual union all select 5 id, null d1, 'ab' d2, 'ab' d3, 'ab' d4, 'ab' d5 from dual )  UNPIVOT ( value for value_type in(d1,d2,d3,d4,d5) ) Later, you can take the count of it. select id, count(value) from ( select 1 id, null d1, 'ab' d2, 'ab' d3, 'ab' d4, 'ab' d5 from dual union all select 2 id, null d1, 'ab' d2, 'ab' d3, 'ab' d4, 'ab' d5 from dual union a...