Help in calling dynamic columns in anonymous blocks

my code:
DECLARE
col1 VARCHAR2(20):='city';
BEGIN
FOR i IN (select * from xbd.cus_ord where rownum < 10)
LOOP
-- I would like to call col1 dynamically here in my dbms output.
DBMS_OUTPUT.PUT_LINE (i.col1);
END LOOP;
END;
On above code I was trying to call a dynmic column. How can I do that.
I heve been tried in different way by using EXECUTE IMMEDIATE. Still it doesnt work.
Thx,
Vi

DECLARE
   col1        VARCHAR2(30)   := 'object_name';
   TYPE REF_CURSOR IS REF CURSOR;
   refCursor   REF_CURSOR;
   text        VARCHAR2(4000);
BEGIN
   OPEN refCursor FOR 'SELECT ' || col1 || ' FROM all_objects WHERE ROWNUM < 10';
   LOOP
      FETCH refCursor
       INTO text;
      EXIT WHEN refCursor%NOTFOUND;
      DBMS_OUTPUT.PUT_LINE(text);
   END LOOP;
END;
/

Similar Messages

  • Calling sql script from anonymous block

    Hi
    how to call an script from an anonymous block, like
    declare
    v_reccord_account number :=0;
    begin
    SELECT xx.cc INTO v_reccord_account FROM
    (select count(1) cc
    from accounts
    group by account_id
    having count(account_id) > 1
    )xx
    where ROWNUM=1;
    if v_reccord_account <1
    then
    dbms_output.put_line('no duplicates');
    ELSE
    < here i have to call this script -- @e:/test44.SQL >
    end if;
    end;

    Hi
    thanks for replying, i'm having some sql statements, i have to spool the results of those statements .. below is the content of the file i'm calling.
    =================================================
    whenever sqlerror exit sql.sqlcode
    set serveroutput on
    column fn new_value filename
    select 'remove_duplicates_'||to_char(sysdate, 'yyyymmddhh24miss')||'.log' as fn from dual;
    spool E:/&filename
    prompt 'Checking for duplicates'
    --select account_id, count(1)
    --from accounts
    --group by account_id
    --having count(1) > 1;
    prompt 'Records to be deleted'
    select *
    from accounts
    where decode ( substr(account_id,1,3),'COG',1,0)=1
    group by account_id
    having count(1) > 1;
    prompt ' Deleting duplicates'
    delete
    from accounts
    where account_id in (
    select account_id
    from accounts
    where decode ( substr(account_id,1,3),'COG',1,0)=1
    group by account_id
    having count(1) > 1
    commit;
    ==========================================

  • Help me adding dynamic column in JSP

    Hi!
    Can any body please tell me how to add a column DYNAMICALY in JSP?
    I am using a drilldown and I want to add the next column after every + is clicked in drilldown.
    *If you have something to e-mail then please e-mail me at my below given e-mail address.
    Regards
    Ashish Bagora
    <[email protected]>

    I guess you're referring to a column table.
    You can simply submit to server and regenerate the page or you can add the column using Javascript DOM manipulation function.

  • Help!! how to call pl/sql anonymous block from java?

    I know that jdbc can call a pl/sql package or procedure,but if i
    want to call a pl/sql anonymous block, how can i do it? no procedure
    name or package name will be offered.
    Can u give me a sample code? thanks very much

    thanks ,but do u make sure that it can work? i have tried to do like this ,but i can not get it. Or please give me a detail code, thanks very much

  • Calling a function from ananymous block

    All,
    I have created a function which is to create a table with the given string. Below is the code.
    CREATE OR REPLACE
    FUNCTION tcr(
    name IN VARCHAR2)
    RETURN VARCHAR2
    IS
    vsql VARCHAR2(100);
    vmsg VARCHAR2(100);
    BEGIN
    vsql :='create table '||name||' ( a number(4) )';
    EXECUTE immediate vsql;
    dbms_output.put_line('craeted');
    vmsg:='creation msg';
    RETURN vmsg;
    EXCEPTION
    WHEN OTHERS THEN
    RETURN sqlerrm;
    END;
    When I am calling this from a SELECT stmt giving me the below error
    SELECT tcr('test1') FROM dual; ORA-14552: cannot perform a DDL, commit or rollback inside a query or DML
    And when I called this from an anonymous block giving me the error again.
    DECLARE
    vmsg VARCHAR2(200);
    BEGIN
    vmsg:= tcr('test11');
    dbms_output.put_line(vmsg);
    END;
    ORA-01031: insufficient privilegesCan we use a DDL inside a function and can be called from a SELECT Query. If not what happening inside it when we call from a query, am not able to understand. Expecting a clear explanation.
    Thanks
    Edited by: 968217 on Apr 17, 2013 11:08 AM

    >
    Can we use a DDL inside a function and can be called from a SELECT Query. If not what happening inside it when we call from a query, am not able to understand.
    >
    No - you can NOT use DDL inside a function used in a SELECT query.
    See 'Invoking Stored PL/SQL Functions from SQL Statements' in the Advanced Application Developer's Guide
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28424/adfns_packages.htm#ADFNS00908
    The section 'Controlling Side Effects' has the information about restrictions
    >
    Restrictions
    When a SQL statement is run, checks are made to see if it is logically embedded within the execution of an already running SQL statement. This occurs if the statement is run from a trigger or from a subprogram that was in turn invoked from the already running SQL statement. In these cases, further checks occur to determine if the new SQL statement is safe in the specific context.
    The following restrictions are enforced on subprograms:
    A subprogram invoked from a query or DML statement might not end the current transaction, create or rollback to a savepoint, or ALTER the system or session.
    A subprogram invoked from a query (SELECT) statement or from a parallelized DML statement might not execute a DML statement or otherwise modify the database.
    A subprogram invoked from a DML statement might not read or modify the particular table being modified by that DML statement.
    >
    Since DDL issues a COMMIT it would 'end the current transaction' which, as the first item above says, is not allowed.
    Yes - using the AUTONOMOUS_TRANSACTION pragma can side-step that issue but that would be a serious misuse of the functionality.

  • Calling a function which has a CLOB parameter via an anonymous block.

    OK,
    we are moving a lot of exports currently done by Crystal to just be done by stored procs.
    So we have a load of existing, some extremely length SQL statements used for these exports.
    IN the exports, we have meaningful column headings, so we have a 'lookup' file where all the column names are listed with the desired column name text listed against it.
    So - to make our lives easier(i thought) , I have written a Oracle function to extract al;l of the column names as a list (see below).
    It works fine except for when I am trying to pass in a SQL treatment that is longer than 4000 character.
    What I want to be able to do is simply have an anonymous block that callls my function, I will be running this via SQL explorer.
    Something like......
    DECLARE
    theSQL CLOB;
    BEGFIN
    theSQL := 'SELECT * FROM ORDERS WHERE 1=0';
    SELECT GET_COLUNS_AS_LIST( theSQL, 0 ) FROM DUAL;
    END;
    However, when I run this I get the error................
    PLS-00428: an INTO clause is expected in this SELECT statement
    06550. 00000 - "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    If I hard code the SQL like this, SELECT GET_COLUNS_AS_LIST( 'SELECT * FROM ORDERS WHERE 1=0', 0 ) FROM DUAL; all is well.
    Also, I am going to need to be able to pass in SQL ststement longer that 4000 characters as weel so please bear that in mind.
    I am not an Oracle guy, so I guess I am missing something fundamental - Please enlighten me with regards to this.
    Any help extremely appreciated.
    CREATE OR REPLACE FUNCTION GET_COLUNS_AS_LIST( P_SQL IN VARCHAR2, Add_Equals_Sign Number := 0)
    RETURN CLOB
    IS
    fResult VARCHAR2(32000);
    HNDL NUMBER;
    d NUMBER;
    colCount INTEGER;
    i INTEGER;
    rec_tab DBMS_SQL.DESC_TAB;
    cCRLF VARCHAR(2) := CHR(13) || CHR(10);
    LONG_SQL dbms_sql.varchar2s;
    n INTEGER;
    l INTEGER;
    u INTEGER;
    StartPos INTEGER;
    BEGIN
    --INITIIALISE RESULT
    fResult := '';
    HNDL := DBMS_SQL.OPEN_CURSOR;
    l := Length( P_SQL );
    u := ( l / 1000 ) + 1;
    FOR n IN 1..u
    LOOP
    StartPos := ( n - 1 ) + 1;
    LONG_SQL( n ) := SubStr( P_SQL, StartPos, 1000 );
    END LOOP;
    if HNDL <> 0 THEN
    DBMS_SQL.PARSE ( c => HNDL,
    statement => LONG_SQL,
    lb => 1,
    ub => u,
    lfflg => false,
    language_flag => DBMS_SQL.NATIVE );
    --DBMS_SQL.PARSE( HNDL, P_SQL, DBMS_SQL.NATIVE);
    d := DBMS_SQL.EXECUTE( HNDL );
    DBMS_SQL.DESCRIBE_COLUMNS( HNDL, colCount, rec_tab);
    FOR i in 1..colCount
    LOOP
    IF Add_Equals_Sign > 0 AND i > 1 THEN
    fResult := ltrim( fResult || '=' || cCRLF || UPPER( rec_tab( i ).col_name ), cCRLF );
    ELSE
    fResult := ltrim( fResult || cCRLF || UPPER( rec_tab( i ).col_name ), cCRLF );
    END IF;
    END LOOP;
    IF Add_Equals_Sign > 0 THEN
    fResult := fResult ||'=';
    END IF;
    ELSE
    fResult := '!!COULD NOT OPEN CURSOR!!';
    fResult := P_SQL;
    END IF;
    RETURN fResult;
    --Tidy Up 
    DBMS_SQL.CLOSE_CURSOR(HNDL);
    Return 'EGG';
    END;
    --EXAMPLE USAGE
    --Select GET_COLUNS_AS_LIST
    --Select * from SALES_TYPE
    --', 1) FROM DUAL;

    So I have ended up with this.
    When I next get some time, I'd like to be able to strip out the table and simply output the results to an SQL Developer script window without having to go through the table.
    Now this works - but if you see that I am doing something wrong - please point it out.
    Many thanks,
    Ant
    CREATE OR REPLACE FUNCTION GET_COLUNS_AS_LIST( P_SQL IN CLOB, Add_Equals_Sign Number := 0)
    RETURN VARCHAR2
    IS
    fResult VARCHAR2(32000);
    HNDL NUMBER;
    d NUMBER;
    colCount INTEGER;
    i INTEGER;
    ChunkSize INTEGER;
    rec_tab DBMS_SQL.DESC_TAB;
    cCRLF VARCHAR(2) := CHR(13) || CHR(10);
    LONG_SQL dbms_sql.varchar2s;
    n INTEGER;
    l INTEGER;
    u INTEGER;
    StartPos INTEGER;
    BEGIN
    --INITIIALISE RESULT
    HNDL := 0;
    ChunkSize := 4;
    fResult := '';
    --fResult := fResult|| 'A'; 
    HNDL := DBMS_SQL.OPEN_CURSOR;
    --l := Length( P_SQL );
    l := dbms_lob.getLength( P_SQL );
    --l := 50;
    u := Round( l / ChunkSize ) + 1;
    --fResult := fResult|| 'B';   
    FOR n IN 1..u
    LOOP
    StartPos := ( ( n - 1 ) * ChunkSize ) + 1;
    IF StartPos = 0 THEN
    StartPos := 1;
    END IF;
    --LONG_SQL( n ) := SubStr( P_SQL, StartPos, ChunkSize );
    LONG_SQL( n ) := DBMS_LOB.SUBSTR( P_SQL, ChunkSize, StartPos );
    END LOOP;
    --fResult := fResult|| 'C';  
    if HNDL <> 0 THEN
    DBMS_SQL.PARSE ( c => HNDL,
    statement => LONG_SQL,
    lb => 1,
    ub => u,
    lfflg => false,
    language_flag => DBMS_SQL.NATIVE );
    --DBMS_SQL.PARSE( HNDL, P_SQL, DBMS_SQL.NATIVE);
    d := DBMS_SQL.EXECUTE( HNDL );
    DBMS_SQL.DESCRIBE_COLUMNS( HNDL, colCount, rec_tab);
    --fResult := fResult|| 'D';  
    FOR i in 1..colCount
    LOOP
    IF Add_Equals_Sign > 0 AND i > 1 THEN
    fResult := ltrim( fResult || '=' || cCRLF || UPPER( rec_tab( i ).col_name ), cCRLF );
    ELSE
    fResult := ltrim( fResult || cCRLF || UPPER( rec_tab( i ).col_name ), cCRLF );
    END IF;
    END LOOP;
    IF Add_Equals_Sign > 0 THEN
    fResult := fResult ||'=';
    END IF;
    ELSE
    fResult := '!!COULD NOT OPEN CURSOR!!';
    END IF;
    RETURN fResult;
    --Tidy Up 
    IF HNDL <> 0 THEN
    DBMS_SQL.CLOSE_CURSOR(HNDL);
    END IF;
    END;
    -- !!!!HOW TO USE THIS FUNCTION!!!!
    BEGIN
    EXECUTE IMMEDIATE ('DROP TABLE RPT_COLNAME_LOOKUPS;');
    COMMIT;
    EXECUTE IMMEDIATE ('CREATE TABLE RPT_COLNAME_LOOKUPS( COLUMN_NAME CLOB );');
    COMMIT;
    EXCEPTION WHEN OTHERS THEN NULL;
    END;
    DECLARE
    theSQL Clob;
    myresult CLOB;
    BEGIN
    --CLEAR OUT PREVIOUS RWS
    DELETE FROM RPT_COLNAME_LOOKUPS; COMMIT;
    --ASSIGN THE SQL TO RUN IT FOR 
    theSQL := '
    SELECT
    EVENT.EVENT_ID AS COCK_SUCKER,
    EVENT.EVENT_CODE, BLAH, BLAH, VERY LONG SQL STATEMENT';
    --CALL THE FUNCTION PASSING IN THE SQL AND IF I WANT THE = OR NOT
    SELECT GET_COLUNS_AS_LIST( theSQL, 1 ) INTO myresult FROM DUAL;
    --INSERT THE RESULTS INTO A TABLE SO WE CAN GRAB THEM
    INSERT INTO RPT_COLNAME_LOOKUPS SELECT myresult FROM DUAL;
    COMMIT;
    END;
    --THEN LOOK AT THE COLUMNS NAMES IN THIS TABLE
    --SELECT * FROM RPT_COLNAME_LOOKUPS;
    --#############################################################################

  • INVALID CURSOR - Anonymous Block calling Cursor in function

    I am getting an error when trying to call my cursor.
    CREATE OR REPLACE PACKAGE tax_update
    AS
    TYPE gencur IS ref cursor;
    FUNCTION tax_sf
       p_state IN bb_tax.state%type,
       p_thecursor IN OUT gencur
    RETURN NUMBER;
    END;
    CREATE OR REPLACE PACKAGE BODY tax_update
    AS
    FUNCTION tax_sf
       p_state IN bb_tax.state%type,
       p_thecursor IN OUT gencur
    RETURN NUMBER
      IS
      lv_taxrate NUMBER;
    BEGIN
      OPEN p_thecursor FOR
       SELECT taxrate
       FROM bb_tax
       WHERE state = p_state;
      RETURN lv_taxrate;
    END;
    END;
    DECLARE
      tax_cur tax_update.gencur;
      rec_tax bb_tax%rowtype;
    BEGIN
    LOOP
      FETCH tax_cur INTO rec_tax;
       EXIT WHEN tax_cur%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(rec_tax.taxrate);
    END LOOP;
    END;
    DECLARE
    ERROR at line 1:
    ORA-01001: invalid cursor
    ORA-06512: at line 6Assignment is to create a package that will hold tax rates by state in a packaged cursor. The package will contain a function that can receive a 2 character state abbr. as an argument and find a match in the cursor and return the tax rate for tha tstate. An anonymous block will test the function with state of NC.
    Can anyone assist?

    You would need to call the function to open the cursor before you try to fetch from the cursor
    DECLARE
      tax_cur tax_update.gencur;
      rec_tax bb_tax%rowtype;
      l_some_number number;
    BEGIN
      l_some_number :=  tax_update.tax_sf( <<some state parameter>>, tax_cur );
      LOOP
        FETCH tax_cur INTO rec_tax;
        EXIT WHEN tax_cur%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(rec_tax.taxrate);
      END LOOP;
    END;A couple of points, though.
    1) Your function returns a NUMBER but that NUMBER will always be NULL. It seems rather unlikely that this is really what you want. It would seem to make more sense for the function to return the cursor rather than returning a superfluous number.
    2) Your function requires a `bb_tax.state%type` parameter. But your anonymous block doesn't seem to have any concept of a state so I'm not sure what you want to pass in there.
    3) Looking at the code, it seems a bit odd that your cursor returns a single column of data. If a state can have multiple rates, wouldn't you need to select some additional criteria in order to figure out which sort of tax each row represents or to otherwise differentiate different rows? If a state can only have a single tax rate, it makes no sense to open a cursor that is only going to ever return a single row.
    4) There is no need to declare your own weak ref cursor type (tax_update.gencur). You can just use the Oracle built-in type SYS_REFCURSOR.
    Justin

  • Calling PL/SQL anonymous block from href in tabular report

    apex 2.2.
    I've got a tabular report where I've added some img columns with a href to call diff processes
    for example
    "<a href="f?p=&APP_ID.:22:&APP_SESSION.:BRANCH_TO_PAGE_ACCEPT|NEW_PROXY:NO:::22,ABCDEF ><img src="/i/asyl.gif" border="0" alt="Runprocess"></a>"
    When clicking on an image column in row x then I would like to run the process - no page submit.
    The pl/sql anonymous block process source calls package.storedproc(p1,p2) - two in parameters
    I'm struggling with the syntax and is wondering if there's a smarter way to achieve the same function
    Any ideas most welcome
    Thanks
    Peter

    &lta href="f?p=&APP_ID.:22:&APP_SESSION.:BRANCH_TO_PAGE_ACCEPT|NEW_PROXY:NO:::22,ABCDEFG" &gt&ltimg src="/i/asylogin.gif" border="0" alt="Process"&gt&lt/a&gtQuestion is how can you pass values from a row in a tabular report to the application process ?

  • CFChart Dynamic Column HELP

    I looked over the posts on CFChart but did not find anything
    that addresses my specific problem with the cfchart. So if you can
    help, I'd appreciate it very much!
    What I want to do is take the dynamic name of the column
    derived from the first query and use that name in the Legend. E.G.
    A_R1_DIS is the first dataset, A_R1_J is the second dataset, and
    A_R1_PPLI is the third dataset. Then show a line graph with each
    dataset based on the first query. The X Axis displays the Date/Time
    value and the Y Axis displays the number of points for each record
    of time for each dataset individually. I was able yesterday to get
    all three datasets to display individually but when I tried to show
    the legend it either displayed only the first Dataset name
    "A_R1_DIS" or it displayed "NONE". Currently the code will not
    display any line on the chart and the legend repeats the A_R1_DIS
    as many times as there are records in the table (60+).
    I use the following query to get the dynamic column name
    "SelectedDatasetColName" from the MasterDataList table.
    <CFQUERY name="getSelectedDatasetColName"
    datasource="#getcfdbname.EventCFDBName#">
    SELECT MDL_TestName + '_' + MDL_DatasetID + '_' +
    MDL_MeaningfulName as SelectedDatasetColName
    FROM MasterDataList
    </CFQUERY>
    Here is where I'm using the "SelectedDatasetColName" value:
    ******************************************* queries
    <CFQUERY name="DatasetHistogramQry"
    datasource="#getcfdbname.EventCFDBName#">
    SELECT
    <cfset i = 1>
    <cfloop query="getSelectedDatasetColName">
    #SelectedDatasetColName# as col#i#,
    <cfset i = i + 1>
    </cfloop>
    JDay, TheHour, TheMinute,
    convert(varchar(12), JDay, 114) + ' ' + convert(varchar(12),
    TheHour, 114) + ':' + convert(varchar(12), TheMinute, 114) as
    DateTime
    FROM vPositionHistogram
    ORDER BY JDay, TheHour, TheMinute
    </CFQUERY>
    Here is the code for the table; which works correct:
    **************************** Report Code
    <TABLE>
    <TR>
    <TH>Day</TH>
    <TH>Hour</TH>
    <TH>Minute</TH>
    <CFOUTPUT QUERY="getSelectedDatasetColName">
    <TH>#SelectedDatasetColName# Message Count</TH>
    </CFOUTPUT>
    </TR>
    <CFOUTPUT QUERY="DatasetHistogramQry">
    <TR BGCOLOR="###IIF(DatasetHistogramQry.currentrow MOD 2,
    DE('DCDCDC'), DE('FFFFFF'))#">
    <TD ALIGN="center">#JDay#</TD>
    <TD ALIGN="center">#TheHour#</TD>
    <TD ALIGN="center">#TheMinute#</TD>
    <CFSET i = 1>
    <CFLOOP INDEX="X" FROM="1"
    TO="#getSelectedDatasetColName.recordcount#">
    <TD ALIGN="center">#evaluate("col#i#")#</TD>
    <CFSET i = i + 1>
    </CFLOOP>
    </TR>
    </CFOUTPUT>
    </TABLE>
    Here is the output for the table; Dynamic Column Name used to
    repeat counts for each dataset.
    ********************************* output
    Day Hour Minute A_R1_DIS Message Count A_R1_J Message Count
    A_R1_PPLI Message Count
    37 17 36 0 2 35
    37 17 37 19 6 32
    37 17 38 28 30 33
    37 17 39 40 27 27
    37 17 40 66 64 32
    Here is the problem code. I have tried several variations on
    this code but currently all it does is display a blank chart.
    **************************** Chart Code
    <CFCHART FORMAT="flash" CHARTHEIGHT="340" CHARTWIDTH="600"
    SHOWXGRIDLINES="yes" SHOWYGRIDLINES="yes" SHOWBORDER="no"
    FONTBOLD="no" FONTITALIC="no" XAXISTITLE="Timeline (Day
    Hour:Minute)" YAXISTITLE="Message Counts" SHOW3D="no" ROTATED="no"
    SORTXAXIS="no" SHOWLEGEND="yes" TIPSTYLE="MouseOver"
    SHOWMARKERS="no">
    <CFOUTPUT QUERY="DatasetHistogramQry">
    <CFSET i = 1>
    <CFLOOP INDEX="X" FROM="1"
    TO="#getSelectedDatasetColName.recordcount#">
    <CFCHARTSERIES QUERY="DatasetHistogramQry" TYPE="line"
    ITEMCOLUMN="#DateTime#" VALUECOLUMN="#evaluate("col#i#")#"
    SERIESLABEL="#getSelectedDatasetColName.SelectedDatasetColName#">
    <CFSET i = i + 1>
    </CFLOOP>
    </CFOUTPUT>
    </CFCHART>
    Please let me know if you need any additional info on my
    problem and if you can help, it is greatly appreciated!!!!
    - Debra

    DateTime is a column in the vPositionHistogram (View). Col#i#
    is the variable used to loop through the column names derived from
    the getSelectedDatasetColName query. The view is populated
    dynamically and the columns in it vary depending on the dataset
    used to populate the view. The view can have 1 to many columns.
    That is why I pull the column names from the MasterDataList table
    and use a variable to get the values from each column. My column
    names end up being Col1, Col2, Col3, and so on. I use that variable
    in the loop to get the data from vPositionHistogram for each column
    in the report/chart. I made some headway on Friday before I called
    it a day, but I will try the last suggestion and post my findings
    in a little while. Thanks!

  • How to call the column names into the prompt and display values dynamically

    Hi,
    i have a typical requirement where I have to call 3 columns into the AGE Prompt (I know we can use the Column Selector to call the columns) .Below is the Screen Shot.
    !http://i46.tinypic.com/2qjfukh.jpg!
    2nd Requirement)
    The three columns I have are order Date, Ship Date and Entry Date.
    Whenever I click on Orderdate from the Prompt, It should dynamically show its values in the report.
    and When I click on the Ship Date from the Prompt, it should display the corresponding values in the report.
    and so on with the Entry Date.
    Can anybody help me how to acheive this.
    Thanks a ton.

    Ok so then you can use a fake column prompt. Here's one quick approach (nicer and cleaner with LOV tables but I don't if you have any of those).
    - Create a fresh prompt using any column you want.
    - Open the column formula using the fx button and replace the formula with 'abc'.
    - Use "SqL Results" as the "Show" option.
    - SQL:
    select case when 1=0 the Markets.Region else 'Order Date' from Paint.Markets UNION ALL
    select case when 1=0 the Markets.Region else 'Ship Date' from Paint.Markets UNION ALL
    select case when 1=0 the Markets.Region else 'Entry Date' from Paint.Markets
    - Set Variable = Presentation Variable = @{vPresVarSelectedDate}{Order Date}
    - Label = Date
    Then in the request, you change the column formula for the date. I'm going to make it short and just assume you called your time dimension alias(es) like the lowest grain:
    "@{vPresVarSelectedDate}{Order Date}"."@{vPresVarSelectedDate}{Order Date}"
    Cheers,
    C.

  • Refresh pl/sql anonymous block via dynamic action?

    Greetings again to the community!
    Something I must be misunderstanding.
    I want to dynamically (ajax) update a select list depending on a page item. Now when you research for operations like this, you get some examples - but which mostly are older and... contain a lot of coding. So I am wondering if this is to be achieved in a simple way using dynamic action.
    I have created a testcase here where the html for a select list ist created in a pl/sql anonymous block like that:
    begin
    for i in (select EMPNO, ENAME from EMP
            where DEPTNO = :P50_DEP_NO or
                     :P50_DEP_NO is null)
          loop
      htp.p('<option value="' || i.EMPNO || '">' || i.ENAME || '</option>');
      end loop;
    end;Region header and footer contain the tags for <select id="selEmps"> ... </select>.
    When you press [Btn Update Sel], a dynamic action is triggered, that submits :P50_DEP_NO, then refreshes the region with the pl/sql code, so that, after you have enteres another value in :P50_DEP_NO, the select list then shows the employees of that department. Thats the plan, but
    Its not working! Can anyone tell me, what I have overlooked here, please?
    Thank you and good night for now,
    tobi

    Hi Marko,
    thanks for your hint. I have already tought about that, but im not sure if this is the solution of this particular situation, because the list really should be generated html-code for formating reasons with jQuery UI and further processing. But I have not worked so much with cascading LOVs, so I really should look into it further.
    If I dont find a solution there, I'll get back here.
    Thanks and so long,
    tobi

  • PL/SQL Anonymous Block - Trying to Call Function within Cursor

    Hello -
    I need to create an anonymous block that contains a cursor and a function. I want to call the function from within the cursor, and the function will basically take an ID as its IN parameter, and will return a comma separated list of values.
    However, when I try to do this I get the error " function 'GET_PAYMENT_DATES' may not be used in SQL".
    Does anyone know of a workaround? I'm trying to avoid having to store this function.
    Thanks,
    Christine

    Exploring Keith's suggestion of using the function code inline in your SQL:
    test@ORA10G>
    test@ORA10G> --
    test@ORA10G> drop table t;
    Table dropped.
    test@ORA10G> drop table monetary_trans;
    Table dropped.
    test@ORA10G>
    test@ORA10G> create table monetary_trans as
      2  select 1 household_id, trunc(sysdate)-10 received_date from dual union all
      3  select 1, trunc(sysdate)-9 from dual union all
      4  select 1, trunc(sysdate)-8 from dual union all
      5  select 2, trunc(sysdate)-7 from dual union all
      6  select 2, trunc(sysdate)-6 from dual;
    Table created.
    test@ORA10G>
    test@ORA10G> create table t as
      2  select rownum x, rownum*10 y from dual connect by level <= 4;
    Table created.
    test@ORA10G>
    test@ORA10G> --
    test@ORA10G> select * from monetary_trans;
    HOUSEHOLD_ID RECEIVED_
               1 28-DEC-08
               1 29-DEC-08
               1 30-DEC-08
               2 31-DEC-08
               2 01-JAN-09
    test@ORA10G> select * from t;
             X          Y
             1         10
             2         20
             3         30
             4         40
    test@ORA10G>
    test@ORA10G> --
    test@ORA10G> -- the function code could be rewritten as follows
    test@ORA10G> --
    test@ORA10G> select household_id,
      2         ltrim(sys_connect_by_path(rd,','),',') payment_dates
      3    from
      4  (
      5  select household_id,
      6         to_char(received_date,'mm/dd/yy') as rd,
      7         row_number() over (partition by household_id order by 1) rn,
      8         count(*) over (partition by household_id) cnt
      9    from monetary_trans
    10    -- and the constraints here in the where clause
    11  )
    12  where level = cnt
    13  start with rn = 1
    14  connect by prior household_id = household_id
    15  and prior rn = rn - 1
    16  and household_id = 1 -- <== this is the input parameter value
    17  ;
    HOUSEHOLD_ID PAYMENT_DATES
               1 12/28/08,12/29/08,12/30/08
    test@ORA10G>
    test@ORA10G> --
    test@ORA10G> -- and can be used as an inline view when joined with other tables
    test@ORA10G> --
    test@ORA10G> select t.y,
      2         fn.payment_dates
      3    from t,
      4         (select household_id,
      5                 ltrim(sys_connect_by_path(rd,','),',') payment_dates
      6          from (select household_id,
      7                       to_char(received_date,'mm/dd/yy') as rd,
      8                       row_number() over (partition by household_id order by 1) rn,
      9                       count(*) over (partition by household_id) cnt
    10                  from monetary_trans)
    11          where level = cnt
    12          start with rn = 1
    13          connect by prior household_id = household_id
    14          and prior rn = rn - 1
    15         ) fn
    16   where t.x = fn.household_id
    17  ;
             Y PAYMENT_DATES
            10 12/28/08,12/29/08,12/30/08
            20 12/31/08,01/01/09
    test@ORA10G>
    test@ORA10G>HTH
    isotope

  • Calling Anonymous block from VO

    Hi All,
    I have an Anonymous block which contains Record types, table types, functions, and procedure. Procedure returns multiple rows using all functions and types. I want to display those rows in Advanced table in OAF page. Please suggest methods to get this done.
    Thanks in advance.
    Kaushik Rambhiya

    Hi Kaushik ,
    You can make use of Prepared statment or Callable statement (both are Java API's ) to call an pl/sql block .
    Regards ,
    Keerthi

  • Help for anonymous block

    hi friends
    I am trying to develop anonymous block which display the message on screen like "hello world" "today is SYSDATE" and "Tommorow is SYSDATE+1".For that i try to develop anonymous block but it shows me error..so friends can you help me out with this...
    set SERVEROUTPUT on
    declare
    p_text varchar2 DEFAULT 'hello world';
    P_date date Default sysdate;
    P_next_date date default sysdate+1;
    begin
    DBMS_OUTPUT.PUT_LINE (||P_text);
    DBMS_OUTPUT.PUT_LINE ('today is:'||P_date);
    DBMS_OUTPUT.PUT_LINE ('Tommorrow is:'||p_next_date);
    end;
    thanks in advance
    rommy

    Hi, Rommy,
    Always format your code. Indent to show the major sections (DECLARE, BEGIN, etc.)
    Type these 6 characters
    &#123;code&#125;
    (small letters only, inside curly brackets) before and after formatted text, to preserve spacing when posting on this site.
    DECLARE
         p_text          VARCHAR2 (50)  DEFAULT 'hello world';
         P_date          DATE            DEFAULT SYSDATE;
         P_next_date     DATE            DEFAULT SYSDATE + 1;
    BEGIN
         DBMS_OUTPUT.PUT_LINE (P_text);
         DBMS_OUTPUT.PUT_LINE ('today is: ' || TO_CHAR (P_date, 'Dy DD-Mon-YYYY'));
         DBMS_OUTPUT.PUT_LINE ('Tommorrow is: ' || TO_CHAR (p_next_date, 'Dy DD-Mon-YYYY'));
    END;
    /When you declare a VARCHAR2 variable, you have to specify the maximum length.
    The || operator is used between two string expressions; it looks like you forgot the first operand in one place.
    Using a DATE where a VARCHAR2 is expected (as an operand to ||, for example) is not technically an error, but it's bad practice. Use TO_CHAR to create a string in whatever format you want.

  • Need help displaying item based on pl/sql anonymous block

    This is probably something really simple but I'm stuck.....
    On purchase order, I want to show related parent project name and ID. What is the best way to do it? I have created a region based on pl/sql anonymous block, and that works, but the data is above where I want it. I want the project name and ID to show up in the region w/ all the other fields.
    I have created an item in the region that has other form fields, item is based on pl/sql anonymous block, w/ same code as above region, and the item doesn't find the data. What's the difference? Is it because the item doesn't save state? In order to choose for the item to be based on pl/sql anon block, APEX made me choose Display as Text (based on PLSQL, does not save state).
    Please see this picture:
    http://farm3.static.flickr.com/2391/2658673285_04f157a3fa_o.png
    thanks!
    ~Darby

    this is weird.. Now it is working. I didn't change anything! What the heck?
    http://farm3.static.flickr.com/2010/2659557520_73e54b67ea_o.png

Maybe you are looking for

  • Move media from external hard drive

    External Hard drive to itunes: I put all my music, audiobooks, tv shows, movies into a separate folders under the "Itunes Media". I also have the xml and database files on my external hard drive as well. I just purchased a new computer, and I don't w

  • A good stand for MacBook?

    I apologize if there's a thread for this already- but just a quick question. I am looking to buy a stand that allows me to hold my MacBook actually in my lap. I don't really want anything huge that attaches to the bed or anything, but any suggestions

  • Wireless Internet Connection questions

    Hello everyone, Im using a Linksys wireless router its located in my room, My roommates room is located about 75 feet from mine, We are both Gamers and in his room he is constantly getting disconnected, high latency and slow connection. I was wonderi

  • Missing characters in XML-result

    Hi all, on 23-12-1999 Vadim posted the following message. He did not get a satisfactory answer and as i have the same problem when using dbms_output (both in SQL+ and with TOAD) i post this one again. The problem is that a character is missing and th

  • Datagrid: Custom Itemrenderer

    Hello, my Datagrid consists of a variable number of columns that are handled by the same Itemrenderer. Now I have the problem that I can't find out which column I belong to when I am in the override set data function. Any hints how i can back track t