pip install ipython-sql
In jupyter file:
%reload_ext sql
%sql oracle://RDF_CN_Q321:password@localhost:8521/xe
%config SqlMagic.style = '_DEPRECATED_DEFAULT'
if no config , will got below errors:
KeyError Traceback (most recent call last)
Cell In[9], line 1
----> 1 get_ipython().run_cell_magic('sql', '', 'select * from TABLE1\n')
File c:\Users\heeeeguo\AppData\Local\miniforge3\lib\site-packages\IPython\core\interactiveshell.py:2541, in InteractiveShell.run_cell_magic(self, magic_name, line, cell)
2539 with self.builtin_trap:
2540 args = (magic_arg_s, cell)
-> 2541 result = fn(*args, **kwargs)
2543 # The code below prevents the output from being displayed
2544 # when using magics with decorator @output_can_be_silenced
2545 # when the last Python token in the expression is a ';'.
2546 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):
File c:\Users\heeeeguo\AppData\Local\miniforge3\lib\site-packages\sql\magic.py:219, in SqlMagic.execute(self, line, cell, local_ns)
216 return
218 try:
--> 219 result = sql.run.run(conn, parsed["sql"], self, user_ns)
221 if (
222 result is not None
223 and not isinstance(result, str)
(...)
226 # Instead of returning values, set variables directly in the
227 # user's namespace. Variable names given by column names
229 if self.autopandas:
...
--> 116 self.pretty = PrettyTable(self.field_names, style=prettytable.__dict__[config.style.upper()])
117 else:
118 list.__init__(self, [])
KeyError: 'DEFAULT'
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
%%sql
select * from TABLE1
output :
column1 |
---|
111 |