#+TITLE: Running sql in org mode #+DATE: 2017-06-20 12:00:00 UTC #+DESCRIPTION: Example on how to run sql statements and display the results #+FILETAGS: emacs:sql:draft #+CATEGORY: emacs #+SLUG: running-sql-with-org-mode #+BEGIN_COMMENT .. title: Running sql in org mode .. slug: running-sql-with-org-mode .. date: 2017-06-20 12:00:00 UTC .. tags: emacs, sql, draft .. category: emacs .. description: Example on how to run sql statements and display the results .. type: text #+END_COMMENT When searching for this i found the information was incomplete or just plain did not work, after some trial and error and working things out i got it working and have created the examples for future reference. ** Specifying your connection in the document header This makes the connection available to all source code blocks by default *** Oracle example #+BEGIN_EXAMPLE #+PROPERTY: header-args :engine oracle :dbhost 172.17.0.2 :dbport 1521 :dbuser mydb_username :dbpassword mydb_password :database XE #+END_EXAMPLE Specifying your connection in a block #+BEGIN_EXAMPLE :PROPERTIES: header-args: engine oracle header-args: dbhost 172.17.0.2 header-args: dbport 1521 header-args: dbuser mydb_username header-args: dbpassword mydb_password header-args: database XE :END: #+END_EXAMPLE ** Specifying your connection as part of your source block You must not have any blank lines between the connection header pram's and the starting source code block else it will not work. #+BEGIN_EXAMPLE #+name: my-query #+header: :engine oracle #+header: :dbhost 172.17.0.2 #+header: :dbport 1521 #+header: :dbuser mydb_username #+header: :dbpassword mydb_password #+header: :database XE #+begin_src sql select * from dual; #+end_src #+END_EXAMPLE