Is there a way to dynamically calculate values for the IN operator?

I am looking to see if there is a way to dynamically calculate the criteria to include inside an IN operator in the WHERE clause. For example when I try to run the following I get an Oracle error message 'OR!-01722: invalid number'. The script below is just an example to help illistrate the problem, I do not want to hardcode the values assigned to v_test directly within the IN operator becasue the values in v_test will change from user to user.
DECLARE
v_test VARCHAR2(10) := '1,15,25,55';
v_tmp VARCHAR2(50) := NULL;
BEGIN
SELECT d.metric_title INTO v_tmp FROM tbl_health_metric_definition d
WHERE d.metric_status = 'Active' AND d.metric_id IN (v_test);
END;

Hi Jason,
When ever you use IN operator your values should be either seperated by a comma. If the column is of type number then your values should not enclosed in single quotes.
Eg: Wrong - '1,2,3,4,5'
Correct - 1,2,3,4,5
If your column is of type varchar then your values should be seperated by a comma and each value should be enclosed in single quotes.
Eg : Wrong - '1,2,3,4,5'
Correct - '1','2','3','4','5'
Correct - 'sam','boy','girl'
So correct you query so that the values in the IN operator are with out single quotes.
DONOT USE IN OPERATOR IN PL/SQL BLOCK WITH OUT A CURSOR._
If you use IN Operator and fire a query with out a cursor, it throws an error multiple rows returned. If at all you want to use in operator then use cursor.
Regards,
Rajesh
Edited by: Rajesh Gudipati on Jun 23, 2009 9:49 PM

Similar Messages

  • I cannot transfer my file to my ipadair from my laptap.is there other way to do it.Thanks for the answer.

    i cannot transfer my file to my ipadair from my laptap.is there other way to do it.Thanks for the answer.

    1. Copy videos and photos from laptop to a wireless flash drive
    2. Copy videos and photos wirelessly from flash drive to iPad
    http://www.sandisk.com/products/wireless/flash-drive/

  • Need help with a calculated column - is there any way to reference a value in the current row?

    Hey guys,
    I'm a bit of a DAX newbie, and I'm running into a block. I'm creating a Power View report about IT tickets. We are going to be creating a cube to automate the data soon, I'm currently working with a flat Excel Data Table of data to demonstrate the Power
    View reporting capabilities to the team. I need the default display to show the top 4-5 items basked on the Ticket Count. The three applicable columns I'm using are the TicketID, the ContactReason, and the AssetCategory - all three are
    text. One slide will show the top five Contact Reasons by Ticket Count, and the other will show the top five Categories by Ticket Count. The users will see this default view, but will be able to change it to see differently ranked items or can clear the
    ranking slicer altogether.
    What I've accomplished so far is to create the Calculated Field [Ticket Count] = COUNTA(Table1[TicketID])
    And 2 other calculated fields:
    [Contact Rank] = RANKX(ALL(Table1[ContactReason]),[Ticket Count],,,DENSE)
    [Asset Rank] = RANKX(ALL(Table1[AssetCategory]),[Ticket Count],,,DENSE)
    If I were creating a Pivot Table, this would be great. These fields calculate everything the right way. The problem is, I need to have a Rank slicer on each slide and the calculation by itself contains no data - with no data, there's nothing to slice. I
    realized I need to actually have columns of data so I can create a slicer. I need each row of the table to show the same [Contact Rank] for every instance of a particular ContactReason (and the same for the [Asset Rank] and AssetCategory).
    The RANKX formulas pasted into the Calculated Column section only show a value of 1 - with no Pivot table summarizing the fields, it's counting each row's ticket once, giving every line the tied Rank of #1.
    I've solved the problem in Excel by creating 2 Pivot Tables on a separate sheet that have the data field and the calculated field for ContactRason and AssetCategory. Then on my Excel Data Table, I've added two columns that do a VLOOKUP and pull over a the
    Calculated Rank from each Pivot Table that match the ContactReason and AssetCategory fields. This works on the flat Excel Data Table now, but will not be a solutions when we start pulling the data from the cube (and there is no flat table).
    What I think I need is an Expression for the RANKX formula that can give me, for each row, the count of all of the times a ContactReason shows up in an entire column. There's only about 100,000 lines of data and each ContactReason or AssetCategory
    may show up several thousand times. But if I can get the expression to return that count, then the RANKX formula should work in the Column. If it wasn't a DAX formula, I'd use a COUNTIF and say 'Count the entire ContactReason column anytime it's equal to the
    ContactReason on THIS row', but in DAX I don't know how to reference a single value in a row. I've tried the CALCULATE() formula, but it seems like the filter needs a specific value, and doesn't work on a dynamic "cell" value.
    Any help would be greatly appreciated! (I hope it all makes sense!)

    If I've understood you correctly then the ALLEXCEPT function may be what you're after and it could be applied in a similar way to the following...
    =
    RANKX(
    ALL(Table1),
    CALCULATE(
    COUNTROWS(table1),
    ALLEXCEPT(Table1, Table1[ContactReason])
    DENSE
    If this has missed the mark, would it be possible to clarify the requirement further?
    Regards,
    Michael Amadi
    Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to vote it as helpful :)
    Website: http://www.nimblelearn.com
    Blog: http://www.nimblelearn.com/blog
    Twitter: @nimblelearn

  • IS there any way to pass a value in the view as a variable

    Hi
    I have 2 views and 1 view on top of them that calls the 2 views e.g.
    View1
    select ename, deptno, date from emp;
    View2
    select sal, date from salary;
    view3
    select v1.ename, v1.deptno, v2.sal from view1, view2 where date = SOME VARIABLE;
    sql query
    Select * from v3 where date='10-AUG-2007'';
    ITs taking a while is there any way that I can define the V3 as follows
    view3
    select v1.ename, v1.deptno, v2.sal from view1, view2 where v1.date = SOME VARIABLE and v2.date=SOME VARIABLE;
    and then at the sql plus level can i use it like
    I have 2 views and 1 view on top of them that calls the 2 views e.g.
    View1
    select ename, deptno, date from emp;
    View2
    select sal, date from salary;
    view3
    select v1.ename, v1.deptno, v2.sal from view1, view2 where date = SOME VARIABLE;
    sql query
    Select * from v3 where date='10-AUG-2007''; can this date be passes as a variable in side the view definition.

    Setting up a view which contains a substiutution variable

  • Is there a way to create a shortcut for the 'copy unique selector' tool in Web Developer?

    Currently the only way to copy a unique selector is to either double click in the inspector tool, or access the popup bubble and click 'copy unique selector'. Is there a way to create a keyboard shortcut for that process?

    Hi Dubes,
    Thank you for your question. Maybe you can try the [https://addons.mozilla.org/en-US/firefox/addon/customizable-shortcuts/?src=search Customize shortcuts add on]

  • Is there a way to create a button for the tool bar that will View a page in "No Style'?

    I guess what I'm asking is...Is there a way to make a customized button for the toolbar that will allow me to change the view on a webpage to 'No Style' as listed under the view menu. If so, How can I do this?

    Try this add-on: <br />
    https://addons.mozilla.org/en-US/firefox/addon/custom-buttons/

  • In HCP Cockpit, is there a way to provide version information for the deployed java applications?

    We have a Java Application which is deployed on HCP. When we make fixes and redeploy it again, is there a way that we can provide version information that could be useful to identify which version is currently deployed. Please advice if there is an alternate way to achieve this.

    Unfortunately there is no way to do that current stage , you would need to add the tags manually.
    Thanks,
    Sanjit

  • HT203077 Is there any way to get other voices for the voice over?  Alex is dull.

    Is there any way to get other American English voices for the voice over--besides Alex?

    Settings > General > Siri > Voice Gender

  • Is there a way to dynamically update date in the file comments every time I save the file?

    My files starts with comments on who has created them and such.
    I want to update the datefield where it says it was last modified. It would be very tiresome to update it manually every time, and I am looking for a easier way.
    Of course I can always check in SVN when someone did an update, but I would like to see it in the files as well.
    Could anyone point out if there already is a working solution for this or if I have to hack it myself?
    /Thanks

    More breadcrumbs on Subversion keywork substitution.

  • Is There a way to request new features for the next upgrade?

    I want to be able to make custom tones for receiving text messages and emails... Blackberries can do this and I would like to be able to have my Iphone do this also.
    Am I the only one that wants this or are there others?
    Is there a place that we can request new features for an upcoming software upgrade?
    thanks alot

    You can request features via this form:
    http://www.apple.com/feedback/iphone.html
    Cheers,
    Leann

  • I want to buy Production Premium CS6, but I already own Flash Professional.  Is there a way I can avoid paying for the same product twice?

    I have a feeling I already know the answer to this question, but I figured it was worth asking anyway.
    Just under a year ago, I purchased Flash Professional CS6 for school.  Now that I am expanding my practices, I am interested in purchasing the Production Premium bundle of programs.  However, it already comes with Flash CS6, and if I can avoid paying for the same product twice, I'd like to do so.
    Is it possible for me to either get some kind of discount on the suite since I already own one of the programs?

    I have a feeling I already know the answer to this question, but I figured it was worth asking anyway.
    Just under a year ago, I purchased Flash Professional CS6 for school.  Now that I am expanding my practices, I am interested in purchasing the Production Premium bundle of programs.  However, it already comes with Flash CS6, and if I can avoid paying for the same product twice, I'd like to do so.
    Is it possible for me to either get some kind of discount on the suite since I already own one of the programs?

  • Is there a way to dynamically determine the number of out parameters for a server side procedure?

    Hi,
    Below is a helper method used for calling a server-side function which loops through the inbound bindVars parameter to populate the function's IN parameters. Is there a way to dynamically determine the IN/OUT parameters based on the procedure name in the stmt parameter? No members of the CallableStatement class seemed promising, but the getParameterMetaData() method in the PreparedStatement class seemed like it could be helpful lead. However, I have not found any detailed descriptions (yet) of how to use it.
    protected Object callStoredFunction(int sqlReturnType, String stmt,
      Object[] bindVars) {
      CallableStatement st = null;
      try {
      // 1. Create a JDBC CallabledStatement 
      st = getDBTransaction().createCallableStatement(
      "begin ? := "+stmt+";end;",0);
      // 2. Register the first bind variable for the return value
      st.registerOutParameter(1, sqlReturnType);
      if (bindVars != null) {
      // 3. Loop over values for the bind variables passed in, if any
      for (int z = 0; z < bindVars.length; z++) {
      // 4. Set the value of user-supplied bind vars in the stmt
      st.setObject(z + 2, bindVars[z]);
      // 5. Set the value of user-supplied bind vars in the stmt
      st.executeUpdate();
      // 6. Return the value of the first bind variable
      return st.getObject(1);
      catch (SQLException e) {
      throw new JboException(e);
      finally {
      if (st != null) {
      try {
      // 7. Close the statement
      st.close();
      catch (SQLException e) {}
    James

    The PreparedStatement.getParameterMetaData() object is exactly what you need for this task.
    Once you have the ParameterMetaData you can ask it how many parameters are present and which mode they are. The parameters are numbered from 1 to n and you can use ParameterMetaData.getParameterMode(1); to get the mode of the 1st parameter. The modes are defined as static values in the ParameterMetaData object. Check out the doc at http://docs.oracle.com/javase/7/docs/api/java/sql/ParameterMetaData.html
    Timo

  • Dynamically selecting values for filter in power pivot

    Hi,
    I am creating a power pivot report. I want the values of its filters to be set dynamically based on certain critreria. For Example, if some one changes the Iteration Path then the range of dates should change automatically to Iteration start date -
    Itearation End Date.
    Is there any way to set filter values based on some calculation.
    Any help in this regard will be highly appreciated.
    Thanks,
    Bhawna.
    Bhawna Aggarwal

    Check out the Event-In-Progress pattern as described here:
    http://cwebbbi.wordpress.com/2013/06/13/a-new-events-in-progress-dax-pattern/
    basically you need to create a separate measure which to do the specific filtering for you
    hth,
    gerhard
    Gerhard Brueckl
    blogging @ http://blog.gbrueckl.at
    working @ http://www.pmOne.com

  • Is there a way to automatically add another of the same page while a form is being filled?

    Is there a way to automatically add another of the same page while a form is being filled?
    I have a two-page form of which the second page is essentially a spreadsheet analog.  Often, there is need for for more lines than are available on the page.  Is there a way in which to add another or even multiple copies of the second page? 
    Thanks ahead...
    TG

    You can do that with a dynamic XFA form created in LiveCycle Designer, which comes with Acrobat Pro for Windows. For more information, you can ask over at the LiveCycle Designer forum.

  • Any way to pass Multiple Values for a single Label in the Parameter?

    I have a Report that Contains 2 Parameters, @Customer & @Area. When trying to set up the Available Values for @Area, I'm having issues using multiple values for one Label, i.e. = "4006" Or "4610"
    One of the Filters in the Report is an Operation number, which is the [OPERATION] field, which is setup as a filter on the Tablix referencing the @Area parameter. 
    PROBLEM: I cannot retrieve any data when trying to use the ‘Or’ Operator here. If I simply put “4006” or “4610” I retrieve data, but when trying to combine it returns no data.
    Example, I need to allow a user to select ‘Chassis Incoming’, which would include data from Operations 4006 & 4610.
    QUESTION:
    Any way to pass Multiple Values for a single Label in the Parameter?
    I realize the typical solution may be to use ‘Multi-Value’ selection, but in this case we want the User to select the Area and the multiple values for Filtering will be automatically determined for them. Otherwise, they are subject to not getting
    it correct.
    I have tried several different ways, such as =”4006” Or “4610”, =(“4006”, “4610”), = In(“4006”, “4610”), etc….
    Note: We are using Report Builder 3.0

    Based on my experience, there's no way to 'intercept' the query that gets passed back to SQL Server, so a Split wouldn't work.
    Try creating either a function or stored procedure using the code below (compliments to
    http://www.dotnetspider.com/resources/4680-Parse-comma-separated-string-SQL.aspx) to parse the string: 
    CREATE FUNCTION dbo.Parse(@Array VARCHAR(1000), @Separator VARCHAR(10))
    RETURNS @ResultTable TABLE (ParseValue VARCHAR(100))AS
    BEGIN
    DECLARE @SeparatorPosition INT
    DECLARE @ArrayValue VARCHAR(1000)
    SET @Array = @Array + @Separator
    WHILE PATINDEX('%' + @Separator + '%' , @Array) <> 0
    BEGIN
    SELECT @SeparatorPosition = PATINDEX('%' + @Separator + '%', @Array)
    SELECT @ArrayValue = LEFT(@Array, @SeparatorPosition - 1)
    INSERT @ResultTable VALUES (CAST(@ArrayValue AS VARCHAR))
    SELECT @Array = STUFF(@Array, 1, @SeparatorPosition, '')
    END
    RETURN
    END
    Once created you can do things like this:
    SELECT * FROM Parse('John,Bill,David,Thomas', ',')
    SELECT * FROM (SELECT 'John' AS TestName union select 'David' AS TestName) AS Main
    WHERE TestName IN (SELECT ParseValue FROM dbo.Parse('John,Bill,David,Thomas', ','))
    This is what your SQL query would probably look like:
    SELECT OperationID, OperationName FROM dbo.Operations
    WHERE AreaID IN (SELECT ParseValue FROM dbo.Parse(@Area, ','))
    You may need to fiddle around with the Separator depending on whether SQL Server inserts a space between the comma and next value.

Maybe you are looking for