Running a query generated by a query

Hello,
I have the following query in 9i that will generate the add partitions queries for my tables.
Since I want to use it in a cron script, please suggest a way that I can run the queries generated from this script.
SELECT 'ALTER TABLE '||
table_name||
' ADD PARTITION '||
'P'||
TO_CHAR(TRUNC(sysdate+7), 'IYYY')||
'W'||
TO_CHAR(TRUNC(sysdate+7), 'IW')||
' VALUES LESS THAN(TO_DATE('''||
TO_CHAR(sysdate + 14, 'YYYYMMDD')||
''',''YYYYMMDD''));'
FROM user_tab_partitions
WHERE partition_name = (
SELECT 'P'||
TO_CHAR(TRUNC(SYSDATE), 'IYYY')||
'W'||
TO_CHAR(TRUNC(SYSDATE), 'IW')
FROM DUAL
AND table_name NOT IN
SELECT table_name
FROM user_tab_partitions
WHERE partition_name = (
SELECT 'P'||
TO_CHAR(TRUNC(sysdate+7), 'IYYY')||
'W'||
TO_CHAR(TRUNC(sysdate+7), 'IW')
FROM DUAL));
Thank you

Use dynamic SQL:
DECLARE
    stmt VARCHAR2(32767);
BEGIN
    SELECT  'ALTER TABLE '||
            table_name||
            ' ADD PARTITION '||
            'P'||
            TO_CHAR(TRUNC(sysdate+7), 'IYYY')||
            'W'||
            TO_CHAR(TRUNC(sysdate+7), 'IW')||
            ' VALUES LESS THAN(TO_DATE('''||
            TO_CHAR(sysdate + 14, 'YYYYMMDD')||
            ''',''YYYYMMDD''))' -- note no semi-colon
      INTO  stmt
      FROM  user_tab_partitions
      WHERE partition_name = (
                              SELECT  'P'||
                                      TO_CHAR(TRUNC(SYSDATE), 'IYYY')||
                                      'W'||
                                      TO_CHAR(TRUNC(SYSDATE), 'IW')
                                FROM  DUAL
        AND table_name NOT IN (
                               SELECT  table_name
                                 FROM  user_tab_partitions
                                 WHERE partition_name = (
                                                         SELECT  'P'||
                                                                 TO_CHAR(TRUNC(sysdate+7), 'IYYY')||
                                                                 'W'||
                                                                 TO_CHAR(TRUNC(sysdate+7), 'IW')
                                                           FROM  DUAL
    EXECUTE IMMEDIATE stmt;
END;
/SY.

Similar Messages

  • Problem while running a query on multiprovider

    Dear all,
    I have created a query to generate the balance sheet in FIGL using standard virtual cube 0FILGL_V01 and a custom transactional cube which gets plan data through BPS. The custom plan cube is an exact copy of the 0FIGL_V01 (plan value is populated in 0val_flow KF). These two cubes are conncected using a multiprovider. In the identification tab in the mutliprovider definition I have selected both the data targets for all characteristics.
    Now when I create a query for balance sheet using GL account no and plan and actual value of cumulative balance KF I get the following error.
    Error 'Field symbol has not yet been assigned.' in RSDRC_CUBE_DATA_GET_RFC could not be caught.
    When i run the query in the RSRT transaction it shows 'Some Key figure have exception aggregation.'
    I'll be very grateful if somebody could explain how to about removing this error. Thanks a lot.
    Regards,
    Sumit

    Hi Sumit,
    Try this OSS note:905083
    Import Support Package 16 for 3.5 (BW 3. 50 Patch 16 or SAPKW35016) into your BW system. The Support Package is available once Note 0872275 "SAPBWNews BW Support Package 16 NetWeaver'04 Stack 16", which describes this Support Package in more detail, has been released for customers.
    Before you implement the correction, you must carry out the following actions:
    1. Use Transaction SE37 to create the RSDRC_RAISE_EXCEPTION function module in the RSDRC function group (Short text = Terminator 2). This function does not have any parameters.
    2. In the RSDRC_CUBE_DATA_GET_RFC function module, under 'Tables', add the new entry E_T_MESG of the TSMESG type and this new entry is optional.
    3. The T100 messages DBMAN 003,004 and 005 complete the correction:
    a) 003: Unknown error in part cube RSDRC_CUBE_DATA_GET_RFC = &1
    b) 004: Non-catchable error '&1' in RSDRC_CUBE_DATA_GET_RFC.
    c) 005: The following error occurred in RSDRC_CUBE_DATA_GET_RFC for part cube = &1.
    In urgent cases you can implement the correction instructions.
    To make information available in advance, the notes mentioned may already be available before the Support Packages are released. However, in this case the short text still contains the words "preliminary version".
    Hope this helps.
    Assign points if useful
    Venkat

  • Problem while running a query on a multiprovider

    Dear all,
    I have created a query to generate the balance sheet in FIGL using standard virtual cube 0FILGL_V01 and a custom transactional cube which gets plan data through BPS. The custom plan cube is an exact copy of the 0FIGL_V01 (plan value is populated in 0val_flow KF). These two cubes are conncected using a multiprovider. In the identification tab in the mutliprovider definition I have selected both the data targets for all characteristics.
    Now when I create a query for balance sheet using GL account no and plan and actual value of cumulative balance KF I get the following error.
    Error 'Field symbol has not yet been assigned.' in RSDRC_CUBE_DATA_GET_RFC could not be caught.
    When i run the query in the RSRT transaction it shows 'Some Key figure have exception aggregation.'
    I'll be very grateful if somebody could explain how to about removing this error. Thanks a lot.
    Regards,
    Sumit

    Hi Sumit,
    Try this OSS note:905083
    Import Support Package 16 for 3.5 (BW 3. 50 Patch 16 or SAPKW35016) into your BW system. The Support Package is available once Note 0872275 "SAPBWNews BW Support Package 16 NetWeaver'04 Stack 16", which describes this Support Package in more detail, has been released for customers.
    Before you implement the correction, you must carry out the following actions:
    1. Use Transaction SE37 to create the RSDRC_RAISE_EXCEPTION function module in the RSDRC function group (Short text = Terminator 2). This function does not have any parameters.
    2. In the RSDRC_CUBE_DATA_GET_RFC function module, under 'Tables', add the new entry E_T_MESG of the TSMESG type and this new entry is optional.
    3. The T100 messages DBMAN 003,004 and 005 complete the correction:
    a) 003: Unknown error in part cube RSDRC_CUBE_DATA_GET_RFC = &1
    b) 004: Non-catchable error '&1' in RSDRC_CUBE_DATA_GET_RFC.
    c) 005: The following error occurred in RSDRC_CUBE_DATA_GET_RFC for part cube = &1.
    In urgent cases you can implement the correction instructions.
    To make information available in advance, the notes mentioned may already be available before the Support Packages are released. However, in this case the short text still contains the words "preliminary version".
    Hope this helps.
    Assign points if useful
    Venkat

  • Database Error while running the query.

    Hi,
    While running the query in webi rich client i am having a "database error IES 10901 and WIS 10901" , it is showing that the data source name not found and default driver is not specified.
    I am trying to generate report from efashion universe which is in .unx format, same client version and universe is running fine on another machine (webi rich client).
    PS: The above mentioned universe is running fine on my BI launch pad, the problem is with webi rich client only.
    Please help!!

    Hi,
    Which Database your are using .
    As explained by Yuvraj You need to install driver for specific database .
    Ask for client or (your Database ) driver from administrator .
    After installation you can see your database Driver in following path
    Control Panel\System and Security\Administrative Tools\Data Sources (ODBC)
    See in Drivers Tab .
    If you are using oracle & client is install on your system then Check TNS Names File in NETWORK folder .

  • Running MDX Query in BEX

    I've a question regarding MDX Query .
    1.Can we run MDX Query in BEx.
    2.If yes , then can you please tell me how and where can we run MDX Query in BEx.
    Regards,
    -Neha

    Hello,
    BEx does not support MDX. You can use MDXTEST transaction to generate the MDX select statements against queries or infocubes but it cannot be used with BEx.
    Thanks,
    Michael

  • Event Viewer cannot open the event Log or Custom view. Verify that the Event log service is running or query is too long. The instance name passed was not recognized as valid by a WMI data provider(4201).

    "Event Viewer cannot open the event Log or Custom view. Verify that the Event log service is running or query is too long. The instance name passed was not recognized as valid by a WMI data provider(4201)"
    This error keeps cropping up now and again on most of our domain controllers (OS-2008 AND 2008R2)...Usually a restart fixes the issue however the issue repeats and security logs don't generate.
    Any advice on how to fix this issue permanently would be greatly appreciated.

    Please see this: https://social.technet.microsoft.com/Forums/windows/en-US/95987ca3-a1b2-4da6-95b7-d825d06cdac7/error-code-4201-the-instance-name-passed-was-not-recognized-as-valid-by-a-wmi-data-provider?forum=w7itprosecurity
    You can also try rebuilding the WMI repository: http://blogs.technet.com/b/askperf/archive/2009/04/13/wmi-rebuilding-the-wmi-repository.aspx
    This posting is provided AS IS with no warranties or guarantees , and confers no rights.
    Ahmed MALEK
    My Website Link
    My Linkedin Profile
    My MVP Profile

  • How do you run a query to view duplicate records?

    I need to run a query with the query generator to produce a list of matching records. We have a problem whereby sales orders can come in by phone and email and therefore they sometimes get put on the system twice. I need to produce a query which picks up any orders where the CardCode and Document Value match, within say two days of each other.
    Please help?

    Hi Wendy Burt....
    Try This
    SELECT   COUNT(T0.[CardCode])as Duplicatecount, T0.[CardName], T0.[DocTotal] FROM ORDR T0
    WHERE T0.[DocTotal] IN ( select t1.doctotal from ORDR t1
    where t0.cardcode=t1.CardCode AND datediff(dd, t0.docdate,getdate())<=2)
    AND
    T0.CARDCODE IN ( select t1.CardCode from ORDR t1
    where t0.cardcode=t1.CardCode AND datediff(dd, t0.docdate,getdate())<=2)
    and t0.docstatus = 'O' and t0.doctotal >0
    GROUP BY  T0.[CardName], T0.[DocTotal]
    Regards,
    Kennedy

  • Running Answers query based on SAP BW metadata errors out

    Hello,
    When we run a query in Answers built upon SAP BW metadata in OBIEE repository , it errors out. The report runs for a long time ( around 10 minutes ) and then the following error message is displayed. This error occurs even in latest version 10.1.3.4.
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. Expected an attribute value (HY000)
    SQL Issued: SELECT "Billing doc. date"."Billing doc. date Level 01" saw_0, "Material (Sales)"."Key#3" saw_1, "SlsSold: Cust Hi Lvl"."Key#5" saw_2, "ZBILLIFC/ZCMI_ZBILLIFC_DATASOURCE"."Billing Qty:Base UoM" saw_3, "ZBILLIFC/ZCMI_ZBILLIFC_DATASOURCE"."Doc Gross Sls Amt" saw_4 FROM ZBILLIFC WHERE "Billing doc. date"."Billing doc. date Level 01" IN ('01/01/2008', '04/01/2008', '04/15/2008') ORDER BY saw_0, saw_1, saw_2
    The Logical SQL and query code is
    -------------------- Logical Request (before navigation):
    RqList
    Billing doc. date.Billing doc. date Level 01 as c1 GB,
    Material (Sales).Key#3 as c2 GB,
    SlsSold: Cust Hi Lvl.Key#5 as c3 GB,
    Billing Qty:Base UoM:[DAggr(ZBILLIFC/ZCMI_ZBILLIFC_DATASOURCE.Billing Qty:Base UoM by [ Billing doc. date.Billing doc. date Level 00, Billing doc. date.Billing doc. date Level 01, Material (Sales).Key#3, SlsSold: Cust Hi Lvl.Key#5] )] as c4 GB,
    Doc Gross Sls Amt:[DAggr(ZBILLIFC/ZCMI_ZBILLIFC_DATASOURCE.Doc Gross Sls Amt by [ Billing doc. date.Billing doc. date Level 00, Billing doc. date.Billing doc. date Level 01, Material (Sales).Key#3, SlsSold: Cust Hi Lvl.Key#5] )] as c5 GB,
    Billing doc. date.Billing doc. date Level 00 as c6 GB
    DetailFilter: Billing doc. date.Billing doc. date Level 01 in ([ '01/01/2008', '04/01/2008', '04/15/2008'] )
    OrderBy: c1 asc, c2 asc, c3 asc
    -------------------- Sending query to database named ZBILLIFC (id: <<3594792>>):
    With
    set [0BILL_DATE1] as '{[0BILL_DATE].[LEVEL00].members}'
    set [0BILL_DATE2] as ' hierarchize ({ [0BILL_DATE1], Generate({[0BILL_DATE1]},Descendants([0BILL_DATE].currentmember,[0BILL_DATE].[LEVEL01],SELF), ALL) } )'
    set [0MAT_SALES2] as '{[0MAT_SALES].[LEVEL01].members}'
    set [ZSOLDTO__ZCUSTHI2] as '{[ZSOLDTO__ZCUSTHI].[LEVEL01].members}'
    set [Q] as 'crossjoin ({[0BILL_DATE2]},crossjoin ({[0MAT_SALES2]},{[ZSOLDTO__ZCUSTHI2]}))'
    select
    {[Measures].[4BN5BQ04SN24SMG6AVQ4YF3DW],[Measures].[4BN5BQ7TBLNUB8ZMGPSH8H23O]}on columns,
    NON EMPTY {[Q]} properties MEMBER_UNIQUE_NAME, PARENT_UNIQUE_NAME , [0MAT_SALES].[20MAT_SALES] , [ZSOLDTO__ZCUSTHI].[2ZSOLDTO__ZCUSTHI] on rows
    from
    [ZBILLIFC/ZCMI_ZBILLIFC_DATASOURCE]
    Any help would be highly appreciated.
    Thanks
    Azfar

    It looks like an error in your "where" clause.
    You have:
    WHERE "Billing doc.date", "Billing doc. date Level 01" IN ('01/01/2008', '04/01/2008', '04/15/2008')
    It looks like it should be:
    WHERE "Billing doc.date" IN ('01/01/2008', '04/01/2008', '04/15/2008')
    AND "Billing doc.date Level 01" = <enter a condition here>

  • Run InfoSpoke Query

    Hi,
    I have a infospoke techincal name of query: how do i run the query?
    is it in Bex or WAD ?
    Thanks

    Magic,
       Infospoke is to extract the data from BW.
       may be you are talking about Infoset.... same way... how you are generating the Queries in Bex and WAD.
    It will in the same as Cubes.
    Regards,
    Nagesh Ganisetti.
    Message was edited by: Nagesh Ganisetti

  • Error while running a query-Input for variable 'Posting Period is invalid

    Hi All,
    NOTE: This error is only cropping up when I input 12 in the posting period variable selection. If I put in any other value from 1-11 I am not getting any errors. Any ideas why this might be happening?
    I am getting the following error when I try and run a query - "Input for variable 'Posting Period (Single entry, mandatory)' is invalid" - On further clicking on this error the message displayed is as follows -
    Diagnosis
    Variable Posting Period (Single Value Entry, Mandatory) is used as a lower limit (X) and an upper limit () in an interval selection. This limit has the value #.
    System Response
    Procedure
    Enter a different value for variable Posting Period (Single Value Entry, Mandatory). If the value of the other limit is determined by another variable, you can change its value also.
    Procedure for System Administration

    OK.
    Well, if the variable is not used in any interval selection, then I would say "something happened to it".
    I would make a copy of the query and run it to check if I get the same problem with period 12.
       -> If not, something is wrong in the original query (you can proceed as below, if changes to original are permitted).
    If so, then try removing the variable completely from the query and hardcode restriction to 12.
       -> If problem still persists, I would have to do some thinking.
    If problem is gone, then add the variable again. Check.
       -> If problem is back, then the variable "is sick". Only quick thing to do, is to build an identical variable and use that one.
    If problem also happens with the new variable, then it's time to share this experience with someone else and consider raising an OSS.
    Good luck!
    Jacob
    P.S: what fisc year variant are you using?
    Edited by: Jacob Jansen on Jan 25, 2010 8:36 PM

  • 'Structure Changed' Error when running a query

    Hi,
    I created a query with 2 structures. One structure for the time periods and one with Key figures (Calc and Restricted).
    The query ran fine and subsequently I put this into a workbook which had other queries and made a workbook type report.
    I modified the structure with the key figures recently and when I run the query now a popup box appears saying "warning; structure changed" and lists down the query elements that I changed, and subsequently the query does not run (no data is displayed).
    But if I open the same query in design mode and do nothing and run the query again (with the same input parameters), it runs ok.
    Please advise on how I can sort this out.
    Any help would be greatly appreciated.
    Thanks,
    Dominic

    Hi,
    If you want, you can remove the query with 'Remove Query' option in the BEx toolbar and then re-insert the query and then save the changes to the workbook. The next time, you refresh the workbook you won't get any such messages.
    Thanks

  • 'ORA-01722: Invalid Number' error while Running a Query

    Hi,
    I'm trying to run a query built on a DSO. The DSO has a field 'Start Date'. This Start Date InfoObject has a reference Char as 0DATE.
    This Start Field has blank values due to which I'm getting the ORA-01722 error. I came across many threads with same topic of discussion. As mentioned in one of the Threads I have written a program to update 'Start Date' with 00000000. The code wriiten is "UPDATE /BIC/AZ_MONINV00 SET /BIC/ZSTR_DTE = '00000000' where /BIC/ZSTR_DTE = ' '.
    Now when I see the data in the active data table of DSO the blank value is replaced with '00000000'.
    But If I right click on the DSO click on display data the 'Start Date' field is blank. And now the Query also gets executed without any error. But in the output of the query the 'Start Date' Field has "#" values.
    Can anyone suggest on how can I make these "#" values appear as 00000000 in the report?

    In this case, you have to write a macro to avoid # in Analyzer.
    Right Click-->Display Data will show data from Active table of DSO only.
    If you don't want to show any blank date values in the report, you can exclude in Filter in Query.

  • Error while running a Query on webi

    Hi Folks
    I just installed a BOBJ edge standard 3.1 and trying to configure and test it  the very first time, I have following issues if you can advise the solution., I would really appreciate.
    1. when i try to create a test query on Webi Rich Client and and run query, I get the follow messge:
    A databse error occured. The database error text is : [Microsoft] [ODBC Microsoft access driver] could not use (unknown);
    file already in use (WIS 10901)
    2. The other issue I have is that when i create a test query on the webi (infoview side) and try to run the query I dont see any result like column, rown or fields, all I see is a solid yellow block which I believe is because of kmissing Java connector. can you guys pls let me know if this is the reason I dont see the report or Is there any other reason for that.
    I would appreciate your help on this.
    Regards

    Hello,
    What type of database did you build your universe on? Access? SQL Server? or other? You would need to go into the universe you are trying to use for the report go into File, Parameters, and see what your connection is, and while you're there, click "test" to be sure it is working. If not, that is your problem. If it is, but the report still is not working, either way, you will need to go into Control Panel, Administrative Tools, Data Sources (ODBC) and set up a system DSN that links to the correct database. Again test it to be sure it works. Then make sure the universe has a connection that uses this same DSN. The report should run.
    Hope that helps.

  • Run a query on linked tables to create a new datasource

    Using Crystal XI
    I have a report that draws from two data sources.  They can't be joined at the server side, but they are linked in Crystal Database Expert. 
    I can't figure out if Crystal gives me a way to write an SQL Query to run an aggregate function referencing both tables.  The results of this query would be the datasource for a graph in the report.  I'm wondering if Crystal gives me a way, maybe through subreports, to write the query I need.
    More concretely:
    And I want to include in my datasource alarmId, Hour and the Maximum amount of calls received in any one hour for any one station (this maximum is to provide scale for a graph)
    In one table nameed AlarmStartTimes I have data like
    Alarms
    AlarmID  Hour    Recipient
    Alarm1       8       Joe
    Alarm23  10      Mark
    Alarm60  7      Joe
    Alarm95  8      Linda
    In another I have data like
    EELocation
    Recipient   Location
    Joe         Station1
    Mark         Station2
    Linda          Station1
    So if I could just join my talbes at the server side I'd use a query like:
    select *, max(select count(AlarmID) from Alarms, EELocation from Alarms Join EELocationo on Alarms.Recipient=EELocation.Recipient group by Hour, Location) AS  from Alarms
    Anyway, that's probably got a syntax error or 4 in it, but you get the idea.
    I can't group on the database side.  Since Crystal is able to link the two tables and successfully group them out by Location, it seems like there should be some way for me to run a query against the tables reflecting that existing link, but I can't see how to do it.
    The reason I can't link on database side is that the data is in two databases, and it's not known what the location of the databases is at report-writing time.  The location of the databases gets set via the Crystal API when the report is launched from an application.

    Since you have 2 datasource in the report you are limited on what you can use in crystal, such as crystal will not allow you to use sql expressions.

  • How to know that a form is running in query-only mode

    I have a form that can run in query-only mode or non-query-only mode depending on the current user who logs in, and I want to change its apprearance dynamically when it's in different modes (for example, enable or disable buttons). Is there a built-in or system variable from which I know that the form is running in query-only mode or not?
    Thanks,
    Shu

    The global variable solution is what we are using now. I thought there are some unpublished built-in or system variables. In my application, there is a public "menu" form from where hundreds of forms are CALLed with some in query-only mode and some in non-query-only mode depending on the current user role. :PARAMETER.QUERY_ONLY will always be 'NO' because the "menu" form is started in non-query-only mode. But it's good to know about it.
    Thank you very much for your replies,
    Shu

Maybe you are looking for