1.7 KiB
Executable File
1.7 KiB
Executable File
Running sql in org mode
- Specifying your connection in the document header
- Specifying your connection as part of your source block
.. 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
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
#+PROPERTY: header-args :engine oracle :dbhost 172.17.0.2 :dbport 1521 :dbuser mydb_username :dbpassword mydb_password :database XE
Specifying your connection in a block
: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:
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.
#+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