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

Question - Calling Oracle Stored Procedures Example #74

Open
Arunosaur opened this issue Mar 17, 2023 · 3 comments
Open

Question - Calling Oracle Stored Procedures Example #74

Arunosaur opened this issue Mar 17, 2023 · 3 comments

Comments

@Arunosaur
Copy link

How to call Oracle stored procedures returning sys_refcursor as out parameter from oracle0.5.7?

@kubo
Copy link
Owner

kubo commented Mar 17, 2023

See https://www.jiubao.org/rust-oracle/oracle/sql_type/struct.RefCursor.html.

let sql = "begin StoredProcedureName(:cursor); end;";
let mut stmt = conn.statement(sql).build()?;
stmt.execute(&[&None::<RefCursor>])?; // bind :cursor as RefCursor and execute the statement.

let mut cursor: RefCursor = stmt.bind_value(1)?; // get :cursor as RefCursor.

@lebe-dev
Copy link

lebe-dev commented Aug 5, 2023

How to specify an argument for this procedure? I have a procedure cursor = get_containers(identity), identity is a string (varchar).

As far as I know we should describe return value like this:

:outval = StoredProcedureName(:somearg);

How to get outval?

@lebe-dev
Copy link

lebe-dev commented Aug 5, 2023

Solved. May be it will help someone:

Procedure returns rows with id and path.

let mut containers: Vec<CloudContainer> = vec![];
let sql = "BEGIN :out := CLOUD_STORAGE_META.get_s3_containers(:identity); END;";
let mut stmt = cnn.statement(sql).build()?;

stmt.execute(&[&OracleType::RefCursor, &identity]).unwrap();

let mut ref_cursor: RefCursor = stmt.bind_value(1)?;

let rows = ref_cursor.query_as::<(u32, String)>()?;

for row_result in rows {
  let (storage_id, container_name) = row_result.expect("unable to decode result");

  let container = CloudContainer {
      storage_id,
      container_name,
  };

  containers.push(container);
}

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

3 participants