Page 170 - Informatics_Practices_Fliipbook_Class12
P. 170

Executing the above statement will produce  the output shown in Table 4.22.


                                               Dept_Name          Location

                                             Administration         Delhi
                                              Home Goods          Mumbai

                                                 Textile          Mumbai

                                      Table 4.22 Departments located in Mumbai or Delhi
        4.4.14 IS Operator

        Recall from the previous chapter that when the value of an attribute is not known, we use either the default value
        (if specified) or the  NULL  value. We can check whether a value is NULL  using IS  NULL  or IS NOT NULL.
        Using the following syntax:

               SELECT attribute1, attribute2, ...
               FROM table_name
               WHERE attributeJ IS [NOT] NULL;
        The  operator  IS NULL  returns  TRUE  if  the  specified  attribute  (attributeJ  in  the  above  description)  has
        a  NULL  value  and  FALSE  otherwise.  The  operator  IS  NOT  NULL  returns  TRUE  if  the  specified  attribute
        (attributeJ in the above description) has a non-NULL value and FALSE  otherwise.

        For example, to display the department name and the manager ID (from Table 4.23) for the departments having  a
        manager(means having a value in the attribute Mgr_Id).
               SELECT Dept_Name, Mgr_Id

               FROM DEPARTMENT
               WHERE Mgr_Id IS NOT NULL;
        Executing the above statement will produce  the output shown in Table 4.23.

                                               Dept_Name          Mgr_Id

                                              Administration       10005
                                               Home Goods          10003

                                                Automobile         10007
                                                  Textile          10004

                              Table 4.23 Dept_Name, Mgr_Id for the departments with a manager

        4.4.15 LIKE Operator

        The SQL LIKE operator uses wildcard operators % and _ to define a pattern.  The per cent  (%) operator denotes
        zero, one, or more occurrences of arbitrary characters. The underscore (_)  operator represents exactly one occurrence
        of an arbitrary character. If required, we may use a combination of % and _  operators. The syntax for the LIKE
        operator is given below:
               SELECT attribute1, attribute2, ...
               FROM table_name

               WHERE attributeJ LIKE 'pattern';



          156  Touchpad Informatics Practices-XII
   165   166   167   168   169   170   171   172   173   174   175