How to get sysdate value from oracle DB in django -
how sysdate value oracle db using django? tried adding dual class in model below:
class dual(models.model): dummy = models.charfield(max_length=1, null=true, blank=true) sysdate = models.datefield(blank=true, null=true) class meta: managed = false db_table = 'dual'
tried accessing sysdate:
sysdate = dual.objects.only('sysdate')
but result in below error:
databaseerror: ora-00904: "dual"."sysdate": invalid identifier
am doing wrong? please me here. in advance
you can retrieve rows select statement cursor iterator. know sysdate query return 1 row, can use fetchone() method.
views.py
from django.db import connection def get_sysdate(request): cursor = connection.cursor() sql = cursor.execute("select to_char(sysdate,'dd.mm.yyyy hh24:mi:ss') dual") result = cursor.fetchone() return render(request, 'sysdate.html', { 'result' : result, })
sysdate.html
{{ result }}
you can find related information below link. cx_oracle - fetch
Comments
Post a Comment