0% found this document useful (0 votes)
8 views

SQL Day5

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

SQL Day5

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

--|| SQL DAY 5 ||--

###### PLSQL (PROCEDURAL LANGUAGE & STRUCTURED QUERY LANGUAGE.) : -

CREATE DEFINER=`root`@`localhost` FUNCTION `Age_calucation`(dob date) RETURNS int


READS SQL DATA
DETERMINISTIC
BEGIN
declare today date;
select current_date() into today;

RETURN year(today)-year(dob);
END

###### to run the method : -

use abc;

select demo123();

-----------------------------------------------------------------------------------
-----------------------------
CREATE DEFINER=`root`@`localhost` FUNCTION `parameter`(num int) RETURNS varchar(20)
CHARSET utf8mb4
READS SQL DATA
DETERMINISTIC
BEGIN

RETURN num;
END

select parameter(123) as msg;

-----------------------------------------------------------------------------------
-------------------------------

DETERMINISTIC : -

-- > returns same result for same input

-- > when using non deterministic for determinsitic type of function will take
unwanted execution time

NONDITERMINISTIC : -

-- > returns differenct result for same input.

-- > when using deterministic for nondeterministic methods might return wrong
results

-----------------------------------------------------------------------------------
-------------------------------

###### METHODS OF DATE : -


1) select now(); - - - > > > returns current date & time

2) select curdate(); - - - > > > returns current date

3) select dayofmonth("2012-12-23"); - - - > > > returns day of month

4) select dayofyear("2012-12-23"); - - - > > > returns day of year

5) select curtime(); - - - > > > returns current time

6) select current_timestamp(); - - - > > > returns current date


& time

7) select current_time(); - - - > > > returns current time

-----------------------------------------------------------------------------------
-------------------------------

###### STORED PROCEDURE : -

CREATE DEFINER=`root`@`localhost` PROCEDURE `abc`()


BEGIN
select * from person;
END

call abc.abc();

You might also like