61

What is MySQL's alternative to Oracle's NEXT_DAY function?

 3 years ago
source link: https://www.codesd.com/item/what-is-mysql-s-alternative-to-oracle-s-next-day-function.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

What is MySQL's alternative to Oracle's NEXT_DAY function?

advertisements

NEXT_DAY("01-SEP-95","FRIDAY") returns what is the date on next Friday, but in MySQL this function does not seem to be appear. What is the alternative?


In MySQL, you can create user defined function

DELIMITER //

  CREATE FUNCTION next_day(start_date DATETIME, weekday CHAR(20))
    RETURNS DATETIME
  BEGIN
    DECLARE start DATETIME;
    DECLARE i INT;

    // Select the next date
    SET start = ADDDATE(start_date, 1);
    SET i = 1;

    days: LOOP
          -- Compare the day names
        IF SUBSTR(DAYNAME(start), 1, 3) = SUBSTR(weekday, 1, 3) THEN
       LEAVE days;
        END IF;

        // Select the next date
        SET start = ADDDATE(start, 1);
        SET i = i + 1;

        -- Not valid weekday specified
        IF i > 7 THEN
       SET start = NULL;
       LEAVE days;
    END IF;

     END LOOP days;

     RETURN start;
  END;
  //

   DELIMITER ;

and call it

SELECT NEXT_DAY("1995-09-01","FRIDAY")

Source : http://www.sqlines.com/mysql/how-to/next_day

Related Articles

MySQL Data Field to Oracle

I am using sqlldr to load mysql data in an Oracle database... My problem is I have a DATE column in MySQL that Oracle doesn't like... Here is the structure of my column in mysql: Extra Type Field Default Null Key date dateToSend 0000-00-00 NO here is

The query works in MySQL and not in Oracle

The following SQL statement works in MySQL but not with Oracle: SELECT *, MAX(COLUMN_A) FROM table_xyz WHERE COLUMN_A <= 100 GROUP BY COLUMN_A Oracle complaint: "FROM keyword not found where expected" actually the statement was incorrect, we

What is a faster alternative to Python http.server (or SimpleHTTPServer)?

Python's http.server (or SimpleHTTPServer for Python 2) is a great way of serve the contents of the current directory from the command line: python -m http.server However, as far as web servers go, it's very slooooow... It behaves as though it's sing

What is a good alternative for putting passwords in the configuration files?

I have a bunch of .Net config files which contain passwords for Windows service accounts and/or SQL server logins. I would like to get them out of the config files and keep them more secure. What is a good alternative to having the passwords in the c

What are the interesting alternatives to line / line statements if / else?

More and more I realize my code is getting filled with if/else statements. Eventually, I started to write one-liners (x = 'this' if y > 0 else 'that') and, in some cases, if a test were often true, I assumed it was from the beginning and only changed

What is a good alternative for SourceSafe on a USB drive?

I like to keep my source files on a USB drive for the portability. To date I have been using Visual SourceSafe for this purpose. What is a good alternative to VSS that fulfils these criteria: Entire database can be held on a USB "pen" drive Code

What should be the alternative for lead and lag for SQL Server 2000 to 2008

What could be the alternative for lead and lag for SQL Server 2000 to 2008? I am trying to get previous and next invoice number to given invoice number, i.e 5 SqlDataAdapter invoiceAdptr = new SqlDataAdapter(@" select t.prev_invNo, t.InvNo, t.next_in

What type of Java is the Oracle type of record type configured for?

I have a Grails application that is required to call an Oracle database package function. The return value of the function is a RECORD Oracle data type. What Java Oracle datatype does RECORD map to? I have found this page, however, I am either blind

What is the multiplatform alternative to Python's subprocess.getstatusoutput (older commands.setstatusoutput ()?

The code below is outdated in Python 3.0 by being replaced by subprocess.getstatusoutput(). import commands (ret, out) = commands.getstatusoutput('some command') print ret print out The real question is what's the multiplatform alternative to this co

What is the best alternative to Flash for the live video of Red5

With Firefox's announcement that they will stop Flash in their browsers, Facebook calling for it's death, and others to potentially follow at some point, what's the best alternative for streaming live video in a browser using Red5? We use Flash Build

What is a good alternative to Toad for Mac OSX?

I am looking for an alternative to Oracle's Toad for Mac OS X. I currently use this for work on a Windows machine, but I would like to use it natively in OSX. I am looking for something that specifically handles XMLTYPEs well.No love for SQL Develope

What are the faster alternatives to Java2d?

I'm looking to do some physics simulations and I need fast rendering in Java. I've run into performance issues with Java2d in the past, so what are the fast alternatives? Is JOGL significantly faster than Java2d?My experience with Java2D is that it c

Alternative to the fscanf () / vscanf () function family to use another validation key or how to create a custom language layout?

I am rather knew in C. And the only way I know for setting a variable from stdin is by using thefscanf()/vscanf()functions family. DOS operating systems are seeing a resurgence in the embedded market. The device which I am using is programmatically c

Quick alternation to execute a numpy function on all Pandas DataFrame rows

I have a Pandas data frame created the following way: import pandas as pd def create(n): df = pd.DataFrame({ 'gene':["foo", "bar", "qux", "woz"], 'cell1':[433.96,735.62,483.42,10.33], 'cell2':[94.93,2214.38,97.93,12

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK