0% found this document useful (0 votes)
55 views4 pages

09-02-24 Single Row Function, Null, NVL Function

The document discusses null values in SQL and the NVL function. It explains that null represents an unknown or undefined value and cannot be used with comparison operators. The NVL function is used to convert null values to an alternate value by taking in two parameters - the column/expression and the alternate value to return if null.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views4 pages

09-02-24 Single Row Function, Null, NVL Function

The document discusses null values in SQL and the NVL function. It explains that null represents an unknown or undefined value and cannot be used with comparison operators. The NVL function is used to convert null values to an alternate value by taking in two parameters - the column/expression and the alternate value to return if null.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

USE OF NULL, NVL FUNCTION

SELECT * FROM EMP;

SELECT * FROM student19;

INSERT INTO student19 VALUES (2,'SHYAM',NULL,'','01014');

SELECT * FROM student19;

NULL VALUES:-
 If a row(record) absence of a data is known as null.
 Null is a unknown or undefined value.
 No operations are allowed to null values.
 Null is not equal to zero (null^=0)
 Each null value are not same.
 When we apply condition on null then it should compare with ‘IS’ keyword.

SELECT * FROM EMP;

SELECT * FROM EMP WHERE MGR = NULL; { it will not display the result but only display the
structure of table because = is not used In the NULL value }

SELECT * FROM EMP WHERE MGR IS NULL; { it will display the output because we are using IS in the
NULL value }

Q:- DISPLAY EMPLOYEE INFORMATION WHERE THERE IS NO REPORTING MANAGER?

SELECT * FROM EMP WHERE MGR IS NULL;

Q:- DISPLAY EMPLOYEE INFORMATION WHERE EMPLOYEES ARE GETTING NO COMMISSION?

SELECT * FROM EMP WHERE COMM IS NULL;

SELECT * FROM EMP;

CREATE TABLE STUDENT_DDL (ROLLNO NUMBER, NAME VARCHAR2(10));

INSERT INTO STUDENT_DDL VALUES (1,'RAM');

INSERT INTO STUDENT_DDL VALUES (2,'LAXMAN');

COMMIT;
SELECT * FROM STUDENT_DDL;

CREATE TABLE "STUDENT_DDL"

( "ROLLNO" NUMBER,

"NAME" VARCHAR2(10 BYTE)

);

SELECT dbms_metadata.get_ddl('TABLE','STUDENT_DDL') FROM DUAL;

SELECT dbms_metadata.get_ddl('TABLE','EMP') FROM DUAL;

CREATE TABLE "STUDENT_DDL"

( "ROLLNO" NUMBER,

"NAME" VARCHAR2(10 BYTE)

);

Insert into STUDENT_DDL (ROLLNO,NAME) values (1,'RAM');

Insert into STUDENT_DDL (ROLLNO,NAME) values (2,'LAXMAN');

SELECT * FROM STUDENT_DDL;

Q:-DISPLAY EMPNO, ENAME, SAL FOR ALL THE EMPLOYEES?

SELECT EMPNO,ENAME,SAL FROM EMP;

===========================================================================

FUNCTION:-
 Function is a database object which is used to return(give) some values.

It is two type

1. Single row function

2. Multirow function/aggregate function


SINGLE ROW FUNCTION:-
 This function works on each row of a table and return a single value.
 Oracle has predefined some functions.

1. NVL FUNCTION:- (NO VALUE)


 It is a single row function.
 It is used to convert a null value to an alternate value.
 It accept 2 parameter
 1st parameter is column/expression.
 2nd parameter is alternate value.
 Data type should be match between the parameter.

Ex:-

SELECT EMPNO,ENAME,SAL ,COMM, SAL + COMM FROM EMP;

SELECT COMM, NVL(COMM,0) FROM EMP;

SELECT COMM, NVL(COMM,100) FROM EMP;

DESC EMP;

SELECT COMM, NVL(COMM,'RAM') FROM EMP;

SELECT NAME, NVL(NAME,'KRISHNA') FROM STUDENT_DDL;

SELECT NAME, NVL(NAME,1000) FROM STUDENT_DDL;

SELECT EMPNO,ENAME,SAL, COMM, SAL + NVL(COMM,0) FROM EMP;


{IT WILL DISPLAY THE OUTPUT AS EMPNO,ENAME,SAL,COMM AND SUM OF (SAL AND COMM)}
===========================================================================

COLUMN OR EXPRESSION :-
SELECT NVL(NULL,100) FROM DUAL; { This query replaces a NULL value with 100. Since the first
parameter is NULL, it returns the second parameter, which is 100.

SELECT NVL('SCOTT',100) FROM DUAL;

SELECT NVL(200,100) FROM DUAL;

SELECT NVL(100,100) FROM DUAL;

SELECT NVL (0, 100) FROM DUAL; {This query replaces 0 (which is not NULL) with 100. Since the first
parameter is not NULL (it's 0), the function returns the first parameter.}

SELECT NVL(100) FROM DUAL;--ORA-00909: invalid number of arguments


SELECT 100 FROM DUAL;

SELECT 'SCOTT' FROM DUAL;

SELECT 'ENAME' FROM EMP;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy