본문 바로가기
통계프로그램 비교 시리즈/오라클함수 비교(R & Python)

CURRENT_DATE(SYSDATE) 오라클 함수 [Oracle, Pandas, R Prog, Dplyr, Sqldf, Pandasql, Data.Table, DuckDB]

by 기서무나구물 2021. 11. 22.

포스팅 목차

    * 파이썬 & R 패키지 호출 및 예제 데이터 생성 링크


    [ CURRENT_DATE / SYSDATE Oracle Function ]

     


    CURRENT_DATE 함수는 현재 세션의 날짜 정보를 Date 데이터 형으로 반환한다.

     

     


    1. Oracle(오라클)

     

    CURRENT_DATE

    현재 시간을 반환한다.

     

    Oracle Programming
    SELECT SESSIONTIMEZONE, CURRENT_DATE 
    FROM   DUAL;

     

    Results
    SESSIONTIMEZONE	CURRENT_DATE
    ------------------------------
    US/Pacific	06-JAN-24

     


    SYSDATE

    Oracle Programming
    SELECT SYSDATE 
    FROM   DUAL;

     

    Results
    SYSDATE
    ------------
    06-JAN-24

     


    2. Python Pandas(파이썬)

     

    datetime.datetime.utcnow()

    Python Programming
    import datetime
    import dateutil
    
    # Get the current date
    now = datetime.datetime.utcnow()
    now

     

    Results
    datetime.datetime(2020, 12, 27, 15, 47, 12, 977360)

     


    date()

    Python Programming
    import datetime
    import dateutil
    
    # Get the current date
    now = datetime.datetime.utcnow()
    now = now.date()
    now

     

    Results
    datetime.date(2020, 12, 27)

     


    pd.Timestamp.now()

    Python Programming
    pd.Timestamp.now()

     

    Results
    Timestamp('2020-12-28 00:47:18.093358')

     

     


    3. R Programming (R Package)

     

    Sys.Date()

    R Programming
    %%R
    
    Sys.Date()

     

    Results
    [1] "2020-12-28"

     

     


    4. R Dplyr Package

     

    Sys.Date()

    R Programming
    %%R
    
    emp %>%
      dplyr::mutate(todate := Sys.Date()) %>%
      head()

     

    Results
    # A tibble: 6 x 9
      empno ename  job        mgr hiredate     sal  comm deptno todate    
      <dbl> <chr>  <chr>    <dbl> <date>     <dbl> <dbl>  <dbl> <date>    
    1  7369 SMITH  CLERK     7902 1980-12-17   800    NA     20 2020-12-28
    2  7499 ALLEN  SALESMAN  7698 1981-02-20  1600   300     30 2020-12-28
    3  7521 WARD   SALESMAN  7698 1981-02-22  1250   500     30 2020-12-28
    4  7566 JONES  MANAGER   7839 1981-04-02  2975    NA     20 2020-12-28
    5  7654 MARTIN SALESMAN  7698 1981-09-28  1250  1400     30 2020-12-28
    6  7698 BLAKE  MANAGER   7839 1981-03-01  2850    NA     30 2020-12-28

     

     


    5. R sqldf Package

     

    'now'

    R Programming
    %%R
    
    sqldf(" select strftime('%d-%m-%Y', 'now') now_date  ")

     

    Results
        now_date
    1 27-12-2020

     


    Sys.Date()

    R Programming
    %%R
    
    gsubfn::fn$sqldf("select `Sys.Date()` now_date ")

     

    Results
      now_date
    1    18624

     

     


    6. Python pandasql Package

     

    'now'

    Python Programming
    ps.sqldf(" select date('now')      현재날짜2,  \
                      datetime('now')  현재날짜3")

     

    Results
    	현재날짜2	현재날짜3
    0	2020-12-27	2020-12-27 15:47:50

     

     

     


    7. R data.table Package

     

    Sys.Date()

    R Programming
    %%R
    
    DT          <- data.table(emp)
    dept_DT     <- data.table(dept)
    
    DT[, todate := Sys.Date()][1:5, ]

     

    Results
       empno  ename      job  mgr   hiredate  sal comm deptno     todate
    1:  7369  SMITH    CLERK 7902 1980-12-17  800   NA     20 2020-12-28
    2:  7499  ALLEN SALESMAN 7698 1981-02-20 1600  300     30 2020-12-28
    3:  7521   WARD SALESMAN 7698 1981-02-22 1250  500     30 2020-12-28
    4:  7566  JONES  MANAGER 7839 1981-04-02 2975   NA     20 2020-12-28
    5:  7654 MARTIN SALESMAN 7698 1981-09-28 1250 1400     30 2020-12-28

     


    8. Python DuckDB의 SQL

     

    Python Programming
    %%sql
      SELECT CURRENT_DATE,
             today()          -- start of current transaction

     

    Python Programming
    duckdb.sql("   SELECT CURRENT_DATE, today() ").df()

     

     

    Results
      CURRENT_DATE    today()
    0   2023-08-15 2023-08-15

     

     

     

     


    Alarm clock friends situation with hand (https://unsplash.com/photos/UAvYasdkzq8)

     

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

    [Oracle, Pandas, R Prog, Dplyr, Sqldf, Pandasql, Data.Table] 오라클 함수와 R & Python 비교 사전 목록 링크

     

    오라클 SQL 함수(Oracle SQL Function) 목록 리스트 링크

     

    [SQL, Pandas, R Prog, Dplyr, SQLDF, PANDASQL, DATA.TABLE] SQL EMP 예제로 만나는 테이블 데이터 처리 방법 리스트 링크 링크
    반응형

    댓글