2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > oracle clob 粘贴 使用Oracle SQL Developer将CLOB导出到文本文件

oracle clob 粘贴 使用Oracle SQL Developer将CLOB导出到文本文件

时间:2022-01-10 09:17:40

相关推荐

oracle clob 粘贴 使用Oracle SQL Developer将CLOB导出到文本文件

您可以使用Python脚本采取的护理出口,该CLOB的不会被截断:

from __future__ import print_function

from __future__ import division

import time

import cx_Oracle

def get_cursor():

'''

Get a cursor to the database

'''

# /questions/24149138/cx-oracle-doesnt-connect-when-using-sid-instead-of-service-name-on-connection-s

# /technetwork/articles/dsl/prez-python-queries-101587.html

ip = '' # E.g. '127.0.0.1'

port = '' # e.g. '3306'

sid = ''

dsnStr = cx_Oracle.makedsn(ip, port, sid)

username = '' # E.g. 'FRANCK'

password = '' # E.g. '123456'

db = cx_Oracle.connect(user=username, password=password, dsn=dsnStr)

cursor = db.cursor()

return cursor

def read_sql(filename):

'''

Read an SQL file and return it as a string

'''

file = open(filename, 'r')

return ' '.join(file.readlines()).replace(';', '')

def execute_sql_file(filename, cursor, verbose = False, display_query = False):

'''

Execute an SQL file and return the results

'''

sql = read_sql(filename)

if display_query: print(sql)

start = time.time()

if verbose: print('SQL query started... ', end='')

cursor.execute(sql)

if verbose:

end = time.time()

print('SQL query done. (took {0} seconds)'.format(end - start))

return cursor

def main():

'''

This is the main function

'''

# Demo:

cursor = get_cursor()

sql_filename = 'your_query.sql' # Write your query there

cursor = execute_sql_file(sql_filename, cursor, True)

result_filename = 'result.csv' # Will export your query result there

result_file = open(result_filename, 'w')

delimiter = ','

for row in cursor:

for count, column in enumerate(row):

if count > 0: result_file.write(delimiter)

result_file.write(str(column))

result_file.write('\n')

result_file.close()

if __name__ == "__main__":

main()

#cProfile.run('main()') # if you want to do some profiling

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。