How to create dataframe from oracle resultset using DataFrames version 0.19?

Viewed 86

Table Data:

SQL> SELECT * FROM SUBJECTS;

    ID SUBJECT
---------- --------------------------------------------------
     1 tamil
     2 english
     3 mathematics
     4 science
     5 social science

Julia script to fetch data and create dataframe, as follows:

using DataFrames
import Oracle

global const dbHost = "localhost";
global const dbClientType = "thin";
global const dbName = "xe";
global const dbPort = "1521";
global const dbUserName = "ava";
global const dbUserPassword = "ava";
global const conn_str="//"*dbHost*":"*dbPort*"/"*dbName;

conn = Oracle.Connection(dbUserName, dbUserPassword, conn_str);
rs=Oracle.query(conn, "SELECT * FROM SUBJECTS");
df=DataFrame(rs)
Oracle.close(conn);

But, getting error, as follows:

julia> include("/root/oraConnTest.jl")
ERROR: LoadError: ArgumentError: no default `Tables.columns` implementation for type: Oracle.ResultSet
Stacktrace:
 [1] columns at /opt/julia/julia-1.4.1/share/julia/stdlib/v1.4/packages/Tables/FXXeK/src/fallbacks.jl:180 [inlined]
 [2] DataFrame(::Oracle.ResultSet; copycols::Bool) at /opt/julia/julia-1.4.1/share/julia/stdlib/v1.4/packages/DataFrames/yH0f6/src/other/tables.jl:32
 [3] DataFrame(::Oracle.ResultSet) at /opt/julia/julia-1.4.1/share/julia/stdlib/v1.4/packages/DataFrames/yH0f6/src/other/tables.jl:23
 [4] top-level scope at /root/oraConnTest.jl:14
 [5] include(::String) at ./client.jl:439
 [6] top-level scope at REPL[2]:1
in expression starting at /root/oraConnTest.jl:14

Please guide me in creating dataframe from oracle resultset. (ps: I am using dataframe version 0.19)

1 Answers

Just load the package and pass the ResultSet to the constructor

using DataFrames
DataFrame(rs)

See the official Julia Oracle driver tutorial for more details, including how to use a cursor if your ResultSet is too large for memory.

Related