linux oracle 分号引起大错误

本文介绍了一个常见的Oracle数据库错误ORA-00911:无效字符的问题及解决方案。通常此错误是因为SQL语句末尾多出了不必要的符号如分号导致,移除这些多余的符号即可成功执行SQL。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ORA-00911: invalid character。这是因为在其末尾加上了“;”的缘故,去掉“;”SQL就可以执行了

转载于:https://www.cnblogs.com/ssor/archive/2011/10/26/2225024.html

import cx_Oracle import os def execute_index_statements(sql_file_path, error_file_path, db_username, db_password, db_dsn): """ 执行SQL文件中的CREATE INDEX语句,并将错误语句保存到新文件 :param sql_file_path: 包含CREATE INDEX语句的SQL文件路径 :param error_file_path: 错误SQL语句的输出文件路径 :param db_username: 数据库用户名 :param db_password: 数据库密码 :param db_dsn: 数据库DSN连接字符串 """ # 读取SQL文件并按分号分割语句 with open(sql_file_path, 'r') as sql_file: sql_content = sql_file.read() # 分割SQL语句,保留分号以便后续处理 raw_statements = [stmt.strip() + ";" for stmt in sql_content.split(';') if stmt.strip()] # 连接到Oracle数据库 try: connection = cx_Oracle.connect(user=db_username, password=db_password, dsn=db_dsn) cursor = connection.cursor() # 创建错误文件 with open(error_file_path, 'w') as error_file: error_count = 0 for stmt in raw_statements: try: # 移除语句末尾的分号Oracle动态SQL不需要分号) executable_stmt = stmt.rstrip(';') cursor.execute(executable_stmt) print(f"成功执行: {stmt.split()[2]}") # 显示索引名 except cx_Oracle.DatabaseError as e: error_msg = f"错误语句: {stmt}\n错误信息: {e}\n{'=' * 50}\n" print(error_msg) error_file.write(stmt + "\n") error_count += 1 print(f"\n执行完成!错误语句数: {error_count}") print(f"错误语句已保存至: {os.path.abspath(error_file_path)}") except cx_Oracle.DatabaseError as e: print(f"数据库连接失败: {e}") finally: if 'cursor' in locals(): cursor.close() if 'connection' in locals(): connection.close() # 配置参数 config = { "sql_file_path": "C:\Users\Administrator\PycharmProjects\pythonProject\oracle_comments_ghana_cash.sql", # 输入SQL文件 "error_file_path": "failed_indexes.sql", # 错误SQL输出文件 "db_username": "YTF", # 替换为实际用户名 "db_password": "YTF_123456", # 替换为实际密码 "db_dsn": "oracle-1.cfjq6sky0wee.ap-south-1.rds.amazonaws.com:1521:ORCL" # 替换为实际DSN } # 执行函数 execute_index_statements(**config) 报 "sql_file_path": "C:\Users\Administrator\PycharmProjects\pythonProject\oracle_comments_ghana_cash.sql", # 输入SQL文件 ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
最新发布
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值