MySQL Stored Procedure Parameters with Special Characters

AmitDiwan
Updated on 22-Aug-2019 06:58:36

263 Views

You cannot give MySQL stored procedure parameter with @ in the beginning. You can give @ sign in user-defined variables.Following is the syntax −SET @yourVariableName=yourValue;Let us implement the above syntax to correctly place @sign −mysql> DELIMITER // mysql> CREATE PROCEDURE declare_Variable(IN StudentName varchar(100))    BEGIN       SET @Name=StudentName;       SELECT @Name;    END // Query OK, 0 rows affected (0.12 sec) mysql> DELIMITER ;Now you can call stored procedure with the help of CALL command −mysql> call declare_Variable('John Smith');This will produce the following output −+------------+ | @Name | +------------+ | John Smith | +------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected, 1 warning (0.03 sec)

Insert or Update in the Same MySQL Query

AmitDiwan
Updated on 22-Aug-2019 06:56:16

224 Views

Yes, use ON DUPLICATE KEY UPDATE. Let us first create a table −mysql> create table DemoTable(Id int NOT NULL PRIMARY KEY, Number int); Query OK, 0 rows affected (0.83 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1, 190) ON DUPLICATE KEY UPDATE Number=Number+10; Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(2, 130) ON DUPLICATE KEY UPDATE Number=Number+10; Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(1, 190) ON DUPLICATE KEY UPDATE Number=Number+10; Query OK, 2 rows affected (0.14 sec) mysql> insert into DemoTable values(2, 130) ON DUPLICATE ... Read More

Print Left Rotation of Array in O(N) Time and O(1) Space in C

Sunidhi Bansal
Updated on 22-Aug-2019 06:54:19

198 Views

We are given an array of some size n and multiple integer values, we need to rotate an array from a given index k.We want to rotate an array from a index k like −ExamplesInput: arr[] = {1, 2, 3, 4, 5}    K1 = 1    K2 = 3    K3 = 6 Output:    2 3 4 5 1    4 5 1 2 3    2 3 4 5 1AlgorithmSTART Step 1 -> Declare function void leftRotate(int arr[], int n, int k)    Declare int cal = k% n    Loop For int i=0 and i In ... Read More

Print K Different Sorted Permutations of a Given Array in C

Sunidhi Bansal
Updated on 22-Aug-2019 06:49:37

228 Views

Given an array a[] containing N integers, the challenge is to print k different permutations of indices such that the values at those indices form a non-decreasing sequence. Print -1 if it is not possible.ExampleInput: arr[] = {2, 5, 6, 2, 2, 2, 2}, k = 4 Output:    0 3 4 5 6 1 2    3 0 4 5 6 1 2    0 3 4 5 6 1 2    3 0 4 5 6 1 2Sort the given array and keep track of the original indices of each element. That gives one required permutation. Now if ... Read More

Set NULL Values to 0 in MySQL Select

AmitDiwan
Updated on 22-Aug-2019 06:44:54

456 Views

For this, use IFNULL(). Let us first create a table −mysql> create table DemoTable (Value int); Query OK, 0 rows affected (1.02 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(NULL); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(NULL); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> ... Read More

Set Special Characters for Password in MySQL User Creation

AmitDiwan
Updated on 22-Aug-2019 06:40:42

487 Views

To set special characters for a password, use the following syntax −create user 'yourUserName'@'yourHostName' identified by 'yourSpecialCharacterPassword';Let us implement the above syntax in order to create a new user and set password with special characters −mysql> create user 'Mike'@'localhost' identified by 'Mike_123456'; Query OK, 0 rows affected (0.35 sec)Let us check the table where MySQL user and host is stored −mysql> select user, host from MySQL.user;This will produce the following output. The new user created successfully −+------------------+-----------+ | user             | host      | +------------------+-----------+ | Bob              | ... Read More

Print Index of Columns Sorted by Count of Zeroes in a Given Matrix in C

Sunidhi Bansal
Updated on 22-Aug-2019 06:38:22

170 Views

Given an array of size NxM where N number of rows and M number of columns, and the task is to print the number of zeroes in every column of a corresponding matrix after performing sort operation on the basis of number of zeros present in any column.For example if the 1st column contain 1 zeros and 2nd column doesn’t contain any number of zeros and 3rd column contain 2 zeroes then the result should be − 3 1 2.ExampleInput:    0 0 0    1 1 1    1 0 1 Output: 1 3 2ExplanationNote − the matrix is ... Read More

Remove Primary Key from MySQL Table

AmitDiwan
Updated on 22-Aug-2019 06:31:37

503 Views

Yes, we can remove a primary key using the DROP in MySQL. Following is the syntax −alter table yourTableName drop primary key;Let us first create a table −mysql> create table DemoTable    (       UserId int NOT NULL PRIMARY KEY    ); Query OK, 0 rows affected (0.58 sec)Following is the query to check the description of table −mysql> desc DemoTable;This will produce the following output displaying the Primary Key −+--------+---------+------+-----+---------+-------+ | Field  | Type | Null | Key | Default | Extra | +--------+---------+------+-----+---------+-------+ | UserId | int(11) | NO | PRI ... Read More

Print Corner Elements and Their Sum in a 2D Matrix in C Program

Sunidhi Bansal
Updated on 22-Aug-2019 06:29:35

3K+ Views

Given an array of size 2X2 and the challenge is to print the sum of all the corner elements stored in an array.Assume a matrix mat[r][c], with some row “r” and column “c” starting row and column from 0, then its corner elements will be; mat[0][0], mat[0][c-1], mat[r-1][0], mat[r-1][c-1]. Now the task is to get these corner elements and sum those corner elements i.e., mat[0][0] + mat[0][c-1] + mat[r-1][0] + mat[r-1][c-1], and print the result on the screen.ExampleInput: Enter the matrix elements :    10 2 10    2 3 4    10 4 10 Output: sum of matrix is ... Read More

Print Balanced Bracket Expression Using Given Brackets in C

Sunidhi Bansal
Updated on 22-Aug-2019 06:24:14

404 Views

Given four variables a, b, c, d with predefined values that will print the given bracket depending upon the variable used.Where variable, a for (( b for () c for )( d for ))The task is to use all the given brackets and print the balanced bracket expression, if we cannot form a balanced bracket expression then print -1. In case of multiple answers we can print any of the multiple answers which can be formed using the given brackets.ExampleInput: a = 3, b = 2, c = 4, d = 3 Output : (((((()()()()())))))()()To achieve this result we can, ... Read More

Advertisements