DEV Community

Abdul Haseeb
Abdul Haseeb

Posted on

Sem V MYSQL Practical 3

  1. Display the string ‘bbbStructure Query Language’’ after trimming from left.
   SELECT LTRIM('   Structure Query Language');
Enter fullscreen mode Exit fullscreen mode
  1. Display the string ‘bbStructure Query Languagebbb’ after trimming from right.
   SELECT RTRIM('Structure Query Language   ');
Enter fullscreen mode Exit fullscreen mode
  1. Display the length of the string ‘bbString Functionsbbb’ after removing blank spaces from both sides.
   SELECT LENGTH(TRIM('   String Functions   '));
Enter fullscreen mode Exit fullscreen mode
  1. Display the reverse of your name.
   SELECT REVERSE('YourName'); -- Replace 'YourName' with your actual name.
Enter fullscreen mode Exit fullscreen mode
  1. Display the string after joining the 3 strings ‘You are ’, ‘learning’ and ‘MYSQL’.
   SELECT CONCAT('You are ', 'learning ', 'MYSQL');
Enter fullscreen mode Exit fullscreen mode
  1. Display the left most 9 characters of the string ‘Structure Query Language’.
   SELECT LEFT('Structure Query Language', 9);
Enter fullscreen mode Exit fullscreen mode
  1. Display the right most 3 characters of the string ‘Structure Query Language’.
   SELECT RIGHT('Structure Query Language', 3);
Enter fullscreen mode Exit fullscreen mode
  1. Display 3 characters from the 6th character of the string ‘Applications’.
   SELECT SUBSTRING('Applications', 6, 3);
Enter fullscreen mode Exit fullscreen mode
  1. Display your name in capital letters and small letters using functions.
   SELECT UPPER('YourName'), LOWER('YourName'); -- Replace 'YourName' with your actual name.
Enter fullscreen mode Exit fullscreen mode
  1. Display the value 65432.49678:

    • After rounding it off to 4 decimal places, 2 decimal places.
      SELECT ROUND(65432.49678, 4), ROUND(65432.49678, 2);
    
- **After rounding it off nearest to 10, nearest to 100, nearest to 1000.**
Enter fullscreen mode Exit fullscreen mode
  ```sql
  SELECT ROUND(65432.49678, -1), ROUND(65432.49678, -2), ROUND(65432.49678, -3);
  ```
Enter fullscreen mode Exit fullscreen mode
  1. Display the square root of the following values:

    • 784
      SELECT SQRT(784);
    
- **12.8547**
Enter fullscreen mode Exit fullscreen mode
  ```sql
  SELECT SQRT(12.8547);
  ```
Enter fullscreen mode Exit fullscreen mode
  1. Display the value of 6^3 and 5^5.

    SELECT POW(6, 3), POW(5, 5);
    
  2. Display the absolute value of -7 and 13.

    SELECT ABS(-7), ABS(13);
    
  3. Display the remainder of the following divisions:

    • 78 by 5
      SELECT 78 % 5;
    
- **78 by -5**
Enter fullscreen mode Exit fullscreen mode
  ```sql
  SELECT 78 % -5;
  ```
Enter fullscreen mode Exit fullscreen mode
- **-78 by 5**
Enter fullscreen mode Exit fullscreen mode
  ```sql
  SELECT -78 % 5;
  ```
Enter fullscreen mode Exit fullscreen mode
  1. Display the day of the month, month, and year portion from the specified date:

    • ‘2024-12-25’
      SELECT DAY('2024-12-25'), MONTH('2024-12-25'), YEAR('2024-12-25');
    
- **‘2025-01-01’**
Enter fullscreen mode Exit fullscreen mode
  ```sql
  SELECT DAY('2025-01-01'), MONTH('2025-01-01'), YEAR('2025-01-01');
  ```
Enter fullscreen mode Exit fullscreen mode
  1. Display the name of the month and name of the week of the given date:

    • ‘2024-08-10’
      SELECT MONTHNAME('2024-08-10'), DAYNAME('2024-08-10');
    
- **‘2024-11-1’**
Enter fullscreen mode Exit fullscreen mode
  ```sql
  SELECT MONTHNAME('2024-11-1'), DAYNAME('2024-11-1');
  ```
Enter fullscreen mode Exit fullscreen mode
  1. Display the date portion of the given expression ‘2024-08-02 23:45:40’.

    SELECT DATE('2024-08-02 23:45:40');
    
  2. Display the time portion of the given expression ‘2024-08-02 23:45:40’.

    SELECT TIME('2024-08-02 23:45:40');
    
  3. Display today’s date.

    SELECT CURDATE();
    
  4. Display today’s date with time.

    SELECT NOW();
    

Top comments (0)