Django connects Oracle and runs PLSQL statements
The code is as follows:
def exec_db():
sql = """
DECLARE
v_money BINARY_INTEGER := 10;
BEGIN
dbms_output.put_line('Hello World');
UPDATE TEST1 SET USER_SALERY=USER_SALERY+v_money;
COMMIT;
END; """
# sql ='DECLARE v_money BINARY_INTEGER := 10; BEGIN UPDATE TEST1 SET USER_SALERY=USER_SALERY+v_money; COMMIT; END;'
db_conn = connections['accounting']
cursor = None
try:
cursor = db_conn.cursor()
cursor.execute(sql)
db_conn.commit()
except:
logger.error(traceback.format_exc())
finally:
if cursor:
cursor.close()
db_conn.close()
This SQL has no problem in the database connection tool, but the following error is reported in the code:
django.db.utils.DatabaseError: ORA-06550: line 8, column 7:
PLS-00103: Encountered the symbol “end-of-file” when expecting one of the following: ;
The symbol “;” was substituted for “end-of-file” to continue.
There are problems in writing SQL as multiple lines and single line.
Finally found the last; After that, add a space as the end. It’s going to work.
There’s no problem with one or more lines.
It’s very weird. Record it.
Similar Posts:
- [Solved] SQL Server Error: Cannot drop database XXX because it is currently in use
- [Solved] Djiango Create Migrations Error: query = query.decode(errors=’replace’) AttributeError: ‘str’ object has no attribute ‘decode’
- Oracle Script: How to Solve ‘unusable state index(ORA-01502)’
- Solve Python MySQL insert int data error: typeerror% d format: a number is required, not str
- [Solved] Record an error of expdp export ora-01555 caused by lob damage
- HttpURLConnection Cannot write output after reading input.
- Python2.7 Error: command not found: django-admin.py [How to Solve]
- Server returned HTTP response code: 500 for URL xxxxxxxxxxxxx
- Oracle error:ORA-01704: string literal too long
- Django auth.User.groups: (fields.E304) Reverse accessor for User.groups clashes with reverse