Select statement or procedure

Hi experts,
I have to run the report every week
In my sample data endreportafter column determines how many times the report runs
run_sunday.... determines which day of the week the reportshould run (1 means reports runs on that day)
startreportdate is the day the report should run.
can any one help me to get the result by using select statement or using procedure
thanks in advance

846773 wrote:
My first query is regular base table and my second query is the my expected result with just two columns(i excluded all the columns from first query )
second query is nothing but for each id what is my report expiredateI think I may have understood something your requirement but WTF, make an effort to be clear!!!
Let's suppose:
* for ID=1*
Your query is starting on '06/14/2012 10:41:40' (which is thursday).
It has to run 4 times and it runs only on Mon, Tue and Fri.
Then it will run on 06/15/2012, 06/18/2012, 06/19/2012 and 06/22/2012 (4 times). Expire date = 06/22/2012. Got it!! :-)
* for ID=2*
Your query is starting on '06/15/2012 10:41:40' (which is friday).
It has to run 1 time and it runs only on Mon, Tue and Fri.
Then it will run on 06/15/2012 and it's finished (1 time). Expire date = 06/15/2012. Got it!! :-)
* for ID=3*
Your query is starting on '06/16/2012 10:41:40' (which is saturday).
It has to run 2 times and it runs only on Mon, Tue and Fri.
Then it will run on 06/18/2012 and 06/19/2012 and it's finished (2 times). Expire date = 06/19/2012. Got it!! :-)
Please confirm the logic.
Regards.
Al
Edited by: Alberto Faenza on Jun 14, 2012 5:35 PM
Understood the logic
Edited by: Alberto Faenza on Jun 14, 2012 5:36 PM

Similar Messages

  • Is it possible to convert only select statement into procedure in Oracle

    Hi, Just i wanted to convert the below query in to procedure.Procedure input is 'P.Column1'
    SELECT
    P.Column1 AS PRODUCT,
    D.Column2 AS Column2N,
    D.Column3 AS LongColumn2iption,
    P.Column4 AS PRODUCICE,
    D.Column5 AS BilliuctID,
    E.Column6 As Impaenue,
    C.Column7 AS EffecDATE,
    FROM Table1 P, Table2 D,Table3 E,Table4 C
    WHERE
    P.Column1=D.Column1 and
    P.Column1=C.PROD_COMPONENT_ID and
    P.SETID=D.SETID and
    D.Setid =E.Setid and
    P.Setid =E.Setid and
    P.Setid =C.Setid and
    D.Column1=E.Column1 and
    P.Column1=E.Column1 and
    C.Column1<>'CONSUMER TARIFFS' and
    P.Column1 in('')

    Something like:
    SQL> var my_Data refcursor
    -- Anonymous block
    SQL> begin
      2  open :my_data for select 1,2 from dual;
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SQL> print :my_Data
             1          2
             1          2You can then convert the above anonymous block in to a procedure.

  • Can we convert a SQL (Select Statement) to Procedure.?

    Hi
    I am using a select sql for retrieving the results - Below is a sample sql select query.
    select TableC.DATEFIELD as QUERY_DATE,
    TableB.COLUMN1 PROCESS,
    TableC.COLUMN1 PRODUCT,
    sum(TableC.COLUMN4) as OPEN_INSTANCES
    from      TableA, TableB, TableC
    where TableB.COLUMN1      = TableA.COLUMN2
    and      TableA.COLUMN2      = TableC.COLUMN2
    and      DATEFIELD <= to_date('2011-02-02' ,'YYYY-MM-DD')
    and      DATEFIELD >= to_date('2011-02-02' ,'YYYY-MM-DD')
    and      TableC.COLUMN4 <= (24 * 3600 )
    and      TableB.COLUMN1 like 'PROCESSID'
    and      TableC.COLUMN1 in ('OSRCITR')
    group by TableC.DATEFIELD as QUERY_DATE,
    TableA.COLUMN1 PROCESS,
    TableC.COLUMN1 PRODUCT
    I believe if we use a Procedure, It would be much faster. Is there any way that we can convert the above select sql to a procedure. If yes, how can it be.
    Thanks in Advance.
    -Sreekant

    Sreekant wrote:
    select TableC.DATEFIELD as QUERY_DATE,
    TableB.COLUMN1 PROCESS,
    TableC.COLUMN1 PRODUCT,
    sum(TableC.COLUMN4) as OPEN_INSTANCES
    from      TableA, TableB, TableC
    where TableB.COLUMN1      = TableA.COLUMN2
    and      TableA.COLUMN2      = TableC.COLUMN2
    and      DATEFIELD <= to_date('2011-02-02' ,'YYYY-MM-DD')
    and      DATEFIELD >= to_date('2011-02-02' ,'YYYY-MM-DD')
    and      TableC.COLUMN4 <= (24 * 3600 )
    and      TableB.COLUMN1 like 'PROCESSID'
    and      TableC.COLUMN1 in ('OSRCITR')
    group by TableC.DATEFIELD as QUERY_DATE,
    TableA.COLUMN1 PROCESS,
    TableC.COLUMN1 PRODUCT
    I believe if we use a Procedure, It would be much faster. Is there any way that we can convert the above select sql to a procedure. If yes, how can it be.Using the code tags would make the query easier to read :)
    What version of Oracle are you on?
    Under the right conditions deconstructing a huge query into smaller components sometimes can offer performance increases, but this is more true of older versions of Oracle than recent ones. Lately I get better results from tuning queries in place - as Aman pointed out you introduce context switching (moving between the SQL and PL/SQL engines to do work) which can also hurt performance.
    Try tuning the query first. Get an execution plan. Things you can look for include
    * make sure the driving table is the best one
    * are the join columns properly indexed? Are existing indexes being suppressed due to the functions?
    Is "and      TableB.COLUMN1 like 'PROCESSID' " correct? without a wildcard LIKE should evalate to =

  • Convert SQL (Select Statement) to Procedure

    Hi
    I am using a select sql for retrieving the results - Below is a sample sql select query.
    select TableC.DATEFIELD as QUERY_DATE,
    TableB.COLUMN1 PROCESS,
    TableC.COLUMN1 PRODUCT,
    sum(TableC.COLUMN4) as OPEN_INSTANCES
    from TableA, TableB, TableC
    where TableB.COLUMN1 = TableA.COLUMN2
    and TableA.COLUMN2 = TableC.COLUMN2
    and DATEFIELD <= to_date('2011-02-02' ,'YYYY-MM-DD')
    and DATEFIELD >= to_date('2011-02-02' ,'YYYY-MM-DD')
    and TableC.COLUMN4 <= (24 * 3600 )
    and TableB.COLUMN1 like 'PROCESSID'
    and TableC.COLUMN1 in ('OSRCITR')
    group by TableC.DATEFIELD as QUERY_DATE,
    TableA.COLUMN1 PROCESS,
    TableC.COLUMN1 PRODUCT
    I believe if we use a Procedure, It would be much faster. Is there any way that we can convert the above select sql to a procedure. If yes, how can it be.
    Thanks in Advance.
    -Sreekant

    Hi,
    Try this...
    CREATE OR REPLACE PROCEDURE testing_sample (
    ov_d_query_date OUT DATE,
    ov_v_process OUT VARCHAR2,
    ov_v_product OUT VARCHAR2,
    ov_v_open_instances VARCHAR2
    AS
    BEGIN
    BEGIN
    SELECT tablec.datefield, tableb.column1, tablec.column1,
    SUM (tablec.column4)
    INTO ov_d_query_date, ov_v_process, ov_v_product,
    ov_v_open_instances
    FROM tablea, tableb, tablec
    WHERE tableb.column1 = tablea.column2
    AND tablea.column2 = tablec.column2
    AND datefield <= TO_DATE ('2011-02-02', 'YYYY-MM-DD')
    AND datefield >= TO_DATE ('2011-02-02', 'YYYY-MM-DD')
    AND tablec.column4 <= (24 * 3600)
    AND tableb.column1 LIKE 'PROCESSID'
    AND tablec.column1 IN ('OSRCITR')
    GROUP BY tablec.datefield, tablea.column1, tablec.column1;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    NULL;
    WHEN OTHERS
    THEN
    NULL;
    END;
    END;
    Note: -In Exceptions if you wanna catch you can do.
    Regards,
    Simma.....

  • Error by using database procedure in select statement

    hi ,
    I have built a database procedure having one parameter with in out varchar type. that return value with some addition.
    i am using it with some column in select statement only for display purpuses but i am facing error by doing that in select statement. that procedure is working well with bind variable but not with select statement.
    plz help me how i can use a procedure in select statement. or can i do it or not.

    plz help me how i can use a procedure in select statement. or can i do it or not.A workaround could be to create a wrapper function for your procedure. One that only passes the input parameters and returns the output parameter.
    The simply call this function in your select which internally calls the procedure.

  • How to use bind variable in this select statement

    Hi,
    I have created this procedure where table name and fieldname is variable as they vary, therefore i passed them as parameter. This procedure will trim leading (.) if first five char is '.THE''. The procedure performs the required task. I want to make select statement with bind variable is there any possibility to use a bind variable in this select statement.
    the procedure is given below:
    create or replace procedure test(tablename in varchar2, fieldname IN varchar2)
    authid current_user
    is
    type poicurtype is ref cursor;
    poi_cur poicurtype;
    sqlst varchar2(250);
    THEVALUE NUMBER;
    begin
         sqlst:='SELECT EMPNO FROM '||TABLENAME||' WHERE SUBSTR('||FIELDNAME||',1,5)=''.THE ''';
         DBMS_OUTPUT.PUT_LINE(SQLST);
    OPEN POI_CUR FOR SQLST ;
    LOOP
         FETCH POI_CUR INTO THEVALUE;
              EXIT WHEN POI_CUR%NOTFOUND;
              DBMS_OUTPUT.PUT_LINE(THEVALUE);
              SQLST:='UPDATE '||TABLENAME|| ' SET '||FIELDNAME||'=LTRIM('||FIELDNAME||',''.'')';
              SQLST:=SQLST|| ' WHERE EMPNO=:X';
              DBMS_OUTPUT.PUT_LINE(SQLST);
                   EXECUTE IMMEDIATE SQLST USING THEVALUE;
    END LOOP;
    COMMIT;
    END TEST;
    Best Regards,

    So you want to amend each row individually? Is there some reason you're trying to make this procedure run as slow as possible?
    create or replace procedure test (tablename in varchar2, fieldname in varchar2)
    authid current_user
    is
       sqlst      varchar2 (250);
       thevalue   number := 1234;
    begin
       sqlst := 'update ' || tablename || ' set ' || fieldname || '= ltrim(' || fieldname || ',''.'')  where substr(' || fieldname
          || ',1,5) = ''.THE ''';
       dbms_output.put_line (sqlst);
       execute immediate sqlst;
    end test;will update every row that satisfies the criteria in a single statement. If there are 10 rows that start with '.THE ' then it will update 10 rows.

  • SELECT statement in stored procedure

    I want to be able to execute a simple SELECT statement from within a stored procedure and return a stream of data which consists of all the rows from the SELECT statement.
    Ultimately, I want to ouput this stream of data to a Crystal Report.
    Apparently, Oracle will not allow you to execute a simple SELECT statement from within a stored procedure. It will only allow execution of a SELECT INTO statment, which requires that you define a cursor, etc. etc.
    Any way around this?
    Thanks
    Bill

    Look into REF CURSORs. Still not sure about whether APEX uses them though.... Good luck.

  • Use of a stored procedure in a select statement submitted to cx_oracle

    Hi,
    I am developping under python and I'm using the cx_oracle interface.
    I've written a stored procedure that I've tested directly under sqlplus session : it's ok. I've also tested this stored procedure from python by using callproc routine : its also ok.
    Now I need to use this procedure within a select statement that I submit to the execute statement of cx_oracle as :
    s = "select a.airport_name,gmlpos.ExpLatLong(a.point_name) from airport"
    self.db = oracledb('ops/opeope00@ACE2008B')
    dbmsg = self.db.execute(s)
    IF (dbmsg == "") :
    An error occurs :
    Message = request = select a.AIRPORT_NAME, gmlpos.ExpLatLong(a.point_name) from airport, errmsg = ORA-00904: "GMLPOS"."EXPLATLONG": invalid identifier
    Noting that the execution of any other select (without stored procedure) order from python works fine.
    Is anybody has a solution or workaround ?
    thanks a lot for your help

    The result gives what is expected :
    AIRP
    GMLPOS.EXPLATLONG(A.POINT_NAME)
    LFLL
    -45.71666666666667 -5.08333333333333
    As I said the stored procedure works fine.
    Thanks for your expertise
    PS : why change the login password until nobody says which machine or database is concerned ?

  • Executing a stored procedure containing multiple Select statements

    Post Author: Beverly
    CA Forum: General
    I am using Crystal  10.0 against a MS SQL 2000 server.
    I am trying to create a report based on a stored procedure that contains multiple select statements.  The sp requires a single parameter (Claim number) and contains 17 Select statements that produce results.
    I am able to use the Add command and execute the sp with the parameter, but I am only getting the results of the first select statement in the sp back in my data set.  Is there a way to have the data from each Select statement returned to my report?
    I have used Crystal for a while, but pretty much for straight-forward reporting.  I am familiar with the basics of SQL.
    I would appreciate any help anyone can offer.
    Thanks.

    Post Author: BISoftware
    CA Forum: General
    I believe Crystal Reports can only handle one recordset at a time, which means it can only handle a single select statement.  The only way I can see around this would be to break up your stored procedure into multiple stored procedures, so that each only contains a single select statement.  Then, use subreports to report on each individual sp. Hope this helps. - Davewww.BusinessSoftwareResource.com

  • JDBC Sender MSSQL Stored Procedure - Multiple Select Statements

    Hello all,
    I will proceed to tell you my problem, for which solution I request your kind advice:
    Im working in a project for a retailer, which consists in sending the information from erp and sql server to pos thru XI interfaces.
    One of the interfaces is about sending items from sql server to a file so the pos can load it into the system. For doing so I have devloped an stored procedure which function is to return several select statements as many stores the retailer might have, so they can have a different file per store along with its corresponding items in it. 
    The thing is that XI just gets the first select statement and creates the corresponding file, but it seems to ignore the remaining responses as I'm neither getting any file nor an error afterwards.
    So, my question is: is XI capable of handling multiple select responses from an Stored Procedure in graphical mapping??? Or am I just wasting my time trying?
    Thanks in advice for your help.
    Regards.

    Hello Ramkumar,
    After 5 days trying, I finally made it work out applying your advice. Below the short explanation of what I did:
    My Source structure is: Main Node->Row->Records (Material Number, StoreNum, Price, Status)
    My Target structure is: Main Node->File Node->Record Node->Records ( Material Number, Price, Status)
    The key was to make all the occurrences happen against StoreNum node. So, based on what you adviced these two where the key mappings:
    1) The Mapping that will create a new file for each different store that comes in the query (In my case, query was already sort by store using an sql "order by" function, if not you can also use xi node function "sort" as Ramkumar suggested)
    StoreNum->RemoveContext->SplitbyValue (Value Changed)->Collapse Contexts->File Node
    2) The Mapping that will create each record in its corresponding store file:
    StoreNum->RemoveContext->SplitbyValue (Value Changed)->Record Node
    And Voilá !!! It worked.
    Thanks very much Ramkumar.
    Regards.

  • Using procedure in SELECT statement

    I have a select statement that currently uses 4 functions to receive necessary values. All the functions are recursive and returns values from the same row.
    What I would like to do is replace these for function calls with 1 procedure. Does anybody know if it possible to use a procedure in this way inside a select statement?
    If so, do you have the syntax for doing this?
    E.g
    SELECT
    Mdbrd_Pkg.calculate_fixed_charge_fn(in_rc_id, ap.CONFIGSET_ID) AS FIXED_CHARGE,
    Mdbrd_Pkg.calculate_charge_rate_fn(in_rc_id, ap.CONFIGSET_ID) AS CHARGE_RATE,
    Mdbrd_Pkg.tax_liable_fn(in_rc_id, ap.CONFIGSET_ID) AS TAX_LIABLE,
    Mdbrd_Pkg.charge_unit_fn( in_rc_id, ap.CONFIGSET_ID) AS CHARGEUNIT_ID
    FROM .....

    This cannot be done. The part of the function used in the SELECT statement is the return value: procedures don't have return values (that's what makes tham procedures and not functions).
    Obviously I don't know what your code does, but you should consider putting them into a single function that returns a TYPE with four attributes and then using the TABLE() function to cast them into something you could reference in the FROM clause of a correlated sub-query. Sounds a bit messy though.
    Do these functions actually select data? Where does the recursion fit in?
    Cheers, APC

  • Can we call a procedure in select statement?

    Can we call a procedure in select statement?

    Hi,
    Raghu_appsdba wrote:
    Can we call a procedure in select statement?No. You can call functions, but not procedures.
    If the procedure does not change the database state (for example, it doesn't update any tables), then you can wrap it in a function, or re-write it as a function.
    Here's an example of wrapping.
    CREATE OR REPLACE FUNCTION fun_x (in_txt IN VARCHAR2)
    RETURN  VARCHAR2
    IS
    BEGIN
            proc_y (in_txt);
            RETURN  in_txt
    END     fun_x;

  • Can we call a stored procedure in a select statement

    Hi All
    I want to call a stored procedure inside a select statement is this possible.
    Regards
    Sravz

    You can create a pipelined function which gathers the data from your stored procedure and then use that in a select statement or directly write your script in any function or pipelined function. ;)
    There is no way you can call any stored procedure in a SELECT statement directly - i guess.
    Regards.
    Satyaki De.

  • How can i retrieve the output of procedure using a select statement ?

    Hi every one.
    this mite be dumm ?
    how can i use the output of the a procedure containing multiple rows of data in a select statement ?

    This is not  a SQL Developer question. You should ask it in the SQL and PL/SQL forum.
    The short answer is you can't.  Sounds is if you are trying to use MSSQL techniques in oracle. Learn oracle techniques

  • Creating multiple datasets using mulitple select statements as part of one macro / stored procedure

    Hi,
    I am working on a report what has 10 datasets derived from 10 different select statements.
    Is it possilbe to save those 10 select statements as a macro / stored procedure and then use that macro to generate those dataset in the ssrs report builder ?
    AshishSinghal

    Hi AshishSinghal84,
    According to your description, you want to write multiple select statements in a procedure, then use the procedure as dataset in the report, right?
    According to my knowledge, when we write multiple select statements in a procedure, we have to create relationship between these select statements, otherwise it will only return the first one query's fields. If you are using SSRS 2008 R2, you can use Lookup
    function to display these fields from different datasets on one data region control, but the prerequisite is that you must have one common field. For more information about lookup function, please see:
    http://msdn.microsoft.com/en-us/library/ee210531.aspx
    If all these solution you cannot achieve due to your special condition, the last workaround is to use subreport to display all the fields together.
    If you have any more questions, please feel free to ask.
    Thanks,
    Wendy Fu
    Wendy Fu
    TechNet Community Support

Maybe you are looking for

  • File to idoc error

    i am testing File to idoc scenario.. everything went smooth in XI...51 status error at ECC. when i went into details..it says..Fill in all required entry fields i tried checking those ..but its fine what should be the error

  • What's the alternative to losing everything?

    Guys I can't believe we lose all these features in iCloud, http://support.apple.com/kb/HT4898 – what is the alternative? Surely Mac would have one? I run 4 computers and need keychains, system preferences, signatures to all be in sync with each other

  • Status3 of Orders05 IDoc

    Hi all, We are sending the Purchase Order details to a third party system from SAP R/3 using Orders05 IDOC, but i am getting the following error: com.wm.lang.flow.FlowException: No Kreditor MPID found for system 75da182 I have checked the connections

  • Help with Album View

    Can anyone tell me why one album splits itself into several parts in album and list views.? I can't seem to get them all in one. Annoying that one or two songs separate themselves out. Thanks

  • After trying to upgrade, I got the error 3014 and now I can't get the iPad to do anything. It continually shows the "plug in to iTunes" icon.  How do I get past this problem?

    Can't restore, can't power off, and pc can't detect iPad.  Error code 3014 when trying to upgrade.  Can't even restore to original settings. Opened Hosts files and I did not see 127....gs.apple.com, or other suggested files.  Pls help.