Tasks - Conditions and Loops #11
Replies: 34 comments
-
DELIMITER //
CREATE PROCEDURE getFactOfPrime(
IN number INT
)
BEGIN
DECLARE x INT;
DECLARE fact INT;
DECLARE str VARCHAR(225);
SET x = 1;
SET fact = 1;
SET str = "1, ";
WHILE x<number-1
DO
SET x = x+1;
SET fact = fact*x;
IF(number mod x = 0)
THEN
SET fact = 0;
SET str = CONCAT(str,x,", ");
END IF;
END WHILE;
SET fact = fact*number;
SET str = CONCAT(str,number);
IF(fact=0)
THEN
SELECT str;
ELSE
SELECT fact;
END IF;
END //
DELIMITER ;
CALL getFactOfPrime(5);
DELIMITER //
CREATE PROCEDURE isPalindrome(
IN number INT,
OUT str VARCHAR(4)
)
BEGIN
DECLARE digit INT;
DECLARE reverse INT;
DECLARE copy INT;
SET copy = number;
SET digit = 0;
SET reverse = 0;
WHILE(number>0)
DO
SET digit = number mod 10;
SET reverse = reverse*10+digit;
SET number = number/10;
END WHILE;
IF reverse = copy
THEN
SET str = "YES";
ELSE
SET str = "NO";
END IF;
END//
DELIMITER ;
CALL isPalindrome(12321,@ans);
SELECT @ans; |
Beta Was this translation helpful? Give feedback.
-
--1
DELIMITER //
CREATE PROCEDURE prime(IN n INT) BEGIN
DECLARE i,flag INT;
DECLARE str VARCHAR(255);
set str = '1,';
SET i = 2,
flag = 1;
while i < n do
SET flag =flag*i;
if(n %i = 0) then
SET flag =0;
SET str= CONCAT(str,i,',');
END IF;
SET i = i + 1;
END WHILE;
if (flag >1) THEN
SELECT flag*n as factorial;
else
SELECT str as divisors;
END IF;
END //
DELIMITER;
--palindrome
DELIMITER / / CREATE PROCEDURE palindrome(IN n INT, INOUT res VARCHAR(10)) BEGIN
DECLARE x,
r,
t INT;
SET x = n;
SET t = 0;
while x > 0 do
SET r = x %10;
SET t =(t * 10) + r;
SET x = x div 10;
end while;
IF (t = n) THEN
SET res = 'YES';
ELSE
SET res = 'NO';
END IF;
END / / DELIMITER;
call palindrome(454, @res);
select @res; |
Beta Was this translation helpful? Give feedback.
-
DELIMITER //
CREATE PROCEDURE getFactorial(
IN num INT,
OUT str varchar(255),
OUT fact int
)
BEGIN
declare flag int;
declare i int;
set flag = 1;
set i = 2;
set str="1";
While i<num
do
if(num mod i = 0) then
set flag = 0;
set str = concat(str,", ",i);
end if;
Set i = i+1;
End while;
set fact =1;
if(flag=1) then
while(num>0) do
set fact = fact*num;
set num = num-1;
end while;
select fact;
else
select str;
end if;
END //
delimiter ;
call getFactorial(5,@str,@fact);
delimiter //
CREATE PROCEDURE checkPalindrome(
IN num INT,
OUT str varchar(255)
)
BEGIN
declare temp int;
declare rev int;
set rev=0;
set temp =num;
while(temp>0) do
set rev = rev*10 + (temp mod 10);
set temp = temp/10;
end while;
if rev=num then
set str ="YES";
else
set str = "NO";
end if;
END //
delimiter ;
call checkPalindrome(141,@result);
select result;
|
Beta Was this translation helpful? Give feedback.
-
-- 1.)
-- For finding prime
create procedure prime(in num int,out res int,out sres varchar(30))
begin
declare i int default 2;
declare c int default 0;
set res=1;
set sres='1';
while(i<=num) do
if(num mod i=0) then set c=c+1;
set sres=concat(sres,',',i);
end if;
set i=i+1;
end while;
if(c>2) then set res=0;
end if;
end //
-- For factorial
create procedure fact(in num int)
begin
declare prod int default 1;
call prime(num,@res,@sres);
if(@res=1) then
while(num<>0) do
set prod=num*prod;
set num=num-1;
end while;
select prod;
else select @sres;
end if;
end //
-- 2.)
create procedure palin(in n int, inout res varchar(10))
begin
declare x,r,rev int;
set x = n;
set rev = 0;
while x > 0 do
set r = x %10;
set rev =(rev * 10) + r;
set x = x div 10;
end while;
if (rev = n) then
set @res = 'YES';
else
set @res = 'NO';
end if;
select @res;
end //
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
DELIMITER //
CREATE PROCEDURE isPrime(IN x INT(11),
OUT outputIs INT
)
BEGIN
SET outputIs = 1;
IF x < 2 THEN
SET outputIs = 0;
ELSE
SET @i = x - 1;
WHILE @i >= 2
DO
IF(x mod @i = 0) THEN
SET outputIs = 0;
END IF;
SET @i = @i - 1;
END WHILE;
END IF;
END //
DELIMITER ;
DELIMITER //
CREATE PROCEDURE printDivisor(IN x INT(11))
BEGIN
DECLARE i INT;
DECLARE str VARCHAR(255) DEFAULT '';
SET i = 1;
WHILE (i <= x)
DO
IF (x mod i = 0) THEN
SET str = CONCAT(str,i, ', ');
END IF;
SET i = i + 1;
END WHILE;
SELECT str;
END //
DELIMITER ;
DELIMITER //
CREATE PROCEDURE mainProcess(
IN x INT(11)
)
BEGIN
SET @temp = x;
CALL isPrime(@temp,@outputIs);
IF (@outputIs = 1) THEN
WHILE @temp <> 1 DO
SET @temp = @temp - 1;
SET x = x * (@temp);
END WHILE;
SELECT x;
ELSE
CALL printDivisor(@temp);
END IF;
END//
DELIMITER ;
CALL mainProcess(5);
CALL mainProcess(4);
DELIMITER //
CREATE PROCEDURE isPalindrome(IN num INT(11), OUT str VARCHAR(5)
)
BEGIN
DECLARE temp VARCHAR(20);
DECLARE rev VARCHAR(20);
SET temp = num;
SET rev = '';
WHILE (num > 0)
DO
SET rev = CONCAT(rev,num mod 10);
SET num = num / 10;
END WHILE;
IF rev = temp THEN
SET str = "YES";
ELSE
SET str = "NO";
END IF;
END//
DELIMITER ;
call isPalindrome(141,@ans);
Select @ans;
call isPalindrome(123,@ans);
Select @ans; |
Beta Was this translation helpful? Give feedback.
-
1DELIMITER //
CREATE PROCEDURE PrimeDivisor(IN n INT)
BEGIN
DECLARE i INT;
DECLARE resPrime INT;
DECLARE res1 INT;
DECLARE res2 VARCHAR(255);
SET i = 2;
SET resPrime = 1;
WHILE i < n DO
IF (n % i = 0) THEN
SET resPrime = 0;
END IF;
SET i = i+1;
END WHILE;
IF resPrime = 1 THEN
SET res1=1;
SET i = 1;
WHILE i <= n DO
SET res1 = res1*i;
SET i = i+1;
END WHILE;
ELSE
SET res2 = "";
SET i = 1;
WHILE i <= n DO
IF (n % i = 0) THEN
SET res2 = CONCAT(res2, i, ", ");
END IF;
SET i = i+1;
END WHILE;
END IF;
IF resPrime = 1 THEN
SELECT res1;
ELSE
SELECT res2;
END IF;
END //
DELIMITER ;
CALL PrimeDivisor(5);2DELIMITER //
CREATE PROCEDURE numberPalindromeCheck(IN n INT, OUT stringResult VARCHAR(5))
BEGIN
DECLARE num INT;
DECLARE result INT;
SET num = n;
SET result = 0;
WHILE num > 0 DO
SET result = result*10 + (num % 10);
SET num = num / 10;
END WHILE;
IF result = n THEN
SELECT "YES" INTO stringResult;
ELSE
SELECT "NO" INTO stringResult;
END IF;
END //
DELIMITER ;
CALL numberPalindromeCheck(141, @result);
SELECT @result;
|
Beta Was this translation helpful? Give feedback.
-
**1**
DELIMITER $$
CREATE PROCEDURE checkPrime(IN n INT) BEGIN
DECLARE i, flag INT;
DECLARE str VARCHAR(255);
SET str = '1,';
SET i = 2,
flag = 1;
while i < n do
SET flag =flag*i;
if(n %i = 0) then
SET flag =0;
SET str= CONCAT(str,i,',');
END IF;
SET i = i + 1;
END WHILE;
if (flag >1) THEN
SELECT flag*n as factorial;
else
SELECT str as divisors;
END IF;
END $$
DELIMITER ;
**2**
DELIMITER $$
CREATE PROCEDURE isPalindrome(IN n INT, INOUT result VARCHAR(10)) BEGIN
DECLARE x, r, t INT;
SET x = n;
SET t = 0;
while x > 0 do
SET r = x %10;
SET t =(t * 10) + r;
SET x = x div 10;
end while;
IF (t = n) THEN
SET result = 'YES';
ELSE
SET result = 'NO';
END IF;
END $$
DELIMITER;
call isPalindrome(1221, @res);
select @result; |
Beta Was this translation helpful? Give feedback.
-
DELIMITER &
CREATE PROCEDURE isPrime(IN x INT,
OUT outputIs INT
)
BEGIN
SET outputIs = 1;
IF x < 2 THEN
SET outputIs = 0;
ELSE
SET @i = x - 1;
WHILE @i >= 2
DO
IF(x mod @i = 0) THEN
SET outputIs = 0;
END IF;
SET @i = @i - 1;
END WHILE;
END IF;
END &
DELIMITER ;
DELIMITER &
CREATE PROCEDURE FACTORIALS(IN N INT,OUT FACT INT)
BEGIN
DECLARE I INT DEFAULT 1;
SET FACT=1;
IF N<=1 THEN SET FACT=1;
ELSE
WHILE I<=N DO
SET FACT=FACT*I;
SET I=I+1;
END WHILE;
END IF;
SELECT @FACT;
END &
DELIMITER ;
DELIMITER &
CREATE PROCEDURE DIVISORS(IN N INT,OUT S VARCHAR(20))
BEGIN
DECLARE I INT DEFAULT 1;
SET S="";
WHILE I<=N DO
IF N MOD I=0 THEN SET S=CONCAT(S,I,",");
END IF;
SET I=I+1;
END WHILE;
SELECT @S;
END &
DELIMITER ;
DELIMITER &
CREATE PROCEDURE OPERATION(IN NUM INT)
BEGIN
CALL IsPrime(NUM,@prime);
IF @prime=1 THEN CALL FACTORIALS(NUM,@fact);
ELSE CALL DIVISORS(NUM,@div);
END IF;
END &
DELIMITER ;
CALL OPERATION(5);
CALL OPERATION(4);
DELIMITER &
CREATE PROCEDURE ISPALINDROME(IN N INT)
BEGIN
DECLARE TEMP INT ;
DECLARE REV INT DEFAULT 0;
DECLARE ANS VARCHAR(5);
SET TEMP=N;
WHILE TEMP>0 DO
SET REV=(REV*10)+(TEMP%10);
SET TEMP=TEMP/10;
END WHILE;
IF REV=N THEN SET ANS='YES';
ELSE SET ANS='NO';
END IF;
SELECT ANS;
END &
DELIMITER ;
CALL ISPALINDROME(1221);
|
Beta Was this translation helpful? Give feedback.
-
DELIMITER //
CREATE PROCEDURE factorial(
IN n INT
)
BEGIN
DECLARE st VARCHAR(250);
DECLARE k INT;
DECLARE fact INT;
SET st = "1";
SET k = 2;
SET fact = 1;
WHILE k<n DO
IF (n mod k = 0) THEN
SET fact=0;
SET st = concat(st,", ",k);
ELSE
SET fact = fact*k;
END IF;
SET k = k + 1;
END WHILE;
SET fact= fact*n;
SET st = concat(st,", ",k);
IF fact=0 THEN
SELECT st;
ELSE
SELECT fact;
END IF;
END //
DELIMITER ;
call factorial(4);
call factorial(5);DELIMITER //
CREATE PROCEDURE isPalin(
IN n int
)
BEGIN
declare k int;
declare r int default 0;
declare rev int default 0;
declare ans varchar(5) default "";
set k=n;
while k>0 do
set r = k mod 10;
set k = k/10;
set rev = rev*10 + r;
end while;
if rev=n then
set ans="Yes";
else
set ans="No";
end if;
SELECT ans;
END //
DELIMITER ;
call isPalin(121);
call isPalin(234); |
Beta Was this translation helpful? Give feedback.
-
DELIMITER //
CREATE PROCEDURE getFactorial(
IN num INT,
OUT str varchar(255),
OUT fact int
)
BEGIN
declare flag int;
declare i int;
set flag = 1;
set i = 2;
set str = "1";
While i < num
do
if(num mod i = 0) then
set flag = 0;
set str = concat(str,", ",i);
end if;
Set i = i+1;
End while;
set fact =1;
if(flag=1) then
while(num > 0) do
set fact = fact*num;
set num = num-1;
end while;
select fact;
else
select str;
end if;
END //
delimiter ;
call getFactorial(5,@str,@fact);
delimiter //
CREATE PROCEDURE checkPalindrome(
IN num INT,
OUT str varchar(255)
)
BEGIN
declare temp int;
declare rev int;
set rev = 0;
set temp = num;
while(temp > 0) do
set rev = rev * 10 + (temp mod 10);
set temp = temp/10;
end while;
if rev=num then
set str ="YES";
else
set str = "NO";
end if;
END //
delimiter ;
call checkPalindrome(141,@result);
select result; |
Beta Was this translation helpful? Give feedback.
-
1. DELIMITER //
CREATE Procedure isPrime(IN num INT)
BEGIN
DECLARE flag int;
DECLARE i int;
DECLARE divisors VARCHAR(20);
DECLARE fact int;
SET flag = 0;
SET i = 2;
SET divisors = "1";
SET fact = 1;
WHILE(i<num) DO
IF num % i = 0 THEN
SET flag = 1;
SET divisors = CONCAT(divisors,", ",i);
END IF;
SET i = i+1;
END WHILE;
SET i =2;
IF(flag = 0) THEN
SELECT divisors;
ELSE
WHILE(i = num) DO
SET fact = fact*i;
SET i = i+1;
END WHILE;
SELECT fact;
END IF;
END//
DELIMITER;
--DROP PROCEDURE `isPrime`;
CALL isPrime('5');
2. DELIMITER //
CREATE Procedure palindrome(IN num int, OUT ans VARCHAR(4))
BEGIN
DECLARE temp INT;
DECLARE reverse INT;
DECLARE duplicate INT;
SET temp = 0;
SET reverse = 0;
SET duplicate = num;
WHILE (num > 0)
DO
SET temp = num % 10;
SET reverse = (reverse*10)+temp;
SET num = num/10;
END WHILE;
IF duplicate = reverse THEN
SET ans = 'YES';
ELSE
SET ans = 'NO';
END IF;
END//
DELIMITER;
CALL palindrome(415,@ans);
SELECT @ans; |
Beta Was this translation helpful? Give feedback.
-
1--
DELIMITER //
CREATE PROCEDURE Prime(IN n INT)
BEGIN
DECLARE i INT;
DECLARE resPrime INT;
DECLARE res1 INT;
DECLARE res2 VARCHAR(255);
SET i = 2;
SET resPrime = 1;
WHILE i < n DO
IF (n % i = 0)
THEN
SET resPrime = 0;
END IF;
SET i = i+1;
END WHILE;
IF resPrime = 1
THEN
SET res1=1;
SET i = 1;
WHILE i <= n
DO
SET res1 = res1*i;
SET i = i+1;
END WHILE;
ELSE
SET res2 = "";
SET i = 1;
WHILE i <= n
DO
IF (n % i = 0)
THEN
SET res2 = CONCAT(res2, i, ", ");
END IF;
SET i = i+1;
END WHILE;
END IF;
IF resPrime = 1 THEN
SELECT res1;
ELSE
SELECT res2;
END IF;
END //
DELIMITER ;
CALL Prime(5);
2--
DELIMITER //
CREATE PROCEDURE isPalindrom(
IN n int
)
BEGIN
declare k int;
declare rem int default 0;
declare rev int default 0;
declare ans varchar(5) default "";
set k=n;
while k>0 do
set rem = k mod 10;
set k = k/10;
set rev = rev*10 + rem;
end while;
if rev=n then
set ans="Yes";
else
set ans="No";
end if;
SELECT ans;
END //
DELIMITER ;
call isPalindrom(989);
|
Beta Was this translation helpful? Give feedback.
-
|
DELIMITER// while i<num DELIMITER// |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
--Q1
DELIMITER //
CREATE PROCEDURE getFactOfPrime(
IN number INT
)
BEGIN
DECLARE x INT;
DECLARE fact INT;
DECLARE str VARCHAR(225);
SET x = 1;
SET fact = 1;
SET str = "1, ";
WHILE x<number-1
DO
SET x = x+1;
SET fact = fact*x;
IF(number mod x = 0)
THEN
SET fact = 0;
SET str = CONCAT(str,x,", ");
END IF;
END WHILE;
SET fact = fact*number;
SET str = CONCAT(str,number);
IF(fact=0)
THEN
SELECT str;
ELSE
SELECT fact;
END IF;
END //
DELIMITER ;
CALL getFactOfPrime(5);
--Q2
DELIMITER //
CREATE PROCEDURE isPalindrome(
IN number INT,
OUT str VARCHAR(4)
)
BEGIN
DECLARE digit INT;
DECLARE reverse INT;
DECLARE copy INT;
SET copy = number;
SET digit = 0;
SET reverse = 0;
WHILE(number>0)
DO
SET digit = number mod 10;
SET reverse = reverse*10+digit;
SET number = number/10;
END WHILE;
IF reverse = copy
THEN
SET str = "YES";
ELSE
SET str = "NO";
END IF;
END//
DELIMITER ;
CALL isPalindrome(12321,@ans);
SELECT @ans;
|
Beta Was this translation helpful? Give feedback.
-
--Q1 Prime
DELIMITER //
CREATE PROCEDURE prime(IN n INT) BEGIN
DECLARE i,flag INT;
DECLARE str VARCHAR(255);
set str = '1,';
SET i = 2,
flag = 1;
while i <= n do
SET flag =flag*i;
if(n %i = 0) then
SET flag =0;
SET str= CONCAT(str,i,',');
END IF;
SET i = i + 1;
END WHILE;
if (flag >1) THEN
SELECT flag*n as factorial;
else
SELECT str as divisors;
END IF;
END //
DELIMITER;
call prime(4);
--Q2 palindrome
DELIMITER //
CREATE PROCEDURE palindrome(IN n INT, INOUT res VARCHAR(10)) BEGIN
DECLARE x,
r,
t INT;
SET x = n;
SET t = 0;
while x > 0 do
SET r = x %10;
SET t =(t * 10) + r;
SET x = x div 10;
end while;
IF (t = n) THEN
SET res = 'YES';
ELSE
SET res = 'NO';
END IF;
END //
DELIMITER;
call palindrome(454, @res);
select @res; |
Beta Was this translation helpful? Give feedback.
-
--1.
DELIMITER //
CREATE PROCEDURE getFactOfPrime(
IN number INT
)
BEGIN
DECLARE x INT;
DECLARE fact INT;
DECLARE str VARCHAR(225);
SET x = 1;
SET fact = 1;
SET str = "1, ";
WHILE x<number-1
DO
SET x = x+1;
SET fact = fact*x;
IF(number mod x = 0)
THEN
SET fact = 0;
SET str = CONCAT(str,x,", ");
END IF;
END WHILE;
SET fact = fact*number;
SET str = CONCAT(str,number);
IF(fact=0)
THEN
SELECT str;
ELSE
SELECT fact;
END IF;
END //
DELIMITER ;
CALL getFactOfPrime(7);
--2.
DELIMITER //
CREATE PROCEDURE palindrome(IN n INT, INOUT res VARCHAR(10)) BEGIN
DECLARE x,
r,
t INT;
SET x = n;
SET t = 0;
while x > 0 do
SET r = x %10;
SET t =(t * 10) + r;
SET x = x div 10;
end while;
IF (t = n) THEN
SET res = 'YES';
ELSE
SET res = 'NO';
END IF;
END //
DELIMITER;
call palindrome(12321, @res);
select @res; |
Beta Was this translation helpful? Give feedback.
-
--1. Write a stored procedure that takes an INT as input and returns the factorial of the number, if the number is prime. Else, it returns a comma-separated string of the divisors of the number.
-- Example:
-- Input = 5, Output = 120
-- Input = 4, Output = "1, 2, 4, "
DELIMITER //
create PROCEDURE getFactorial(In number int)
BEGIN
declare x int;
declare y int;
DECLARE str VARCHAR(225);
SET x = 1;
SET y = 1;
SET str = "1, ";
WHILE x < number -1
DO
SET x = x + 1;
SET y = y * x;
IF(number mod x = 0) THEN
SET y = 0;
SET str = CONCAT(str, x, ", ");
END IF;END WHILE;SET y = y*number;SET str = CONCAT(str, number);IF(y = 0) THEN
SELECT str;
ELSE
SELECT y;
END IF;
END //
DELIMITER;
CALL getFactorial(5);
CALL getFactorial(8);
--2. Write a stored procedure that takes an INT as input and returns "YES" if the number is pallindrome or "NO" if the number is not pallindrome.
-- Example:
-- Input = 141, Output = "YES"
-- Input = 123, Output = "NO"
DELIMITER //
drop PROCEDURE palindrome;
CREATE PROCEDURE palindrome(in number int,out isPalindrome varchar(100))
BEGIN
DECLARE digits INT;
DECLARE reverse INT;
DECLARE copy INT;
SET copy = number;
SET digits = 0;
SET reverse = 0;
WHILE(number > 0)
DO
SET digits = number mod 10;
SET reverse = reverse * 10 + digits;
SET number = number / 10;
END WHILE;
IF reverse = copy THEN
SET isPalindrome = "Yes";
ELSE
SET isPalindrome = "No";
END IF;
END //
DELIMITER ;
call palindrome(1221,@isPalindrome);
SELECT @isPalindrome; |
Beta Was this translation helpful? Give feedback.
-
1. Write a stored procedure that takes an INT as input and returns the factorial of the number, if the number is prime. Else, it returns a comma-separated string of the divisors of the number.Solution 2. Write a stored procedure that takes an INT as input and returns "YES" if the number is pallindrome or "NO" if the number is not pallindrome.Solution |
Beta Was this translation helpful? Give feedback.
-
|
1.Write a stored procedure that takes an INT as input and returns the factorial of the number, if the number is prime. Else, it returns a comma-separated string of the divisors of the number. Input = 5, Output = 120 2.Write a stored procedure that takes an INT as input and returns "YES" if the number is pallindrome or "NO" if the number is not pallindrome. Input = 141, Output = "YES" |
Beta Was this translation helpful? Give feedback.
-
-- Discussion Forum 11 Part 1
delimiter $$
create function factorial (
n int
)
returns int
deterministic
begin
declare ans int default 1;
loop_label : loop
if n = 1 then
leave loop_label;
end if;
set ans = ans * n;
set n = n-1;
end loop;
return ans;
end $$
delimiter ;
drop procedure factors;
delimiter $$
create procedure factors(
in n int,
out ans varchar(100)
)
begin
declare i int default 2;
declare factors varchar(100) default '1, ';
declare prime varchar(10) default 'true';
loop_label: loop
if i > ((n/2) + 1) then
leave loop_label;
end if;
if mod(n, i) = 0 then
set prime = 'false';
select concat(factors, i, ', ') into factors;
end if;
set i = i+1;
end loop;
if prime = 'true' then
set ans = factorial(n);
else
set factors = concat(factors, n);
select factors into ans;
end if;
end $$
delimiter ;
call factors(5, @ans);
select @ans;
-- Discussion Forum 11 Part 2
drop function isPalindrome;
delimiter $$
create function isPalindrome(
n int
)
returns varchar(50)
deterministic
begin
declare ans varchar(50) default '';
declare backup int default n;
loop_label: loop
if (n = 0) then
leave loop_label;
end if;
set ans = (ans*10) + mod(n, 10);
set n = n / 10;
end loop;
if ans = backup then
return 'YES';
else
return 'NO';
end if;
end $$
delimiter ;
select isPalindrome(1001);
|
Beta Was this translation helpful? Give feedback.
-
|
/* 1 Write a stored procedure that takes an INT as input and returns the factorial of the number, if the number is prime. Else, it returns a comma-separated string of the divisors of the number. Input = 5, Output = 120 DELIMITER // END; CALL num_fact(7, @fact_op); /* Write a stored procedure that takes an INT as input and returns "YES" if the number is pallindrome or "NO" if the number is not pallindrome. Input = 141, Output = "YES" DELIMITER // delimiter ; call num_palindrome(2332,@pal_out); |
Beta Was this translation helpful? Give feedback.
-
|
-- Q1 /* creating stored function to check whether a number is Prime*/ drop function fact; /* creating a function to calculate factorial of a number */ end $$ /* stored procedure */ end$$ /* Stored Procedure to Check if Number is Prime and Calculate its Factorial */ END$$ -- Q2 drop procedure palindrome; end$$ |
Beta Was this translation helpful? Give feedback.
-
|
-- 1. Write a stored procedure that takes an INT as input and returns the factorial of the number, if the number is prime. Else, it returns a comma-separated string of the divisors of the number. -- Input = 5, Output = 120 DELIMITER $$ END $$ CALL getFactPrime(4, @output); -- 2. Write a stored procedure that takes an INT as input and returns "YES" if the number is pallindrome or "NO" if the number is not pallindrome. -- Input = 141, Output = "YES" DELIMITER $$ END $$ |
Beta Was this translation helpful? Give feedback.
-
|
#1 END DELIMITER ; END DELIMITER ; |
Beta Was this translation helpful? Give feedback.
-
|
--1 CALL getFactOfPrime(5); --2 CREATE PROCEDURE isPalindrome( END// DELIMITER ; |
Beta Was this translation helpful? Give feedback.
-
DELIMITER {{
DELIMITER ₹₹ |
Beta Was this translation helpful? Give feedback.
-
|
-- 1 Write a stored procedure that takes an INT as input and returns the factorial of the number, if the number is prime. Else, it returns a comma-separated string of the divisors of the number. -- SELECT fact AS factorial, prime_factors AS primeFactors; DELIMITER ; -- 2 Write a stored procedure that takes an INT as input and returns "YES" if the number is pallindrome or "NO" if the number is not pallindrome. -- Input = 141, Output = "YES" |
Beta Was this translation helpful? Give feedback.
-
-- Input = 5, Output = 120 CREATE Procedure Fact(IN num INT) END// DELIMITER; CALL Fact('7');
Input = 141, Output = "YES" CREATE PROCEDURE palindrome(in number int,out isPalindrome varchar(100)) DELIMITER ; call palindrome(14322341,@isPalindrome); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Conditional and Looping Statements in MySQL
Write a stored procedure that takes an
INTas input and returns the factorial of the number, if the number is prime. Else, it returns a comma-separated string of the divisors of the number.Example:
5, Output =1204, Output ="1, 2, 4, "Write a stored procedure that takes an
INTas input and returns "YES" if the number is pallindrome or "NO" if the number is not pallindrome.Example:
141, Output ="YES"123, Output ="NO"Beta Was this translation helpful? Give feedback.
All reactions