Using aliases in Select

How to use an aliase name in the SELECT clause in Oracle

However, instead of ename and job the column headings should be empname and jobrole. The query that will solve our purpose will be:

SELECT ENAME  EMPNAME, JOB JOBROLE FROM EMP;

The fun comes, if you want a space in between. Like if you want JOBROLE should be displayed as JOB ROLE, then the query will become like

SELECT ENAME Empname, JOB “Job Role” FROM EMP;

Notice the usage of quodes.

Null Values in Oracle

NULL in Oracle means empty. You need really a special mechanism to handle NULL values in Oracle

Oracle supoorts the NVL function to handle NULL values.

NULL means empty, so it is neither zero nor spaces. NULL value takes place, when the user does not enter any data in the respective columns.

So, if you encounter a null value, ensure that you have taken enough precautions well in advance, failing which you can land up with invisible result as any operation with the NULL value results NULL only.

Like for numbers, you can handle NVL(comm,0) – which means, if the comm column is NULL, then convert it to zero for computation purpose

Ensure that the column attribute is not set to NOT NULL. A Primary Key, by default can NEVER accept any NULL Value.

Multiple Block handling in PL/SQL

This example will demonstrate the performance of different blocks. The golden rule is followed – first inner, then outer

<> — Block Name
DECLARE
X NUMBER;
BEGIN
X:=1;
WHILE X<5
LOOP
DBMS_OUTPUT.PUT_LINE (X);
<> –Block Name
DECLARE
X NUMBER;
BEGIN
X:=1;
WHILE X<3
LOOP
DBMS_OUTPUT.PUT_LINE(X||’ ‘||OUTER.X);
X:=X+1;
END LOOP;
END;
X:=X+1;
END LOOP;
END;