Skip to content

Dapper OracleDynamicParameters, multipleQquery and clause 'in' #53

Description

@figueiredorj

Hi,
I am struggling with something not sure why not able to execute.

I have a clause in that I would like to execute in a second query...
for simplicity let's say something like :

`

begin

  open :c_query1 for
    select * from T1;

  open :c_query2 for
  select * from T2 t_t2 where t_t2.name in :pNames;

end;

`

where I would have my parameters as
`

            var dynParams = new OracleDynamicParameters();
            dynParams.Add(":c_query1", direction: ParameterDirection.Output, dbType: OracleMappingType.RefCursor);
            dynParams.Add(":c_query2", direction: ParameterDirection.Output, dbType: OracleMappingType.RefCursor);
            dynParams.Add(":pNames", new[] {"AA", "BB"});

`

when I execute this my "in clause" comes empty....
any idea?
thanks

Activity

  1. theumairtahir commented on Oct 13, 2021

    @theumairtahir

    Hello!
    Can you please show that how are you declaring the "pNames" parameter into the procedure?

  2. figueiredorj commented on Oct 14, 2021

    @figueiredorj
    Author

    Hi @ut786
    actually it is a text query....

    I am able to query "in clause" with DynamicParameters... however when I change it for OracleDynamicParameters then query is as if no collection passed on....

  3. theumairtahir commented on Oct 14, 2021

    @theumairtahir

    Actually I couldn't get what you are actually doing. But somehow I get what you want to do. I am showing you the sample on how you can achieve that.
    First change pNames type to VARCHAR2 then write the query like this in the procedure:
    open :c_query2 for 'select * from T2 t_t2 where t_t2.name in ('|| :pNames';
    Then in the C# code:
    var values = new string[]{"AA", "BB"};
    dynParams.Add(":pNames", direction: ParameterDirection.Input, dbType: OracleMappingType.VARCHAR2, value: string.Join(',', values));

  4. figueiredorj commented on Oct 14, 2021

    @figueiredorj
    Author

    Hi @ut786 ,
    that is what I already doing (string concatenation) and was trying to avoid... as for that is always risk of sql injection, I would say....
    and actually using "Aggregate" - cleaner....

  5. theumairtahir commented on Oct 14, 2021

    @theumairtahir

    Hi @ut786 , that is what I already doing (string concatenation) and was trying to avoid... as for that is always risk of sql injection, I would say.... and actually using "Aggregate" - cleaner....

    Try to use DataTable in instead of string array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions