viewquestions/12440/Discuss Various types of Inner Join Operations Database Management Systems 10CS54 VTU notes 8 Marks Jun July2014 5 marks Dec 14Jan 1510 Marks Jan 2016

The Eduladder is a community of students, teachers, and programmers just interested to make you pass any exams. So we solve previous year question papers for you.
See Our team
Wondering how we keep quality?
Got unsolved questions?

Ask Questions

Database-Management-Systems---10CS54-VTU-notes-->View question


Asked by:anonymousguy7799

Taged users:


Likes:
Be first to like this question

Dislikes:
Be first to dislike this question
Talk about this  Delete  Like  Dislike

Answers

Inserting Nulls

You can use indicator variables to insert nulls. Before the insert, for each column you want to be null, set the appropriate indicator variable to -1, as shown in the following example:

set ind_comm = -1; 
EXEC SQL INSERT INTO EMP (EMPNO, COMM) 
 VALUES (:emp_number, :commission:ind_comm);

The indicator variable ind_comm specifies that a null is to be stored in the COMM column.

You can hardcode the null instead, as follows:

EXEC SQL INSERT INTO EMP (EMPNO, COMM) 
 VALUES (:emp_number, NULL);

While this is less flexible, it might be more readable.

Typically, you insert nulls conditionally, as the next example shows:

display 'Enter employee number or 0 if not available: '; 
read emp_number; 
IF emp_number = 0 THEN 
 set ind_empnum = -1; ELSE 
 set ind_empnum = 0; 
ENDIF; 
EXEC SQL INSERT INTO EMP (EMPNO, SAL) 
 VALUES (:emp_number:ind_empnum, :salary);

Handling Returned Nulls

You can also use indicator variables to manipulate returned nulls, as the following example shows:

EXEC SQL SELECT ENAME, SAL, COMM 
 INTO :emp_name, :salary, :commission:ind_comm 
 FROM EMP 
 WHERE EMPNO = :emp_number; 
IF ind_comm = -1 THEN 
 set pay = salary; -- commission is null; ignore it 
ELSE 
 set pay = salary + commission; 
ENDIF;

Fetching Nulls

When DBMS=V6, you can select or fetch nulls into a host variable that lacks an indicator variable, as the following example shows:

-- assume that commission is NULL 
EXEC SQL SELECT ENAME, SAL, COMM 
 INTO :emp_name, :salary, :commission 
 FROM EMP 
 WHERE EMPNO = :emp_number;

SQLCODE in the SQLCA is set to zero indicating that Oracle executed the statement without detecting an error or exception.

However, when DBMS=V7 (the default), if you select or fetch nulls into a host variable that lacks an indicator variable, Oracle issues the following error message:

ORA-01405: fetched column value is NULL

Testing for Nulls

You can use indicator variables in the WHERE clause to test for nulls, as the following example shows:

EXEC SQL SELECT ENAME, SAL 
 INTO :emp_name, :salary 
 FROM EMP 
 WHERE :commission:ind_comm IS NULL ...

However, you cannot use a relational operator to compare nulls with each other or with other values. For example, the following SELECT statement fails if the COMM column contains one or more nulls:

EXEC SQL SELECT ENAME, SAL 
 INTO :emp_name, :salary 
 FROM EMP 
 WHERE COMM = :commission:ind_comm;

The next example shows how to compare values for equality when some of them might be nulls:

EXEC SQL SELECT ENAME, SAL 
 INTO :emp_name, :salary 
 FROM EMP 
 WHERE (COMM = :commission) OR ((COMM IS NULL) AND 
 (:commission:ind_comm IS NULL));

Fetching Truncated Values

When DBMS=V6, if you select or fetch a truncated column value into a host variable that lacks an indicator variable, Oracle issues the following error message:

ORA-01406: fetched column value was truncated

However, when DBMS=V7, no error is generated.


Answerd By:Rohit498

Likes:
Be first to like this answer

Dislikes:
Be first to dislike this answer
Talk about this  Delete  Like  Dislike

Can you help us to add better answer here? Please see this



Below are some of the videos from our collection.Check out our video platform here.

Lets together make the web is a better place

We made eduladder by keeping the ideology of building a supermarket of all the educational material available under one roof. We are doing it with the help of individual contributors like you, interns and employees. So the resources you are looking for can be easily available and accessible also with the freedom of remix reuse and reshare our content under the terms of creative commons license with attribution required close.

You can also contribute to our vision of "Helping student to pass any exams" with these.
Answer a question: You can answer the questions not yet answered in eduladder.How to answer a question
Career: Work or do your internship with us.Work with us
Create a video: You can teach anything and everything each video should be less than five minutes should cover the idea less than five min.How to upload a video on eduladder


Not the answer you're looking for? Browse other questions from this Question paper or ask your own question.

Ask your question?