{"id":2999,"date":"2019-11-22T21:15:25","date_gmt":"2019-11-23T04:15:25","guid":{"rendered":"https:\/\/oracletutorial.com\/?page_id=2999"},"modified":"2025-05-31T20:36:05","modified_gmt":"2025-06-01T03:36:05","slug":"python-oracle","status":"publish","type":"page","link":"https:\/\/www.oracletutorial.com\/python-oracle\/","title":{"rendered":"Python Oracle"},"content":{"rendered":"\n<p>This section shows you how to access the Oracle Database from Python using the <a href=\"https:\/\/python-oracledb.readthedocs.io\/en\/latest\/\" target=\"_blank\" rel=\"noreferrer noopener\">python-oracledb<\/a> package.<\/p>\n\n\n\n<p>The <code>python-oracledb<\/code> package is designed to conform to the Python database API 2.0 specification. It also provides you with a number of additions designed specifically for the Oracle Database.<\/p>\n\n\n\n<p>The <code>python-oracledb<\/code> works perfectly fine with Python version 3.9 to 3.13 on Oracle Database 23ai, 21, 19c, 18c, 12c, and 11gR2.<\/p>\n\n\n\n<p>We assume that you already have basic Python programming. If you don&#8217;t, we recommend the <a href=\"https:\/\/www.pythontutorial.net\/\" target=\"_blank\" rel=\"noreferrer noopener\">Python tutorial<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='setting-up-sample-tables'>Setting up sample tables <a href=\"#setting-up-sample-tables\" class=\"anchor\" id=\"setting-up-sample-tables\" title=\"Anchor for Setting up sample tables\">#<\/a><\/h2>\n\n\n\n<p>We&#8217;ll <a href=\"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-create-table\/\">create two tables<\/a> <code>billing_headers<\/code> and <code>billing_items<\/code> for the demonstration.<\/p>\n\n\n\n<p>Creating the <code>billing_headers<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> billing_headers(\n    billing_no <span class=\"hljs-built_in\">NUMBER<\/span> <span class=\"hljs-keyword\">GENERATED<\/span> <span class=\"hljs-keyword\">BY<\/span> <span class=\"hljs-keyword\">DEFAULT<\/span> <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span>,\n    billing_date <span class=\"hljs-built_in\">DATE<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    amount <span class=\"hljs-built_in\">NUMBER<\/span>(<span class=\"hljs-number\">19<\/span>,<span class=\"hljs-number\">4<\/span>) <span class=\"hljs-keyword\">DEFAULT<\/span> <span class=\"hljs-number\">0<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    customer_id <span class=\"hljs-built_in\">NUMBER<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    note <span class=\"hljs-built_in\">VARCHAR2<\/span>(<span class=\"hljs-number\">100<\/span>),\n    PRIMARY <span class=\"hljs-keyword\">KEY<\/span>(billing_no)\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Creating the <code>billing_items<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> billing_items(\n    item_no <span class=\"hljs-built_in\">NUMBER<\/span> \n        <span class=\"hljs-keyword\">GENERATED<\/span> <span class=\"hljs-keyword\">BY<\/span> <span class=\"hljs-keyword\">DEFAULT<\/span> <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> \n        <span class=\"hljs-keyword\">START<\/span> <span class=\"hljs-keyword\">WITH<\/span> <span class=\"hljs-number\">10<\/span> \n        <span class=\"hljs-keyword\">INCREMENT<\/span> <span class=\"hljs-keyword\">BY<\/span> <span class=\"hljs-number\">10<\/span>,\n    billing_no <span class=\"hljs-built_in\">NUMBER<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    product_id <span class=\"hljs-built_in\">NUMBER<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    price <span class=\"hljs-built_in\">NUMBER<\/span>(<span class=\"hljs-number\">10<\/span>,<span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">DEFAULT<\/span> <span class=\"hljs-number\">0<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    PRIMARY <span class=\"hljs-keyword\">KEY<\/span>(item_no, billing_no),\n    <span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span>(billing_no) \n        <span class=\"hljs-keyword\">REFERENCES<\/span> billing_headers(billing_no)\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='python-oracle-tutorials'>Python Oracle Tutorials <a href=\"#python-oracle-tutorials\" class=\"anchor\" id=\"python-oracle-tutorials\" title=\"Anchor for Python Oracle Tutorials\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span class=\"keyword _ngcontent-poj-89\" aria-hidden=\"false\"><a href=\"https:\/\/www.oracletutorial.com\/python-oracle\/connecting-to-oracle-database-in-python\/\">Connecting to Oracle Database in Python<\/a> &#8211; learn how to connect to Oracle from Python using stand-alone and pooled connections.<\/span><\/li>\n\n\n\n<li><a href=\"https:\/\/www.oracletutorial.com\/python-oracle\/querying-data-using-fetchone-fetchmany-and-fetchall-methods\/\">Querying data using fetchone(), fetchmany(), and fetchall() methods<\/a> &#8211; show you how to query data using various methods of the Cursor object.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.oracletutorial.com\/python-oracle\/bind-variables\/\">Using bind variables to pass data to and from Oracle Database<\/a> &#8211; learn how to use bind variables to pass data to and get data back from Oracle Database.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.oracletutorial.com\/python-oracle\/inserting-data\/\">Inserting data<\/a> &#8211; show you how to insert one or more rows into a table.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.oracletutorial.com\/python-oracle\/updating-data\/\">Updating data<\/a> &#8211; walk you through the steps of updating data in a table.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.oracletutorial.com\/python-oracle\/deleting-data-from-oracle-database-in-python\/\">Deleting data<\/a> &#8211; guide you on how to delete data from a table in a Python program.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.oracletutorial.com\/python-oracle\/managing-transaction-in-python\/\">Managing Transactions<\/a> &#8211; learn how to manage Oracle Database transactions in Python.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.oracletutorial.com\/python-oracle\/calling-a-plsql-procedure-in-python\/\">Calling PL\/SQL stored procedures in Python<\/a> &#8211; show you how to call a PL\/SQL procedure from a Python program.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.oracletutorial.com\/python-oracle\/calling-pl-sql-stored-function-in-python\/\">Calling PL\/SQL stored functions in Python<\/a> &#8211; learn how to call a stored function in Python.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"2999\"\n\t\t\t\tdata-post-url=\"https:\/\/www.oracletutorial.com\/python-oracle\/\"\n\t\t\t\tdata-post-title=\"Python Oracle\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"2999\"\n\t\t\t\tdata-post-url=\"https:\/\/www.oracletutorial.com\/python-oracle\/\"\n\t\t\t\tdata-post-title=\"Python Oracle\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This section shows you how to access the Oracle Database in a Python using the cx_Oracle module.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":15,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2999","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Oracle Tutorial<\/title>\n<meta name=\"description\" content=\"This section demonstrates how to access the Oracle Database from Python using the python-oracledb module.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.oracletutorial.com\/python-oracle\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Oracle Tutorial\" \/>\n<meta property=\"og:description\" content=\"This section demonstrates how to access the Oracle Database from Python using the python-oracledb module.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.oracletutorial.com\/python-oracle\/\" \/>\n<meta property=\"og:site_name\" content=\"Oracle Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-01T03:36:05+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/python-oracle\\\/\",\"url\":\"https:\\\/\\\/www.oracletutorial.com\\\/python-oracle\\\/\",\"name\":\"Python Oracle Tutorial\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/#website\"},\"datePublished\":\"2019-11-23T04:15:25+00:00\",\"dateModified\":\"2025-06-01T03:36:05+00:00\",\"description\":\"This section demonstrates how to access the Oracle Database from Python using the python-oracledb module.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/python-oracle\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.oracletutorial.com\\\/python-oracle\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/python-oracle\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.oracletutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Oracle\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/#website\",\"url\":\"https:\\\/\\\/www.oracletutorial.com\\\/\",\"name\":\"Oracle Tutorial\",\"description\":\"Oracle Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.oracletutorial.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Oracle Tutorial","description":"This section demonstrates how to access the Oracle Database from Python using the python-oracledb module.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.oracletutorial.com\/python-oracle\/","og_locale":"en_US","og_type":"article","og_title":"Python Oracle Tutorial","og_description":"This section demonstrates how to access the Oracle Database from Python using the python-oracledb module.","og_url":"https:\/\/www.oracletutorial.com\/python-oracle\/","og_site_name":"Oracle Tutorial","article_modified_time":"2025-06-01T03:36:05+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.oracletutorial.com\/python-oracle\/","url":"https:\/\/www.oracletutorial.com\/python-oracle\/","name":"Python Oracle Tutorial","isPartOf":{"@id":"https:\/\/www.oracletutorial.com\/#website"},"datePublished":"2019-11-23T04:15:25+00:00","dateModified":"2025-06-01T03:36:05+00:00","description":"This section demonstrates how to access the Oracle Database from Python using the python-oracledb module.","breadcrumb":{"@id":"https:\/\/www.oracletutorial.com\/python-oracle\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.oracletutorial.com\/python-oracle\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.oracletutorial.com\/python-oracle\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.oracletutorial.com\/"},{"@type":"ListItem","position":2,"name":"Python Oracle"}]},{"@type":"WebSite","@id":"https:\/\/www.oracletutorial.com\/#website","url":"https:\/\/www.oracletutorial.com\/","name":"Oracle Tutorial","description":"Oracle Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.oracletutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/pages\/2999","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/comments?post=2999"}],"version-history":[{"count":0,"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/pages\/2999\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/media?parent=2999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}