Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exec pl/sql block #55

Closed
zaz600 opened this issue Mar 6, 2015 · 13 comments
Closed

exec pl/sql block #55

zaz600 opened this issue Mar 6, 2015 · 13 comments

Comments

@zaz600
Copy link

zaz600 commented Mar 6, 2015

Hi
How to execute and read output from pl/sql block?

r, _ := db.Exec("begin dbms_output.put_line('sdsdsdd'); end;")

@mattn
Copy link
Owner

mattn commented Mar 6, 2015

create utility function and do select

CREATE OR REPLACE PACKAGE dbms_output_table IS
   TYPE piped_output IS RECORD (dbms_output VARCHAR2(4000));
   TYPE piped_output_table IS TABLE OF piped_output;
   FUNCTION display RETURN piped_output_table PIPELINED;
END;
/

CREATE OR REPLACE PACKAGE BODY dbms_output_table IS
   FUNCTION display RETURN piped_output_table PIPELINED IS
      rec piped_output;
      p_status NUMBER;
   BEGIN
      DBMS_OUTPUT.GET_LINE(rec.dbms_output, p_status);
      WHILE p_status = 0 LOOP
         PIPE ROW(rec);
         DBMS_OUTPUT.GET_LINE(rec.dbms_output, p_status);
      END LOOP;
      RETURN;
   END;
END;
/
rows, err := db.Query("select * from table(dbms_output_table.display);")

@zaz600
Copy link
Author

zaz600 commented Mar 6, 2015

i can't add something to production database :(

@mattn
Copy link
Owner

mattn commented Mar 6, 2015

go-oci8 is possible to add implementation for fetch output, but database/sql doesn't provide way to set output-buffer for the query. So currently, it's not possible.

@zaz600
Copy link
Author

zaz600 commented Mar 6, 2015

okay. thx

@asaf
Copy link

asaf commented Jan 5, 2017

@mattn

Does it make sense to support this in go-oci8 out of the database/SQL interface?
Like the supplied functionality in the competitive oracle driver?

@mattn
Copy link
Owner

mattn commented Jan 5, 2017

It's possible like go-sqlite3's hook. https://github.com/mattn/go-sqlite3/blob/master/_example/hook/hook.go

But currently, go-oci8 doesn't support yet.

@asaf
Copy link

asaf commented Jan 7, 2017

@mattn Thanks, should follow golang/go#18417 that aggregates some issues that would make the standard interface support SP param bindings.

@kardianos
Copy link

@mattn and @asaf I'm not familiar with this particular aspect of Oracle PL/SQL. Could someone explain this to me? The docs I found: https://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_output.htm#BABJCAJA

What is this typically used for in production databases? How are ways you might interact with it from your API such as database/sql?

@mattn
Copy link
Owner

mattn commented Jan 11, 2017

One of the motivation is rowid in oracle. rowid is not number, so go-oci8 doesn't work correctly for the go's LastInsertId. The second, we have to allocate/free the buffer to get result specific value for the pl/sql.

@kardianos
Copy link

Thanks @mattn,

If the goal is to return a non-numerical rowid, then I would need to look at sql.Result.LastInsertId. Can the driver receive output lines today? Is it just a matter of piping that to the end user somehow? Can multiple lines be outputted and does that happen commonly?

@MichaelS11
Copy link
Contributor

Is this now good with adding of SQL out? Can this be closed?

@MichaelS11
Copy link
Contributor

@mattn Close this?

@mattn
Copy link
Owner

mattn commented Nov 19, 2018

This should be fixed. Please reopen you still have issue and it is related on go-oci8.

@mattn mattn closed this as completed Nov 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants