Python Forum
Check table exists in Database
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Check table exists in Database
#1
Can someone help us to work this code

import cx_Oracle class Table(object): def __init__(self, table_name, database): self.table_name = table_name self.database = database self.exists = self.table_exists() def table_exists(self): conn = get_connection() session = conn.cursor() cnt = session.execute('SELECT COUNT(*) FROM DBA_OBJECTS WHERE OBJECT_TYPE =:1 AND UPPER(OBJECT_NAME) =:2', ('TABLE', self.table_name)) return cnt session.close() conn.close() def get_connection(): db_connection = cx_Oracle.connect('XXXXXXX') return db_connection def main(): c1 = Table c1.__init__('MTL_SYSTEM_ITEMS','DEV') if __name__ == "__main__": main()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 3,864 Jul-02-2021, 02:19 PM
Last Post: xtc14
  How to check spec table in another df Mekala 0 2,253 Oct-11-2020, 02:25 PM
Last Post: Mekala
  Check if a file exists. Pedroski55 5 5,457 Sep-08-2020, 10:01 AM
Last Post: Pedroski55
  p]Why os.path.exists("abc/d") and os.path.exists("abc/D") treat same rajeev1729 1 3,150 May-27-2020, 08:34 AM
Last Post: DeaD_EyE
  Mysql CREATE TABLE IF NOT EXISTS dynamic table name nisusavi 0 3,712 Apr-29-2020, 06:45 PM
Last Post: nisusavi
  MYSQL how to assign a table for each user in my username table database? YoshikageKira 1 4,177 Dec-26-2019, 05:57 AM
Last Post: buran
  How read Table Structure from Database nnsatpute 5 5,864 Oct-25-2019, 10:08 AM
Last Post: Larz60+
  Database table structure compare(Oracle) GKT 4 5,176 Oct-16-2019, 03:16 PM
Last Post: GKT
  How to check if class instance exists in a list of class instance objects? sonicblind 23 29,862 May-27-2018, 05:44 AM
Last Post: buran
  Python code to check SQL table for current date PYTHONDUDE 3 4,419 May-16-2018, 02:27 PM
Last Post: buran

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.