How to specify a variable expression list in a Pro*C query?

后端 未结 4 845
轮回少年
轮回少年 2021-01-29 05:21

I have a problem with a Pro*C query I\'m trying to optimise.

To explain, our application searches for rows in a huge database. These rows exist in several languages and

相关标签:
4条回答
  • 2021-01-29 05:23

    I have used a table before composed of an ID and a set of rows where the rows are the permutation of the possible values in the "in" list. Then I join to the table based on the ID and it gives me the results I need.

    create table permute (
      id number,
      lang char(2)
    );
    create index permute_p1 on permute ( lang, id );
    insert into permute ( id, lang ) values ( 1, 'en' );
    insert into permute ( id, lang ) values ( 2, 'en' );
    insert into permute ( id, lang ) values ( 2, 'fr' );
    ...
    

    All you have to do then is pick the correct "ID" value 2, 3, 4 ... and put that into the join.

    0 讨论(0)
  • 2021-01-29 05:35

    You can't do this without Oracle Dynamic SQL. You will have to build your IN clause at runtime and EXECUTE IMMEDIATE. At least you can use Method 1, based on your queries.

    0 讨论(0)
  • 2021-01-29 05:42

    Probably this AskTom article can help you.

    0 讨论(0)
  • 2021-01-29 05:45

    ... Main String:= 'Select * FROM table WHERE id=:uniqid AND language IN'; -- can split into two to accomadate :uniqd ... Select Language_code into v_string from x_table; loop Copy & Concat v_string to LanCode_String and with ' ', ; end loop; .. Concat Lancode to Main String. .. Prepare and execute the Main String.

    0 讨论(0)
提交回复
热议问题