Python Extracts data

Source: Internet
Author: User
#-*-Coding:utf-8-*-import cx_oracle from pprint import pprint import CSV import time import re import binascii conn = Cx_oracle.connect (' system/oracle@192.168.137.2/serv ') cursor = conn.cursor () table_name= "t300" owner= "system" F = Open (table_name+ ". csv", "w") writer = Csv.writer (f, lineterminator= "\ n", Quoting=csv.) quote_nonnumeric) xsql= "SELECT column_name from Dba_tab_columns where Table_name=upper (" + "'" +table_name+ "'" + ") and
Owner=upper ("+" "" +owner+ "" + ")" + "" + "ORDER by column_id ASC" Print xSQL r = Cursor.execute (xSQL) columns=[]; For (col,) in R:print Col columns.append (col) ysql= "select Column_name,data_type from Dba_tab_columns where tabl E_name=upper ("+" "" +table_name+ "" + ") and Owner=upper (" + "" "+owner+" "+") "+" "+" ORDER by column_id ASC "d={} r = Cursor.execute (Ysql) m=0 arr1=[] for J in R: #print J if (j[1]== ' RAW '): Print j[1] Arr 1.append (m) else:pass m = m + 1 print arr1 print '------------------' EXportoraclesql= "SELECT";
    For I in range (0, len (columns)): If I!= len (columns)-1:exportoraclesql=exportoraclesql+columns[i]+ ', ' Else:exportoraclesql = Exportoraclesql + columns[i] exportoraclesql=exportoraclesql+ "+" from "+" "+owner+". +table_name Print Exportoraclesql Cursor.execute ("alter session set nls_date_format= ' Yyyy-mm-dd '") S1 = Cursor.execute (
             Exportoraclesql) for row in S1: #print type (ROW) s2=[] for I in range (0,len (row)): if (i in arr1): #print (Binascii.b2a_hex (Row[i])) S2.append (Binascii.b2a_hex (row[i))) #writer. Writero W (Binascii.b2a_hex (Row[i])) Else: #print Row[i] S2.append (row[i)) #writ
 Er.writerow (Row[i]) print s2 writer.writerow (s2) f.close () cursor.close () close__ = Conn.close ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.