Pages

Showing posts with label Wild card characters. Show all posts
Showing posts with label Wild card characters. Show all posts

Monday, 20 September 2021

Wild card characters

Wild card characters                 Description

                               A substitute for zero (or) more Characters 

_(underscore)             A substitute for single character

A wild card character can substitute any other character in a string in SQL.

These are used with ‘like’ operator these are used to search for specific data within a table

Ex 1. Select all customers in a city starting with l followed by any character, followed by n and followed by any character (fixed length).

Query:

select * from customer where city like 'l-n-----‘;

Ex 2. List the names of customers whose name start with letter n followed by a character and followed by variable length.

Query :

Select  *  from  customer  where  name  like  ‘ n_% ‘ ;

Ex 3 . List  all  customers  whose  name  starts  with  a 

Query :

Select  *  from  customer  where  name  like  'a%' ;

Ex 4 . List  all  customers  whose  name  ends  with  a

Query :

Select  *  from  customer  where  name  like  '%a';


Special Operator:

Operator               Description

like            Pattern  matching  from  a column

in               To  check  the  value  within  the  set

between    To  check  the  value  within  a range

Ex : 1 . List  the  employees  whose  name  starts  with  letter  K

Query :

select  *  from  employee whose  name  like  'K%';

2 . List  the  name  of  employees who  belong  to  the  departments  of  10  and    20 .

Query :

select  ename  from  employee where  deptno  in(10,20);

3 . List  the  employees  who  does  not  belong  to  the  departments  of  sales  and  marketing .

Query :

select  *  from  employee  where  deptname  not in  (‘sales’,’marketing’);

4 . List  the  employee number  , employee name  and  salary  of  the employee whose  salary  ranges  from  10,000  to  50,000

Query :

select  empno, empname , sal  from  employee where sal  between (10,000  to  50,000);

Example:

like , not like:
SQL> select * from product;
       PID PNAME                       QTY      PRICE     EMAIL
---------- -------------------- ---------- ---------- --------------------
       111 raj                                 2        123     sa@gm
       222 kumar                            3        234     ds@y
       333 rani                                7        542     ff@y
       444 joy                                 5        243     hg#df

SQL> select * from product where pname like 'r%';
       PID PNAME                       QTY    PRICE         EMAIL
---------- -------------------- ---------- ---------- --------------------
       111 raj                             2        123             sa@gm
       333 rani                           7        542             ff@y

SQL> select * from product where pname like 'r__';
       PID PNAME                       QTY      PRICE         EMAIL
---------- -------------------- ---------- ---------- --------------------
       111 raj                           2        123             sa@gm

SQL> select * from product where pname like '__r';
no rows selected

SQL> select * from product where pname like '__j';
       PID PNAME                       QTY      PRICE         EMAIL
---------- -------------------- ---------- ---------- --------------------
       111 raj                           2        123             sa@gm

SQL> select * from product where pname like '%%a';
no rows selected

SQL> select * from product where pname like '%a%';
       PID PNAME                       QTY      PRICE         EMAIL
---------- -------------------- ---------- ---------- --------------------
       111 raj                           2        123             sa@gm
       222 kumar                      3        234             ds@y
       333 rani                          7        542             ff@y

SQL> select * from product where pname not like '%a%';
       PID PNAME                       QTY      PRICE         EMAIL
---------- -------------------- ---------- ---------- --------------------
       444 joy                           5        243             hg#df

SQL> select * from product ;
       PID PNAME                       QTY      PRICE         EMAIL
---------- -------------------- ---------- ---------- --------------------
       111 raj                           2        123             sa@gm
       222 kumar                      3        234 ds@y
       333 rani                          7        542 ff@y
       444 joy                           5        243 hg#df

in , not in :

SQL> select * from product where pid in (111,444) ;
       PID PNAME                       QTY      PRICE EMAIL
---------- -------------------- ---------- ---------- --------------------
       111 raj                           2        123 sa@gm
       444 joy                           5        243 hg#df

SQL> select * from product where pid not in (111,444) ;
       PID PNAME                       QTY      PRICE EMAIL
---------- -------------------- ---------- ---------- --------------------
       222 kumar                      3        234 ds@y
       333 rani                          7        542 ff@y

between , not between :

SQL> select * from product where pid between 222 and 333 ;
       PID PNAME                       QTY      PRICE EMAIL
---------- -------------------- ---------- ---------- --------------------
       222 kumar                      3        234 ds@y
       333 rani                          7        542 ff@y

SQL> select * from product where pid not between 222 and 333 ;
       PID PNAME                       QTY      PRICE EMAIL
---------- -------------------- ---------- ---------- --------------------
       111 raj                           2        123 sa@gm
       444 joy                           5        243 hg#df

Conflict Serializability

Find out conflict serializability for the given transactions T1 T2 T3 R(X)     ...