You are on page 1of 20

PLSQL +

Oracle Charles Babbage

English
conceived
developed
Data_Ba mathematician and inventor Charles Babbage is credited with having
the first automatic digital computer. During the mid-1830s Babbage
plans for the Analytical Engine.

In 1642,
calculator se during the Renaissance era, Blaise Pascal invented the mechanical
which was the first device to perform addition, subtraction,
multiplication and division on its own

Gary Kildall

'A real inventor': UW's Gary Kildall, father of the PC operating system, honored for key work.

Bill Gates

The original Windows 1 was released in November 1985 and was Microsoft's first true attempt at a graphical user
interface in 16-bit. Development was spearheaded by Microsoft founder Bill Gates and ran on top of MS-DOS, which
relied on command-line input.

‘Edgar Frank "Ted" Codd’ also known to the world as the 'Father of Database Management Systems' had
propounded 12 rules which are in-fact 13 in number.

The SQL programming language was first developed in the 1970s by IBM researchers Raymond Boyce and
Donald Chamberlin.
In 1977, Larry Ellison, Bob Miner, and Ed Oates started the consultancy Software Development Laboratories,
which became Relational Software, Inc. (RSI). In 1983, RSI became Oracle Systems Corporation and then later
Oracle Corporation.

PL/pgSQL (Procedural Language/PostgreSQL) is a procedural programming language supported by the


PostgreSQL ORDBMS. It closely resembles Oracle's PL/SQL language. Implemented by Jan Wieck, PL/pgSQL
first appeared with PostgreSQL 6.4, released on October 30, 1998.

CREATE TABLE WITH PK:

Create table groups (


Group_id Number(2),
Goup_title varcher2(20),
constraint g_pk Primary key(Group_id)
);

FORIEIGN KEY:

Create table Account_Master(


g_id Number(2),
acc_id Number(10),
sub_acc_id Number(10),
account_title varchar2(20) ,
constraint g_fk Foreign_key(g_id) References groups(Group_id)
);

ALTER TABLE:

Alter table Accont_Master


Modify account_title Number(10);
We can increase the size of a column in same data type and can not decrease the column size unless the
column values set to null.
We cannot change the datatype unless the column values set to null.

DROP UNIQUE CONSTRAINT:

ALTER TABLE table_name


DROP CONSTRAINT constraint_name;

FRAMES IN REPORT BUILSER:

1. Outer main Fram


2. Grouped frame for Labels and Repeating data(Columns)
3. Label Frame:
a. Frame For labels
b. Labels
4. Repeating Frame for:
a. Fields

MATRIX REPORT:

Order_Date 7-Apr-2021 8-Apr-2021 9-Apr-2021 10-Apr-2021


Nokia 3 3 4 6
Oppo 3 3 4 2
Vivo 3 8 0 2
 Green Are Matrix Rows Fields.
 Gray Are Matrix Columns
 Turqous Are Matrix Fields

ORACLE FILE EXTENSION:

1. Froms have:
o .fmb
o .fmx
2. Menus have:
o .mmb
o .mmx
3. Reports have:
o .rdf
o .rep
4. Libraries have:
o .pll
o plx
o General Library  Attach it to Data entry Forms.
o Normal Library  Attach it to Report Running Forms.
All the extensions with have last letter ‘x and p(Report)’ are not editable and all others are editables.

WINDOWS IN ORACLE BUILDERS:

MDI: Multiple Document Interface (Parent window).


SDI: Single Document Interface (Child window).

COMPILATIONS:

Ctrl +k  Incremental Compile


Ctrl + Shift + k  All Compile
Ctrl + t  Module Compile

WORK TO DO AFTER FRESH INSTALLATION OF 10G:

1. Take file TnsNames.ora form server path is “Z:\oracle\product\10.2.0\db_1\network\ADMIN”


past it to at Developer 10g intallation folder path is “Z:\DevSuiteHome_1\NETWORK\ADMIN”.
2. Make changes to file FormsWeb.cfg at path “Z:\DevSuiteHome_1\forms\server” or take it form
other PC form same path.
PATHS FOR ORACLE BUILDERS:

1. Oracle forms Builder file frmbld.exe will be at path “Z:\DevSuiteHome_1\BIN”.


2. Oracle report Builder file rwbuilder.exe will be at same path “Z:\DevSuiteHome_1\BIN”.
3. For 6i files will be like ifrun60.exe and rwbld.exe

PATHE OF OC4J:

Oc4j file is startinst.bat, and oc4j can be stop by file stopinst.bat and can be find from path:
“Z:\DevSuiteHome_1\j2ee\DevSuite\ startinst.bat”

PATH OF REPORT SERVER:

Report server path is “Z:\DevSuiteHome_1\BIN\rwserver.exe”.


and we can set report server for spacific report server Name by setting its target in its properties as
“Z:\DevSuiteHome_1\BIN\rwserver.exe rwserver server = oam_mt_abd”

LOV  LIST OF VALUES:

o In 6i it will open by pressing F9


o In 10g it will open by Pressing Ctrl + L

ERRORS:

o In 6i it will be showing by pressing Shift + F1


o In 10 it will be showing by pressing Ctrl + Shift + E

SEARCH IN 10G:

Press F11 then enter in the field( like LOV) then press show button  Result will be shown of requested
data in this way we can perform search operation in Oracle 10g.

SEARCH IN 6I:

Press F7 then enter in the field( like LOV) then press show button  Result will be shown of requested data
in this way we can perform search operation in Oracle 6i.

HOW TO START PROGRAMS TO WINDOWS STARTUPS:

Press the Windows logo key  + R, type shell:startup, then select OK. This opens the Startup folder.
Copy and paste the shortcut to the app from the file location to the Startup folder.

GROUPS TABLE VALUE/ ACCOUNTING PILLERS:

1-0-0-0 Capital
2-0-0–0 Liabilities
3-0-0–0 Assets
4-0-0–0 Revenues
5-0-0-0 Expensis

–GAME OF CHART OF ACCOUNTS:

0 0 0 0
Group_Id Account_Id Sub_Acc_Id Branch_acc_Id
Head Account Main/Parent Account Group Account Transacional Account
Fixed by Accounting Fixed by Accounting Can be changed Changed by Every
Principal Principal Transaction

FROMS BUTTON VISIBILITY AND ENABLELITY:

1) On Load / When new form instance:

Visible All Except Save.


Enable New, Show, Exit.
Disabled Edit, Next, Previous, Delete, Print, Exit.

2) On Click ‘New’:

Visible All Except Exit.


Enable Cancel, Save.
Disabled Show, Next, Previous, Delete, Print, Exit.
3) On Click ‘Save:

Visible All Except Save.


Enable New, show, Exit.
Disabled Edit, Next, Previous, Delete, Print.

4) On Click ‘Show:

Visible All Except Save.


Enable All enabled butt only Next.
Disabled Next.
5) On Click ‘Previous:

Visible All Except Save.


Enable All Except Save.
Disabled Save.

6) On Click ‘Next’:

Visible All Except Save.


Enable All except Save.
Disabled Save

7) On Click ‘Delete:

Visible All Except Save.


Enable New, Show, Exit.
Disabled Edit, Next, Previous, Delete, Print.

8) On Click ‘Print:

Visible All Except Save.


Enable All Except Save.
Disabled Save

9) On Click ‘Edit:

Visible All Except Edit.


Enable Cancel, Save.
Disabled Show, Next, Previous, Delete, Print, Exit.

‘Save’ is visible when we Click ‘New’ and Hides ‘Edit’.


On Load/When New form, New, Save, Delete, Exit  Group
Show, Next, Previous, Print  Group
Delete Record of Dedailed table by Clicking Ctrl +Up Arrow.

FORMULA COLUMN:

Formula is user-define column that have PLSQL Coding in form of sql statement, function, expression of
combination of these, which uses the other columns of query of formula column/s. Formula column return
some value/s.

PLACEHOLDER:

It works like global variable that accepts the value/s of formula column, its data type should be same the
returning value of formula column.

SUMMARY COLUMN:

It is used to calculate the agregate function like sum, avg, min, max and count, its data type should be
accouringt ot the agregate function.

INSIDE OR OUTSIDE DATA GROUP?

If we want to calculate a value for every row place the formula column in the group of the data model , so
that it called every time for every record and if we want to derive a value at report level place the formula
column outside to the data group.

ASSIGNMENT # 01 TABLES:

Some table that is used in every software:

Groups
Account_Master
Transaction_Master Trn_dtl
Purchase_Order_Master Purchase_order_dtl
Purchase_return_Master Purchase_return_dtl
Supplier
Item_Type Item_Master
Unit
Grn_Master Grn_dtl

EXPROT BACKUP BY SQL*PLUS:

1) system/oraip@orclip
2) host exp abudllah/abdullah@orclip;
3) Enter array fetch buffer size 4096 > Hit Enter
4) Export file: EXPDAT.DMP > (Path like) :\Proj_fldr_name\Backup_fldr\Your_backupName.dmp
5) (1) E (Entier database), (2) U (Users), or (3) T(Tables): (2) U > Hit Enter
6) Export Grants (yes/no): yes > Hit Enter
7) Export Table data (yes/no): yes > Hit Enter
8) Compress Contents (yes/no): yes > Hit Enter
9) User to be exported > Abdullah (Hit Enter)
10) > Hit Enter
11) > Hit Enter
12) > Hit Enter

IMPORT BACKUP PROCEDURE BY SQL*PLUS:

1) System/oraip@orclip
2) Drop user abdullah cascade;
3) Create suer abdullah identified by abdullah;
4) Grant DBA to abdullah identified by abdullah;
5) host imp abudllah/abdullah@orclip;
6) Import file: EXPDAT.DMP > (path) Z:\proj_folder\backup.dmp
7) List contents of Import file only (yes/no):no > Hit Enter
8) Import Grants (yes/no): yes > Hit Enter
9) Import table data (yes/no): yes > Hit Enter
10) Import entire export file (yes/no): no > Y
11) Wait for “About ot Enable constraints…”
DABIT CRADIT CONCEOPTS:

1-Capital
2-Assets 3-Liabilities
5-Expenses 4-Revenues

Increases Decreases Increases Decreases

Debit Cradit Cradit Debit

ENTRIES FOR DABIT CARIT IN ORACLE FORMS:


1) When we take Mobiles(Expense Account or purchase Account or Cash Account) From Vivo.com(Party
Account or Supplier Account) on Cradit basis(order invoice) at Rupees like 2kk. Now, The Entries will be like
as:
Purchase A/C (5 – x – x - x) 2kk
Party or SupplierA/C (2 – x – x – x) 2kk

2) When uppper Transaction(at bullot point 1.) will be on cash (when we pay to Vivo.com 2kk at some date).
Then The Entries will be like as:
Party or SupplierA/C (2 - 0 - 0 - 0) 2kk
Cash A/C (2 – x – x - x) 2kk

3) When Customer will buy mobile from us on Credit basis then Entries will be like as:
Customer A/C (2 – x – x - x) 30k
Revenue A/C (4 – x – x - x) 30k

4) When customer will pay 30k us the ammount of monbile. Then The Entries will be like as:
Cash A/C (2 – x – x - x) 30k
Customer A/C (2 – x – x - x) 30k

1) When a business man comense(Start ) Business with 2kk rupees. Then The Entries will be like as:
Cash A/C (2 – x – x - x) 30k
Capital A/C (1 – x – x - x) 30k

TOAD SHORTCUTS:
When we press These short keys in ‘Toad for Oracle’:
F1  Toad Guid Book
F2  Output window min or Max.

FOREIGN KEY NOT IN TABLE SCRIPT:


We can make foreign keys by at form level (by Enforce Referencial key) in Oracle Form Builder and in Oracle Report
Builder or Quries like the the referiantial column must be represent uniquely each records of table, even we do’t
define foreign key at level of making tables Script.

VIEW IN PLSQL POINTS:


1) We can combine more then one table in view with the usage of UNION and UNION ALL.
2) The combined tables must have same Columns and their dataTypes.
3) If some column have no such column that is define in view we replace it with dummy column like
i. If its data type is number then replace it with ‘ 0 Column_Name’.
ii. If its data type is varchar2() then replace it with ‘ “ ” Column_Name’.

AVAILABE STOCK HAVE EFFECTS:


Opening Balance, Purchase, Purchase Return, Sales, Sale Return  Availabele Stock

JOURNAL VOUCHER AND TRAIL BALANCE HAVE EFFECTS OF:


Cash Payment voucher, Cash Receive voucher, Bank Payment voucher, Banck Receive voucher and some others 
Journal Voucher(JV)

Cash Payment voucher


Cash Receive voucher
Bank Payment voucher
Banck Receive voucher Some Sale perspectives
and some others Some Purchase
Journal
voucher (JV) Perspectives

Trail Balance

TARANSACTION MATER TABLE VOUCHERS OF AL-KARAM:


Voucher Extension Extension Description
%-ADM Admition
%-A Advnce
%-AR Advance Return
%-FC Fee Challan
%-JV Journal Voucher
%-L Loan
%-LR Loan Return
%-PV Cash Payment Voucher
%-SR Salary

TARANSACTION MATER TABLE VOUCHERS OF SK_HOSPITAL:

Voucher Extension Extension Description


%-BP Bank Payment
%-RV Receive Voucher

TARANSACTION MATER TABLE VOUCHERS OF NAVEED_RRADERS:

Voucher Extension Extension Description


%-SIN Sale Invoice
%-SRN Sale Return
%-PIN Purchase Invoice
%-PRN Purchase Return
%-CS Cash Sale / Cradit Sale
%-CS Cash Payment Invoice at GC_Grammar

TARANSACTION MATER TABLE VOUCHERS OF CC_FACTORY:

Voucher Extension Extension Description


%-CSR Cash Sale Return
%-CPV Cash Payment Voucher
%-PRN Purchase Return at GymKhana

TARANSACTION MATER TABLE VOUCHERS OF MAZHAR_FLOUR_MILL:

Voucher Extension Extension Description


%-CSI Cash Sale Invoice
%-BPI Bank Payment Invoice
%-BR Bank Receive
%-WIN Weat Invoice at Mukhtar
%-WSI Weat Sale Invoice at Mukhtar

WHEY WE NEED NORMALIZATION:


Let’s, Suppose we have a table with all its attributes like Studient_id, Student_Name, Course_id, Course_Name,
First_Name, Salary. If we want to insert, Delete or Update date related to one entity like Student, Course or Salary,
we have to forcefully do that operation with all other entities which cause Problems like
1) Insertion Anomaly
2) Deletion Anamaly
3) Update Anamaly
4) Data Reduncy.
To Solve these Problems, we have to make separate tables of each entity.

FIRST NORMAL FORM (1NF):


Remove or Solve multi_valued attributes from table.

CLOSURE METHOD[IMPLLIES]:
Functional dependency is identified by experienced database person.
Functional dependency shape is like

AB BC  D EC DA

1) Write all the attributes which are on the the right hand side of bold arrow as are [B, D, C, A] then see the
attributes that are not include in this collection like [ E ], that attribute/s will be candidate key( CK ) or part
of candidate Key.
2) Then find all other attributes by the select attibute candidate key by closure or Implies method. If you find all
attributes by the selected key, will called candidate key.
3) But if you fialed to find all attributes, then add one attribute from rest collection and repeat above implies
or closure method. If you find the all the attributes then these two attributes will called candidate key. But if
you failed then add all attributes one by one to repeat the above method.
4) Here, ‘AE’ find all the attributes of table so, ‘AE’ are called Candidate Keys.
5) Now, as we Know ‘E’ is always part of candidate key, So, Replace ‘A’ from candidate key ‘AE’ with a attribute
on which ‘A’ is dependent like D  A. Here, ‘D’ is required to replace with ‘A’ to find all the attributes of
table.
6) Repeat Step-5 but now for ‘D’ .
7) If Independent attribute(attribute that is located on right hand side of bold arrow) not find for step-5 then
that pairs of attribute will be candidate key.

TRANSITIVE DEPENDENCY:
If X  Y and Y  Z then x  z.
For Sub set  https://www.youtube.com/watch?v=xotLg-oLboY

SOME MOST NECESSARY MATH COMCEPT:


A = {1, 2, 3}, B = {1, 2, 3, 4, 5} C = {3, 1, 2}, and D = {1, 3, 4, 5}

SUBSET:
Set ‘A’ is par of set ‘B’  Set ‘A’ is a Subset of set ‘B’  A B

Subset Condition: Every element of Set ‘A’ should alse present in set ‘B’.
So, Set ‘A’ is Subset of Set ‘C’. So, Every Set is Subset of itself.

PROPER SUBSET:
Set ‘B’ has members that do not belong to set ‘A’. So, Set ‘A’ is Proper Subset of Set ‘B’.

IMPROPER SUBSET:

Set ‘C’ has not members that do not belong to set ‘A’ i.e. C =A. So, Set ‘A’ is Im-Proper Subset of Set ‘C’.

NOT SUBSET:

Since some of the members of set ‘A’ are NOT members of set ‘D’, ‘A’ is NOT a subset of ‘D’.
Symbolically this is represented as A   D.

SECOND NORMAL FORM [2NF]:


1) Relation Must be in 1st Normal From.
2) All the attributes in candidate key are called Prime attributes and rest of attributes are called non-Prime
attributes.
3) All the Non- Prime attributes should be fully functional dependent on Candidate Key (CK).
4) Find Candidate Key by Closure method.

Functional Dependencies: AB BC  D EC DA

Here, Candidate Keys = EC+


As, Second NF says in other words blow condition( Point 5) should not be hold:
5) Left Hand Side of arrow(Implies) in functional dependencies in proint 4 should be propper Subset of
candidate key and right hand side hand side should be a non-prime attributes.

THIRD NORMAL FORM [3NF]:


1) Relation must be in 2nd Normal Form.
2) There should not Taransitive dependiency between attributes in the table.
3) For each Functional dependency FD,
Left Hand Side must be a condidate key OR Right Hand Side is a prim attribute.

BCNF BYCY CODD NORMAL FORM:


1) Relation must holds 3NF.
2) For each Functional Dependency FD,
L.H.S must be Candidate Key CK or Supper Key only.

Oracle PL/SQL Programming in Hindi Course by ITORIAN


Column: Field
Row: Record

ORACLE INVENTIONS:

SDL Software Development Laboratry was invented in 1977  1979 in RSI Relational
Software inc  1982 Oracle Carporation, its started version was V2.

ANY RDBMS SHOULD PROPERITES:


1) Insert/Update/Delete Information based on conditions.
2) Accept sql Queries
3) Secutity
4) Transction Control
5) Manage data sharing/access rules.

CURRED COMMANDS IN ORACLE:

Crate Table:
Create Table Student (
id Number,
name, varchar2(10),
Address varchar2(10)
);

Insertion In Table:
Insert into Student
Values ( 2, ‘MUHAMMAD ABDULLAH’, ‘Kotli Bawrain’);

Deletion In Table:
Delete from Student
Where id = 1;

Update In Table:
Update Student
Set Address= ‘Pakistan’,
Name = ’Islam’
Where Name = ‘MUHAMMAD ABDULLAH’;

Rename Table Name:


Rename Student To Teacher;
Save Point in Database:
SAVEPOINT command is used to temporarily save a transaction so that you can rollback to that point whenever
required.
Following is savepoint command's syntax,

SAVEPOINT savepoint_name;

A savepoint is a way of implementing subtransactions (also known as nested transactions) within a relational
database management system by indicating a point within a transaction that can be "rolled back to" without
affecting any work done in the transaction before the savepoint was created.

Multiple Record Insertion in same of multiple tables:

Insert All
InTo Groups values(1, ‘Capital’),
InTo Groups values(2, ‘Liabilities’),
InTo Account_Master(1, 0, 0, 0, ‘Asad Ali’),
INTO Account_Master( 2, 0, 0, 0, ‘Saad Chawal’)
Select * from Dual;

Referential Integrity:
Says that:
Delete record/table from Parent table/Mater Table and can insert into child which reference is available in
parent table.

JOINS:

Equi-Joins Non-Equi-Joins
Joins which have Equal sign for comparision two Joins which have Non-Equal sign for comparision
columns. two columns. like >, <, =>, =<, between

Natural Join:
I make join of two columns that even not having Foreign key in second table. It checks column that having
same datatype and uniquely defind records in their tables, make join of these two tables
like:
Select group_title, accont title From Groups Natural Join Accont_Master;

Cross Join:
Join with no Condition.
Outer Join:
I is same as Equi-join with some extra row of records. form one or two tables.

 Full Outer Join:


A full outer join performs a join between two tables that returns the results of an INNER join as well as the
results of a left and right outer join. This following query retrieves all rows in the employees table, even if
there is no match in the departments table.

 Anti-Join:
Select *
from Employee
where department_no NOT IN (
Select department_no From Department where dpt = ‘Database’);
SQL COMMANDS TYPE IN ORACLE:
 DDL (Data Definition Language):
DDL is used to create and remove database objects.
Example: Create, Alter, Drop Commands.

 DML (Data Manipulation Language):


DML is used to manipulate data in the database.
Example: Insert, Delete, Update, Select Commands.

 DCL (Data Control Language):


DCL is used to control the kind of data transaction and access to the database, like who can access and who
cannot access.
Example: Commit, Rollback are transaction control Commands. Grant, Revoke are data access commands.

GROUP BY CLAUSE:

The GROUP BY clause is used in a SELECT statement to group rows into a set of summary rows by values
of columns. The GROUP BY clause returns one row per group.
The GROUP BY clause is often used with aggregate functions such as AVG(), COUNT(), MAX(), MIN()
and SUM(). In this case, the aggregate function returns the summary information per group.

Oracle GROUP BY with an expression example


The following example groups the orders by year and returns the number of orders per year.
SELECT
EXTRACT(YEAR FROM order_date) YEAR, COUNT( order_id )
FROM orders

GROUP BY EXTRACT(YEAR FROM order_date)


ORDER BY YEAR;

BASIC ORACLE SEQUENCE:


CREATE SEQUENCE id_seq
INCREMENT BY 1
START WITH 1
MINVALUE 1
MAXVALUE 100
CYCLE
CACHE 20;
 The next value of the sequence:  SELECT id_seq.NEXTVAL FROM dual;
 the current value of the sequence  SELECT id_seq.CURRVAL FROM dual;
 This SELECT statement uses the id_seq.NEXTVAL value repeatedly: 
SELECT id_seq.NEXTVAL FROM dual CONNECT BY level <= 9;
 Drop sequence id_seq;

SCHEMA:
The design of the database is called a schema. This tells us about the structural view of the database.
It tells us the table/s, attributes, their relationships and normalizations.

 View Schema or External Schema


View Schema defines the design of the database at the view level of the data abstraction. It defines how an
end-user will interact with the database system.
 Logical or Conceptual Schema:
A logical database schema represents how the data is organized in terms of tables. It also explains how
attributes from tables are linked together.
 Physical Database Schema:
This schema pertains to the actual storage of data and its form of storage like files, indices, etc. It defines
how the data will be stored in a secondary storage.

THREE TIER SCHEMA:

ER DIAGRAMS SYMBOLS & NOTATIONS:


Relationship Symbols:

Difference between Nested Query, Correlated Query and Join Operation :

Parameters Nested Query Correlated Query Join Operation


Definition In Nested query, a query is In Correlated query, a query Join operation is used to
written inside another is nested inside another combine data or rows
query and the result of query and inner query uses from two or more tables
inner query is used in values from outer query.   based on a common
execution of outer query. field between them.
INNER JOIN, LEFT
JOIN, RIGHT JOIN,
FULL JOIN are
different types of Joins.
Example Select * from Emp where Select * from emp Where Select * from emp, dpt
emp.id in (Select dpt.id exists(Select id from dpt Where emp.id = dpt.id;
from dpt); where emp.id = dpt.id);
Approach Bottom up approach i.e. Top to Down Approach i.e. It is basically cross
Inner query runs first, and Outer query executes first product satisfying a
only once. Outer query is and for every Outer query condition.
executed with result from row Inner query is executed.
Inner query.

Dependency Inner query execution is Inner query is dependent on no dependency is there.


not dependent on Outer Outer query.
query.
Performance Performs better than Performs slower than both By using joins we
Correlated Query but is Nested Query and Join maximize the
slower than Join Operation. operations as for every outer calculation burden on
query inner query is the database but  joins
executed. are better optimized by
the server so the
retrieval time of the
query using joins will
almost always be faster
than that of a subquery.

You might also like