Python+cx_Oracle安装及一个简单示例(归档下热备数据文件)
系统环境:[root@nich4 cx_Oracle-py]# uname -aLinux nich4 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:54 EDT 2009 i686 i686 i38
系统环境:
[root@nich4 cx_Oracle-py]# uname -a
Linux nich4 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:54 EDT 2009 i686 i686 i386 GNU/Linux
python版本:
[root@nich4 cx_Oracle-py]# python -V
Python 2.4.3
oracle版本:
oracle database 10.2.0.5 x86
cx_Oracle简介:
cx_Oracle 是一个 Python 扩展模块,通过使用所有数据库访问模块通用的数据库 API 来实现 Oracle 数据库的查询和更新。为使用一些专为 Oracle 设计的特性,还加入了多个通用数据库 API 的扩展。
cx_Oracle 的开发历时十多年,涵盖了大多数需要在 Python 中访问 Oracle 的客户的需求。2008 年 12 月,,一个新的主要版本解决了早期版本的众多限制,并增添了对 Python 3.0 和 Oracle 新推出的一些特性的支持。
cx_Oracle官方及下载:
下载与python版本对应的cx_Oracle版本,一般选择非UNICODE版本就行了.
我选择的是CentOS 5 i386 RPM (Oracle 10g, Python 2.4)
下载之后rpm -ivh 安装.
修改oracle环境变量,加入:
export LD_LIBRARY_PATH=/opt/oracle/10g\:/opt/oracle/10g/network/lib
连接数据库示例:
以下是一个在归档数据库下热备份数据文件的脚本.
#!/bin/env python
# -*- coding: UTF-8 -*-
# Modified: 20101012-23:25:43 by nich4@msn.com
# Filename: hotbak.py
#
import subprocess
import cx_Oracle
import os
db_username = 'sys'
db_passwd = 'oracle123'
db_sid = 'sol10g'
bak_dir = '/u01/app/oracle/oradata/bak/sol10g/'
db = cx_Oracle.connect(db_username,db_passwd,db_sid,cx_Oracle.SYSDBA)
print "连接数据库成功!"
curs = db.cursor()
sql = r'''select 'cp '||name||' %s' from v$datafile''' % bak_dir
res = []
for rs in curs.execute(sql):
res.append(rs[0])
curs.execute('alter database begin backup')
print "开始备份数据文件..."
for i in res:
fname = i.split()[1].split('/')[-1].strip()
print "正在备份%s 到 %s ..." % (fname,bak_dir)
subprocess.call(i,shell=True)
print "数据文件%s 备份完成!" % fname
curs.execute('alter database end backup')
db.close()
print "备份完成!"
注: 该脚本在solaris-10+oracle-10gR2下测试. 这个脚本没有使用python的shutil模块来执行文件的拷贝.仅为演示用.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to download DeepSeek Xiaomi? Search for "DeepSeek" in the Xiaomi App Store. If it is not found, continue to step 2. Identify your needs (search files, data analysis), and find the corresponding tools (such as file managers, data analysis software) that include DeepSeek functions.

The key to using DeepSeek effectively is to ask questions clearly: express the questions directly and specifically. Provide specific details and background information. For complex inquiries, multiple angles and refute opinions are included. Focus on specific aspects, such as performance bottlenecks in code. Keep a critical thinking about the answers you get and make judgments based on your expertise.

Just use the search function that comes with DeepSeek. Its powerful semantic analysis algorithm can accurately understand the search intention and provide relevant information. However, for searches that are unpopular, latest information or problems that need to be considered, it is necessary to adjust keywords or use more specific descriptions, combine them with other real-time information sources, and understand that DeepSeek is just a tool that requires active, clear and refined search strategies.

DeepSeek is not a programming language, but a deep search concept. Implementing DeepSeek requires selection based on existing languages. For different application scenarios, it is necessary to choose the appropriate language and algorithms, and combine machine learning technology. Code quality, maintainability, and testing are crucial. Only by choosing the right programming language, algorithms and tools according to your needs and writing high-quality code can DeepSeek be successfully implemented.

Question: Is DeepSeek available for accounting? Answer: No, it is a data mining and analysis tool that can be used to analyze financial data, but it does not have the accounting record and report generation functions of accounting software. Using DeepSeek to analyze financial data requires writing code to process data with knowledge of data structures, algorithms, and DeepSeek APIs to consider potential problems (e.g. programming knowledge, learning curves, data quality)

Python is an ideal programming introduction language for beginners through its ease of learning and powerful features. Its basics include: Variables: used to store data (numbers, strings, lists, etc.). Data type: Defines the type of data in the variable (integer, floating point, etc.). Operators: used for mathematical operations and comparisons. Control flow: Control the flow of code execution (conditional statements, loops).

Pythonempowersbeginnersinproblem-solving.Itsuser-friendlysyntax,extensivelibrary,andfeaturessuchasvariables,conditionalstatements,andloopsenableefficientcodedevelopment.Frommanagingdatatocontrollingprogramflowandperformingrepetitivetasks,Pythonprovid

This time, the Redstone token $RED will be launched on Binance Launchpool on Binance TGE! This is also the first time Binance has launched a pre-market trading limit mechanism! The first day limit is 200%, and the ban will be lifted after 3 days to avoid "the peak will be achieved when the market opens"! Launchpool mechanism introduces the BinanceLaunchpool participating in Redstone that needs to pledge designated tokens (BNB, USDC, FDUSD) activity period is 48 hours: 08:00 UTC on February 26, 2025 to 08:00 UTC on February 28, 2025 ending this pre-market daily limit rule: 18:00 on February 28, 2025
