doukun1450 2015-03-16 09:16
浏览 124

oracle 10g中where子句中的年份和月份

I have my date in format March 2014. How do I get month and year in number format to compare it in Oracle 10g query.

    <?php
    $date = "March 2014";
    ?>

My query that I am trying to get is

    select EMP_NAME where month = "03" and year = "2014".

Here is my table structure

    EMP_ID  |  EMP_NAME  |  C_DATE
       1    |     ABC    |  01-FEB-14
       2    |     XYZ    |  03-MAR-14 

Note: I am writing the coding in php

  • 写回答

2条回答 默认 最新

  • duanguangwang5829 2015-03-16 09:20
    关注

    You can try with TO_CHAR(date, 'MON') for the months and TO_CHAR(date, 'YYYY') for the year. The query will be

    select EMP_NAME where TO_CHAR(C_DATE, 'MON') = month and TO_CHAR(C_DATE, 'YYYY') = year
    

    And in php you'll have to manage the date to get year and month and pass them to the query

    $dt = new DateTime("March 2014");
    $month = $dt->format("m"); //03
    $year = $dt->format("Y"); //2014
    
    //Here connect to the db..
    $db->query("SELECT EMP_NAME FROM yourTable WHERE TO_CHAR(C_DATE, 'MON') = :month AND TO_CHAR(C_DATE, 'YYYY') = :year");
    $db->bindParam(":month", $month);
    $db->bindParam(":year", $month);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化