The set+0 converts the set value to integer. Let us see an example by creating a table −
mysql> create table SetZeroDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> TechnicalSkills set('C','Spring Framework /Hibernate','Python','Django Framework','Core Java') NOT NULL -> ); Query OK, 0 rows affected (0.56 sec)
Insert some records in the table using insert command. The query is as follows −
mysql> insert into SetZeroDemo(TechnicalSkills) -> values('C,Spring Framework /Hibernate,Python,Django Framework,Core Java'); Query OK, 1 row affected (0.20 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from SetZeroDemo;
Here is the output −
+----+-----------------------------------------------------------------+ | Id | TechnicalSkills | +----+-----------------------------------------------------------------+ | 1 | C,Spring Framework /Hibernate,Python,Django Framework,Core Java | +----+-----------------------------------------------------------------+ 1 row in set (0.00 sec)
Here is the query to set+0 in MySQL statement −
mysql> select TechnicalSkills+0 from SetZeroDemo;
The following is the output −
+-------------------+ | TechnicalSkills+0 | +-------------------+ | 31 | +-------------------+ 1 row in set (0.00 sec)
Now, let us see how the result above is 31.
It starts from 0 till the insert value. In the above table there are 5 words that means it starts from power 0 to 4 (because there are 5 words) as shown below −
=20+21+22+23+24 =1+2+4+8+16 =15+16 =31