SQL Server BasicsWhat is SQL Server database?What is RDBMS?What is Normalization?Why we use Denormalization?What_is_SQL?What is PL/SQL?Difference between SQL and PL/SQLDatabase TableOne to One RelationshipOne to Many RelationshipMany to Many RelationshipMany to One RelationshipString Data TypesNumber Data TypesDate Data TypesOther Data TypesCreate DatabaseDrop DatabaseCreating and Managing Users in SQL ServerCreate TableAlter TableDrop TableConstraints in SQL serverPrimary KeyForeign KeyUnique KeyCandidate KeyComposite KeyDifference between primary key and candidate keyPrimary key and foreign key relationshipSurrogate KeyCascading Referential Integrity ConstraintsSelf Referential Integrity ConstraintsInsert into statementInsert multiple recordsUpdate statementDelete statementTruncate statementDifference between Delete and TruncateAlias in SQL ServerSelect statementSelect DistinctSelect TopSelect IntoNull Functions(ISNULL(),NULLIF(),COALESCE())Sub QueryIdentity ColumnSequence objectDifference between sequence and identity columnSQL Server ClausesWHERE ClauseOrder By ClauseTop N ClauseGroup By ClauseHaving ClauseDifference between Where and HavingSQL Server OperatorsArithmetic OperatorsComparison OperatorsLogical OperatorsBitwise OperatorsAny OperatorsAll OperatorsUnion OperatorsUnion All OperatorsDifference between Union and Union AllIntersect OperatorExcept OperatorDifference between Except and IntersectJoinsInner JoinLeft JoinRight JoinFull JoinSelf JoinCross JoinViewsWhat are views?Create views using SSMSIndexed ViewsComplex ViewsCheck Option in ViewCheck Encryption in ViewSchema Binding Option in ViewRead-only ViewsUpdatable ViewsAdvantages and disadvantages of viewsCreate multiple views on one tableCan we implement index on views?Can we Perform Insert, update, delete operation on views?Stored Procedure and FunctionsWhat are Stored Procedures?Why we use stored procedures?Passing parameters to Stored procedureUser-Defined FunctionsDifference between UDF and Stored procedurePre-Defined Functions@@Indentity and Scope_IndentityNULLIF, ISNULL and COALESCE

What is PL/SQL? Explain with real example.

PL/SQL (Procedural Language/Structured Query Language) is an extension of SQL that provides procedural programming capabilities within the Oracle Database. It combines the power of SQL with procedural constructs such as variables, conditions, loops, and exception handling to develop complex and modular database applications. PL/SQL allows users to write blocks of code that can be executed as a single unit, making it suitable for creating stored procedures, functions, triggers, and packages within the Oracle Database.

Here's an example of a PL/SQL block that calculates the total salary of employees in a specific department:


DECLARE
  total_salary NUMBER := 0;
BEGIN
  -- Iterate over employees in the Sales department
  FOR emp IN (SELECT Salary FROM Employees WHERE Department = 'Sales') LOOP
    total_salary := total_salary + emp.Salary; -- Accumulate the salary
  END LOOP;

  -- Display the total salary
  DBMS_OUTPUT.PUT_LINE('Total Salary in Sales Department: ' || total_salary);
END;
/

Let's break down the PL/SQL block:

DECLARE: The DECLARE section is used to declare variables and other program elements. Here, we declare a variable named total_salary of type NUMBER to store the cumulative salary.

BEGIN and END: These keywords mark the beginning and end of the PL/SQL block, encapsulating the executable statements.

FOR emp IN (SELECT Salary FROM Employees WHERE Department = 'Sales') LOOP: This FOR loop iterates over the employees in the Sales department by querying the "Salary" column from the "Employees" table.

total_salary := total_salary + emp.Salary;: Inside the loop, the salary of each employee is added to the total_salary variable, accumulating the total salary.

DBMS_OUTPUT.PUT_LINE('Total Salary in Sales Department: ' || total_salary);: This statement uses the DBMS_OUTPUT.PUT_LINE procedure to display the calculated total salary.

The output of executing this PL/SQL block might look like:


Total Salary in Sales Department: 25000

This example demonstrates how PL/SQL can be used to perform procedural operations on data retrieved from the database. PL/SQL enables the development of complex business logic, data manipulations, and control structures within the Oracle Database environment. It provides the flexibility and power to build robust and efficient database applications with enhanced functionality and performance.