Delete all records of Department which is located in CHN-102 - cover image

Create a PL/SQL Block to delete all the records of department, which is located in 'CHN-102'.

Table name: Department

COLUMN DATATYPE CONS.
DEPARTMENT_ID NUMBER(5) PK
DEPARTMENT_NAME VARCHAR2(25) NOT NULL
LOCATION_ID VARCHAR2(15)
(Hint: Data is case sensitive. Use '/' to terminate the PL/SQL block)

Let's break down the PL/SQL block step by step:

BEGIN: This keyword marks the beginning of the PL/SQL block, indicating that a sequence of statements is about to begin.

DELETE FROM Department WHERE LOCATION_ID LIKE 'CHN-102': This is the SQL statement within the PL/SQL block. It instructs the database to delete records from the Department table where the LOCATION_ID column matches 'CHN-102'. The LIKE keyword allows for partial matches, but in this case, it's effectively a simple comparison.

END: Marks the end of the PL/SQL block.

/: This is a forward slash often used to execute the PL/SQL block in some SQL environments. It indicates the end of the block and prompts the environment to execute the preceding PL/SQL statements.

Leave a comment