rust-oracle
rust-oracle copied to clipboard
Question - Calling Oracle Stored Procedures Example
How to call Oracle stored procedures returning sys_refcursor as out parameter from oracle0.5.7?
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.
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?
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);
}