How Are MySQL INSTR() and LIKE operator similar?

Lakshmi Srinivas
Updated on 20-Jun-2020 10:54:47

824 Views

We can use both INSTR() function and LIKE operator to search or match a particular pattern and they return same result. It can be demonstrated from the following example of ‘Student’ table.ExampleSuppose we want to search name, which contains ‘av’ in it, from ‘Student’ table. We can use INSTR() function as follows −mysql> Select Name from student where INSTR(name, 'av') > 0; +--------+ | Name   | +--------+ | Gaurav | | Aarav  | | Gaurav | +--------+ 3 rows in set (0.00 sec)Now, for the same kind of search we can use LIKE operator as follows −mysql> Select Name ... Read More

How can I create a table and insert values in that table using prepare statements?

V Jyothi
Updated on 20-Jun-2020 10:54:07

218 Views

It can be understood with the help of following the example in which we have created the table named ‘Student’ by using prepared statement −mysql> PREPARE stmt3 FROM 'CREATE TABLE Student(Id INT, Name Varchar(20))'; Query OK, 0 rows affected (0.00 sec) Statement prepared mysql> EXECUTE stmt3; Query OK, 0 rows affected (0.73 sec) mysql> DEALLOCATE PREPARE stmt3; Query OK, 0 rows affected (0.00 sec)Now, with the help of following queries using prepared statements, we can insert the valuesin table ‘Student’ −mysql> PREPARE stmt7 FROM 'INSERT INTO Student(Id, Name) values(?, ?)'; Query OK, 0 rows affected (0.00 sec) Statement ... Read More

How to use REPLACE() function with column’s data of MySQL table?

Fendadis John
Updated on 20-Jun-2020 10:52:56

239 Views

For using it with column’s data we need to provide column name as the argument of REPLACE() function. It can be demonstrated by using ‘Student’ table data as follows −Examplemysql> Select Id, Name, Subject, REPLACE(Subject, 's', ' Science') from Student WHERE Subject = 'Computers'; +------+--------+-----------+-----------------------------------+ | Id   | Name   | Subject   | REPLACE(Subject, 's', ' Science') | +------+--------+-----------+-----------------------------------+ | 1    | Gaurav | Computers | Computer Science                  | | 20   | Gaurav | Computers | Computer Science                  | +------+--------+-----------+-----------------------------------+ 2 rows in set (0.00 sec)

Command Line arguments in C#

Samual Sam
Updated on 20-Jun-2020 10:51:53

3K+ Views

If you want to pass arguments by command line, then use command line arguments in C# −When we create a program in c#, static void main is used and we can see the arguments in it .class HelloWorld {    static void Main(string[] args) {       /* my first program in C# */       Console.WriteLine("Hello World");       Console.ReadKey();    }The string[] args is a variable that has all the values passed from the command line as shown above.Now to print those arguments, let’s say we have an argument, “One” −Console.WriteLine("Length of the arguments: "+args.Length); ... Read More

How to use sizeof() operator to find the size of a data type or a variable in C#

karthikeya Boyini
Updated on 20-Jun-2020 10:51:08

419 Views

The sizeof() datatype returns the size of a data type. Let’s say you need to find the size of int datatype −sizeof(int);For double datatypesizeof(double);Let us see the complete example to find the size of various datatypes −Example Live Demousing System; namespace Demo {    class Program {       static void Main(string[] args) {          Console.WriteLine("The size of int is {0}", sizeof(int));          Console.WriteLine("The size of int is {0}", sizeof(char));          Console.WriteLine("The size of short is {0}", sizeof(short));          Console.WriteLine("The size of long is ... Read More

What MySQL would return if we refer a user variable which is not assigned any value explicitly?

mkotla
Updated on 20-Jun-2020 10:49:23

131 Views

In case, when we refer a user variable which is not assigned any value explicitly, MySQL would return NULL. In other words, its value would be NULL. Following example would illustrate it −mysql> Select @X, @Y, @Z, @S, @G; +------+-------+----------+------+------+ | @X   | @Y    | @Z       | @S   | @G   | +------+-------+----------+------+------+ | Ram  | Shyam | Students | 5000 | NULL | +------+-------+----------+------+------+ 1 row in set (0.00 sec)We can see from the above result set that @X, @Y, @Z and @S has been assigned values explicitly and they returned the values ... Read More

How to capture multiple matches in the same line in Java regex

Arnab Chakraborty
Updated on 20-Jun-2020 10:49:20

3K+ Views

Exampleimport java.util.regex.*; class PatternMatcher {    public static void main(String args[]) {       int count = 0;       // String to be scanned to find the pattern.       String content = "aaa bb aaa";       String string = "aaa";       // Create a Pattern object       Pattern p = Pattern.compile(string);       // get a matcher object       Matcher m = p.matcher(content);       while(m.find()) {          count++;          System.out.println("Match no:"+count);         ... Read More

What happens if I will assign a value to a MySQL user variable using a statement that returns multiple rows?

Srinivas Gorla
Updated on 20-Jun-2020 10:48:56

279 Views

In case, if we will assign a value to a user variable using a statement that returns multiple rows then the value from the last row would be saved in that user variable because user variables can save the only single value. Following the example, in which we are using data from table ‘Tender’, will exhibit it −Examplemysql> select * from Tender; +----+---------------+--------------+ | Sr | CompanyName   | Tender_value | +----+---------------+--------------+ | 1  | Abc Corp.     |   250.369003 | | 2  | Khaitan Corp. |   265.588989 | | 3  | Singla group. |   220.255997 ... Read More

How do you find the number of dimensions of an array in C#?

Samual Sam
Updated on 20-Jun-2020 10:48:43

993 Views

To find the number of dimensions of an array, use the Rank property.arr.RankHere, arr is our array −int[, ] arr = new int[3, 4];If you also want to get the rows and columns it has, then use the GetLength property −arr.GetLength(0); arr.GetLength(1);The following is the complete code −Example Live Demousing System; class Program {    static void Main() {       int[, ] arr = new int[3, 4];       Console.WriteLine(arr.GetLength(0));       Console.WriteLine(arr.GetLength(1));       // Length       Console.WriteLine(arr.Length);       Console.WriteLine("Upper Bound: {0}", arr.GetUpperBound(0).ToString());       Console.WriteLine("Lower Bound: ... Read More

How can we use SET statement to assign a SELECT result to a MySQL user variable?

radhakrishna
Updated on 20-Jun-2020 10:48:08

637 Views

For using the SET statement to assign a SELECT result to a user variable we need to write the SELECT statement as a subquery within parentheses. The condition is that the SELECT statement must have to return a single value. To make it understand we are using the data from ‘Tender’ table which is as follows −mysql> select * from Tender; +----+---------------+--------------+ | Sr | CompanyName   | Tender_value | +----+---------------+--------------+ | 1  | Abc Corp.     | 250.369003   | | 2  | Khaitan Corp. | 265.588989   | | 3  | Singla group. | 220.255997   | ... Read More

Advertisements