{"id":14723,"date":"2024-03-15T09:49:56","date_gmt":"2024-03-15T09:49:56","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/"},"modified":"2025-08-06T12:33:45","modified_gmt":"2025-08-06T12:33:45","slug":"how-can-i-retrieve-query-results-from-oracle-using-shell","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/","title":{"rendered":"How can I retrieve query results from Oracle using shel&#8230;"},"content":{"rendered":"<p>You can retrieve Oracle query results in a shell using the following methods:<\/p>\n<ol>\n<li>Using the sqlplus command: sqlplus is a command-line tool provided by Oracle, which can connect to an Oracle database and execute SQL statements. It can be used in shell scripts to execute queries using the sqlplus command and output the results to the standard output or save them to a file. For example:<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-meta prompt_\">#<\/span><span class=\"language-bash\">!\/bin\/bash<\/span>\r\nresult=$(sqlplus -S username\/password@hostname:port\/service_name &lt;&lt; EOF\r\nset heading off\r\nset feedback off\r\nset pagesize 0\r\nselect column_name from table_name;\r\nexit;\r\nEOF\r\n)\r\necho $result\r\n<\/code><\/pre>\n<ol>\n<li>By using Oracle Instant Client and programming languages such as Python and Java, it is possible to connect to an Oracle database, execute query statements, and retrieve results. These programming languages&#8217; commands or scripts can be called within shell scripts to obtain query results. For instance, connecting to Oracle and executing queries in Python using the cx_Oracle library.<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-keyword\">import<\/span> cx_Oracle\r\n\r\n<span class=\"hljs-comment\"># \u8fde\u63a5Oracle\u6570\u636e\u5e93<\/span>\r\nconnection = cx_Oracle.connect(<span class=\"hljs-string\">'username\/password@hostname:port\/service_name'<\/span>)\r\n\r\n<span class=\"hljs-comment\"># \u521b\u5efa\u6e38\u6807<\/span>\r\ncursor = connection.cursor()\r\n\r\n<span class=\"hljs-comment\"># \u6267\u884c\u67e5\u8be2\u8bed\u53e5<\/span>\r\ncursor.execute(<span class=\"hljs-string\">'SELECT column_name FROM table_name'<\/span>)\r\n\r\n<span class=\"hljs-comment\"># \u83b7\u53d6\u67e5\u8be2\u7ed3\u679c<\/span>\r\nresult = cursor.fetchall()\r\n\r\n<span class=\"hljs-comment\"># \u5173\u95ed\u6e38\u6807\u548c\u8fde\u63a5<\/span>\r\ncursor.close()\r\nconnection.close()\r\n\r\n<span class=\"hljs-comment\"># \u8f93\u51fa\u67e5\u8be2\u7ed3\u679c<\/span>\r\n<span class=\"hljs-keyword\">for<\/span> row <span class=\"hljs-keyword\">in<\/span> result:\r\n    <span class=\"hljs-built_in\">print<\/span>(row[<span class=\"hljs-number\">0<\/span>])\r\n<\/code><\/pre>\n<p>Call a Python script in a shell script to obtain query results.<\/p>\n<pre class=\"post-pre\"><code><span class=\"hljs-meta prompt_\">#<\/span><span class=\"language-bash\">!\/bin\/bash<\/span>\r\nresult=$(python script.py)\r\necho $result\r\n<\/code><\/pre>\n<p>Choose the method that best suits you to obtain Oracle query results.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can retrieve Oracle query results in a shell using the following methods: Using the sqlplus command: sqlplus is a command-line tool provided by Oracle, which can connect to an Oracle database and execute SQL statements. It can be used in shell scripts to execute queries using the sqlplus command and output the results to [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[453,1402,299,1404,1403],"class_list":["post-14723","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-development","tag-guide","tag-programming","tag-technology","tag-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How can I retrieve query results from Oracle using shel... - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Learn about how can i retrieve query results from oracle using shell?. Comprehensive guide with examples and best practices.\" \/>\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.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How can I retrieve query results from Oracle using shel...\" \/>\n<meta property=\"og:description\" content=\"Learn about how can i retrieve query results from oracle using shell?. Comprehensive guide with examples and best practices.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-15T09:49:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-06T12:33:45+00:00\" \/>\n<meta name=\"author\" content=\"Liam\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Liam\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/\"},\"author\":{\"name\":\"Liam\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/23786905eb7b377f45ddb01c17da7671\"},\"headline\":\"How can I retrieve query results from Oracle using shel&#8230;\",\"datePublished\":\"2024-03-15T09:49:56+00:00\",\"dateModified\":\"2025-08-06T12:33:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/\"},\"wordCount\":159,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"keywords\":[\"Development\",\"guide\",\"programming\",\"technology\",\"tutorial\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/\",\"name\":\"How can I retrieve query results from Oracle using shel... - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2024-03-15T09:49:56+00:00\",\"dateModified\":\"2025-08-06T12:33:45+00:00\",\"description\":\"Learn about how can i retrieve query results from oracle using shell?. Comprehensive guide with examples and best practices.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How can I retrieve query results from Oracle using shel&#8230;\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/23786905eb7b377f45ddb01c17da7671\",\"name\":\"Liam\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8d37ed3e7f770dde8bf069ba0b4298688028c3abaacf1131742fc1352d174ebd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8d37ed3e7f770dde8bf069ba0b4298688028c3abaacf1131742fc1352d174ebd?s=96&d=mm&r=g\",\"caption\":\"Liam\"},\"sameAs\":[\"http:\/\/Wilson\"],\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/liamwilson\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How can I retrieve query results from Oracle using shel... - Blog - Silicon Cloud","description":"Learn about how can i retrieve query results from oracle using shell?. Comprehensive guide with examples and best practices.","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.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/","og_locale":"en_US","og_type":"article","og_title":"How can I retrieve query results from Oracle using shel...","og_description":"Learn about how can i retrieve query results from oracle using shell?. Comprehensive guide with examples and best practices.","og_url":"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2024-03-15T09:49:56+00:00","article_modified_time":"2025-08-06T12:33:45+00:00","author":"Liam","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Liam","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/"},"author":{"name":"Liam","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/23786905eb7b377f45ddb01c17da7671"},"headline":"How can I retrieve query results from Oracle using shel&#8230;","datePublished":"2024-03-15T09:49:56+00:00","dateModified":"2025-08-06T12:33:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/"},"wordCount":159,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"keywords":["Development","guide","programming","technology","tutorial"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/","url":"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/","name":"How can I retrieve query results from Oracle using shel... - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2024-03-15T09:49:56+00:00","dateModified":"2025-08-06T12:33:45+00:00","description":"Learn about how can i retrieve query results from oracle using shell?. Comprehensive guide with examples and best practices.","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/how-can-i-retrieve-query-results-from-oracle-using-shell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How can I retrieve query results from Oracle using shel&#8230;"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/23786905eb7b377f45ddb01c17da7671","name":"Liam","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8d37ed3e7f770dde8bf069ba0b4298688028c3abaacf1131742fc1352d174ebd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8d37ed3e7f770dde8bf069ba0b4298688028c3abaacf1131742fc1352d174ebd?s=96&d=mm&r=g","caption":"Liam"},"sameAs":["http:\/\/Wilson"],"url":"https:\/\/www.silicloud.com\/blog\/author\/liamwilson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/14723","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=14723"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/14723\/revisions"}],"predecessor-version":[{"id":158759,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/14723\/revisions\/158759"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=14723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=14723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=14723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}