Optional Data Input into Spotfire Text Area parameters got from a Oracle Function

假装没事ソ 提交于 2019-12-11 05:05:54

问题


I have created a Function from Oralce DB and used it as input to Spotfire report. The reason why i used a function instead of view is because the parameters had some complex logic operations and i was not able to get that done in a view.

Coming to the report i have built. Currently i am using 2 parameters in the function and i am taking both the values from Spotfire text area in Data on Demand mode. So i have set up two 'Input Field' for getting the data. Issue is that unless i enter values for both parameters i wont get the output. My requirement is that i need to add few more parameters for the report which i can but i need to set up the function and the settings in Spotfire such that if 5 parameters are there , if users enters one value for just one parameter report should run for that parameter. I know that parameters set up with complex logis are there but also i need to add additional ones and make sure it works properly. I dont know about proc in case a solution is achievable using that.

I cannot go back to use a view since that wont give me the desired result. Need any ideas or suggestions to implement it. Let me know in case i need to post additional information.

This is how i implemented in oracle :

 create or replace function Function_test(p1 varchar2='',p2 varchar2='',p3 varchar2)
      return SYS_REFCURSOR as
      my_cursor SYS_REFCURSOR;
    begin
      open my_cursor for

    select distinct

               x.c1
               x.c2
               x.c3
               from x
               where x.c1=p3
               and (p1='' or x.c2=p1)
               and (p2='' or x.c3=p2);

      return my_cursor;
    end;  

回答1:


Using a STORED PROCEDURE or a TABLE VALUED FUNCTION will achieve similar results here and you can probably use either one. I understand you can't use a VIEW because VIEWS can't have parameters. I prefer PROCEDURES over VIEWS anyway while working with SPOTFIRE because if you need to add a column or parameter to the PROCEDURE, your INFORMATION LINK on the PROCEDURE will in inherit these changes, whereas using an INFORMATION LINK on a VIEW, the change will not cascade down and you'll need to recreate the INFORMATION LINK all together.

For your case there are a couple of things I would suggest. Since you are trying to make some of the parameters optional, you need to code your FUNCTION or PROCEDURE to accept this. For example, assume one parameter is @param1 and this is accepting input from {$propertyControl1}. To make this optional, you need to instruct users to leave the property control blank if they don't want it to be used to limit the results. Meanwhile, in your FUNCTION or PROCEDURE you need to default it's value to ''. Here is what it could look like using SQL Server, but it should be similar for ORACLE

CREATE FUNCTION dbo.MyFunction (@param1 VARCHAR(256) = '') --default value is blank. Remember don't use NULL since your property control can't be NULL
RETURNS
@returnTBL TABLE(
   Column1 datetime,
   Column2 int,
   Column3 varchar(16))
AS
BEGIN
   INSERT INTO @returnTBL (Column1, Column2, Column3)
   SELECT
       c.C1
       c.C2
       c.C3
   FROM Table2
   WHERE @param1 = '' OR c.C3 = @param1   --this returns all rows if the user passes in blank, and filters on it if they pass in a value
RETURN
END

Or, similarly, here is the same logic using a STORED PROCEDURE in SQL Server

CREATE PROCEDURE dbo.MyProcedure(@param1 VARCHAR(256) = '') --default value is blank. Remember don't use NULL since your property control can't be NULL
AS

SELECT
   c.C1
   c.C2
   c.C3
FROM Table2
WHERE @param1 = '' OR c.C3 = @param1   --this returns all rows if the user passes in blank, and filters on it if they pass in a value
GO

Lastly, since you have multiple parameters, I wouldn't have the data on demand automatically refresh. I will have the users click the refresh button to retrieve the data. This will prevent the FUNCTION from being executed each time an individual parameter is change. If a user needs to change 3 of the 5 parameters, you really only want it executed once, versus three times.



来源:https://stackoverflow.com/questions/39636297/optional-data-input-into-spotfire-text-area-parameters-got-from-a-oracle-functio

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!