[Tutor] SQL Server Script

Dennis Lee Bieber wlfraed at ix.netcom.com
Tue Apr 18 09:35:44 EDT 2023


On Mon, 17 Apr 2023 16:18:07 +0000 (UTC), Dylan Armstrong via Tutor
<tutor at python.org> declaimed the following:


>Hello,
>I'm trying to create a python script that exports the results of a query from sql into an excel file. I got the original version of the code to work but I want to add python variables into my sql code because of the weird variable format differences between oracle and sql variables. I heard that you can insert python variables into the code by placing a ":" before the variable, declaring the variable after the sql query is defined, and having a curser execute the query with the variables as parameters but I'm not sure how to do that last step. I'm also not sure how to give a specific file path destination for my newly created excel file. I'm using oracledb and pandas. my python version is 3.10.11. Sensitive information has been replaced by generic variables.

{Somehow your posting client doesn't send "wrapped" text, but single long
lines per paragraph -- makes it hard to do decent quoting}

	First a generic comment. Your message subject reads "SQL Server
Script", SQL Server is the formal name for Microsoft's RDBM -- yet the body
of your message references Oracle, a completely different RDBM provider.
(The original M$ SQL Server was based upon Sybase)

	The rest of the matter depends upon the exact nature of the Python
DB-API adapter being used. You need to read (and understand) the base
DB-API documentation, and then the specifics for the adapter.

https://peps.python.org/pep-0249/ (in particular, .execute() under Cursor
methods, and the paramstyle stuff)
https://python-oracledb.readthedocs.io/en/latest/user_guide/bind.html



More information about the Tutor mailing list