SQLAlchemy中,操作oracle資料庫date欄位
阿新 • • 發佈:2019-01-28
from sqlalchemy import Column
from sqlalchemy.dialects.oracle import DATE, NUMBER, VARCHAR
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class MidTaskCtl(Base):
'''
bs_tb_mid_task_ctrl表的ORM類
'''
__tablename__="BS_TB_MID_TASK_CTRL"
SEQNO = Column(NUMBER,primary_key=True) #NUMBER(10)
PNAME = Column(VARCHAR(10)) #VARCHAR2(10)
BILLING_CYCLE_ID = Column(NUMBER) #NUMBER(9)
TASK_NAME = Column(VARCHAR(50)) #VARCHAR2(50)
OBJECT_NAME = Column(VARCHAR(50)) #VARCHAR2(50)
ATTR1 = Column(VARCHAR(300)) #VARCHAR2(300)
ATTR2 = Column(VARCHAR(300)) #VARCHAR2(300)
ATTR3 = Column(VARCHAR(300)) #VARCHAR2(300)
CREATE_DATE = Column(DATE) #DATE
from sqlalchemy.dialects.oracle import DATE, NUMBER, VARCHAR
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class MidTaskCtl(Base):
'''
bs_tb_mid_task_ctrl表的ORM類
'''
__tablename__="BS_TB_MID_TASK_CTRL"
SEQNO = Column(NUMBER,primary_key=True) #NUMBER(10)
PNAME = Column(VARCHAR(10)) #VARCHAR2(10)
BILLING_CYCLE_ID = Column(NUMBER) #NUMBER(9)
TASK_NAME = Column(VARCHAR(50)) #VARCHAR2(50)
OBJECT_NAME = Column(VARCHAR(50)) #VARCHAR2(50)
ATTR1 = Column(VARCHAR(300)) #VARCHAR2(300)
ATTR2 = Column(VARCHAR(300)) #VARCHAR2(300)
ATTR3 = Column(VARCHAR(300)) #VARCHAR2(300)
CREATE_DATE = Column(DATE) #DATE
STATUS_DATE = Column(DATE) #DATE
'''
以上是資料庫表的定義
下面對date欄位的賦值方法如下
'''
from datetime import datetime
task.CREATE_DATE=datetime.now()
task.STATUS_DATE=datetime(2018,4,25,15,47,30)