Case with select into and sub query

hi im trying to use case and select with sebqueries, but my beginer like understanding of syntax fails me. can someone point out what im doing wrong in the case select below. im using select into, as i ultimatly need to load a ref cursor for use with crystal reports.
thanks
james
ps if anyone is london based, and would like to spend a day or two teaching me how to be a bit better at PL/SQL (can aford to pay a little bit) please get in touch!!
SELECT
Case (select kind_code from event where                    
event.event_id = event.container_event_id)     
when 1094006
then          promo_name     
end
into      result
FROM promo,     promo_plan ,     event_promotion
WHERE      promo.promo_id = promo_plan.promo_id
AND     promo_plan.promo_plan_id = event_promotion.promo_plan_id
AND     event_promotion.detail_id = '33532282'
when blah then 'blah';

Hello
AH i see what you are driveing at, yes i am just using case slect to determin which >routine to run, as the name is stored in a diferent location depending on the event kind >code. are are you saying i need multiple selects within the case statment? one for each >type of kind code?Well it depends really. If the select
select kind_code from event where
event.event_id = event.container_event_idIs going to return more than one row for any given run, you're going to need to take a bit of a different approach. Is it the case that this query will return more than one row which would mean that you want value X and value Y for each row?
Using the test data and everything from before:
SQL> CREATE OR REPLACE PROCEDURE p_GetStuff(ac_Result   OUT sys_refcursor)
  2  IS
  3
  4  BEGIN
  5     /*
  6             This uses a cartesian product i.e. repeat every row in
  7             dt_test_data against every row in dt_test_event
  8     */
  9     OPEN Ac_Result FOR
10     SELECT
11             CASE dt_test_event.kind_code
12             WHEN 1 THEN
13                     dt_test_data.object_name
14             WHEN 2 THEN
15                     dt_test_data.object_type
16             END
17     FROM
18             dt_test_data,
19             dt_test_event;
20
21  END;
22  /
Procedure created.
SQL> var x refcursor
SQL> exec p_getstuff(:x)
PL/SQL procedure successfully completed.
SQL> print x
CASEDT_TEST_EVENT.KIND_CODEWHEN1THENDT_TEST_DATA.OBJECT_NAMEWHEN2THENDT_TEST_DAT
ABC
ABC4
AD1
AD2
ADHOC_CONTACT_LOG
AK_CD_CLAIM_VALIDATION_SOURCE
AK_CD_CLAIM_VALIDATION_TYPE
AK_CLAIM_ACTION_ROWSOURCE
APPROVAL_LIST_MEM_IE
APPROVE_GRP_HIST_IE
10 rows selected.
SQL> insert into dt_test_event values(2);
1 row created.
SQL> exec p_getstuff(:x)
PL/SQL procedure successfully completed.
SQL> print x
CASEDT_TEST_EVENT.KIND_CODEWHEN1THENDT_TEST_DATA.OBJECT_NAMEWHEN2THENDT_TEST_DAT
ABC
ABC4
AD1
AD2
ADHOC_CONTACT_LOG
AK_CD_CLAIM_VALIDATION_SOURCE
AK_CD_CLAIM_VALIDATION_TYPE
AK_CLAIM_ACTION_ROWSOURCE
APPROVAL_LIST_MEM_IE
APPROVE_GRP_HIST_IE
TABLE
CASEDT_TEST_EVENT.KIND_CODEWHEN1THENDT_TEST_DATA.OBJECT_NAMEWHEN2THENDT_TEST_DAT
TABLE
TABLE
TABLE
TABLE
INDEX
INDEX
INDEX
INDEX
INDEX
20 rows selected.Or an alternative to that would be, if you have a fixed number of event ids and they relate to a fixed number of attributes you could use something like:
CREATE OR REPLACE PROCEDURE p_GetStuff3(ac_Result     OUT sys_refcursor)
IS
BEGIN
          The SUBSTR
          is just there to make sure the data fit on screen, my SQL*Plus
          is a bit weird!
     OPEN Ac_Result FOR
     SELECT
          SUBSTR(MAX(DECODE(dt_test_event.kind_code,1,dt_test_data.object_name,NULL)),1,30) attribute_1,
          SUBSTR(MAX(DECODE(dt_test_event.kind_code,2,dt_test_data.object_type,NULL)),1,30) attribute_2
     FROM
          dt_test_data,
          dt_test_event
     GROUP BY
          object_name;
END;
SQL> delete from dt_test_event where kind_code=2;
1 row deleted.
SQL> exec p_getstuff3(:x)
PL/SQL procedure successfully completed.
SQL> print x
ATTRIBUTE_1                    ATTRIBUTE_2
ABC
ABC4
AD1
AD2
ADHOC_CONTACT_LOG
AK_CD_CLAIM_VALIDATION_SOURCE
AK_CD_CLAIM_VALIDATION_TYPE
AK_CLAIM_ACTION_ROWSOURCE
APPROVAL_LIST_MEM_IE
APPROVE_GRP_HIST_IE
10 rows selected.
SQL> insert into dt_test_event values(2);
1 row created.
SQL> exec p_getstuff3(:x)
PL/SQL procedure successfully completed.
SQL> print x
ATTRIBUTE_1                    ATTRIBUTE_2
ABC                            TABLE
ABC4                           TABLE
AD1                            TABLE
AD2                            TABLE
ADHOC_CONTACT_LOG              TABLE
AK_CD_CLAIM_VALIDATION_SOURCE  INDEX
AK_CD_CLAIM_VALIDATION_TYPE    INDEX
AK_CLAIM_ACTION_ROWSOURCE      INDEX
APPROVAL_LIST_MEM_IE           INDEX
APPROVE_GRP_HIST_IE            INDEX
10 rows selected.Message was edited by:
david_tyler
Oops, copy + pasted the wrong comments for the 2nd proc.

Similar Messages

  • Syntax errors in update query with inner joins and sub query.

    Below is the query:
    UPDATE sp_CFQ_Coord_Corrections 
    INNER JOIN (CFQ_Coord_Corrections 
    INNER JOIN CFQ_Referrals ON CFQ_Coord_Corrections.CorrID = CFQ_Referrals.RecID) 
    ON sp_CFQ_Coord_Corrections.ID = CFQ_Referrals.RecID 
    SET CFQ_Coord_Corrections.MatchFound = 1, 
    CFQ_Coord_Corrections.RecTblID = [CFQ_Referrals].[RecTblID], 
    sp_CFQ_Coord_Corrections.MatchFound = 1
    WHERE (((CFQ_Coord_Corrections.MatchFound)=0) 
    AND ((sp_CFQ_Coord_Corrections.MatchFound)=0) 
    AND ((CFQ_Coord_Corrections.RecImported)=1) 
    AND ((CFQ_Referrals.RecFileName)='COORDCORR_SPOINT') 
    AND ((CFQ_Referrals.RecCombKey)='No.Match') 
    AND ((sp_CFQ_Coord_Corrections.RecImported)=1));
    Error messages seen when executed:
    Msg 156, Level 15, State 1, Line 3
    Incorrect syntax near the keyword 'INNER'.
    Msg 102, Level 15, State 1, Line 10
    Incorrect syntax near 'CFQ_Coord_Corrections'.
    Please help.....

    Below is the query:
    UPDATE sp_CFQ_Coord_Corrections 
    INNER JOIN (CFQ_Coord_Corrections 
    INNER JOIN CFQ_Referrals ON CFQ_Coord_Corrections.CorrID = CFQ_Referrals.RecID) 
    ON sp_CFQ_Coord_Corrections.ID = CFQ_Referrals.RecID 
    SET CFQ_Coord_Corrections.MatchFound = 1, 
    CFQ_Coord_Corrections.RecTblID = [CFQ_Referrals].[RecTblID], 
    sp_CFQ_Coord_Corrections.MatchFound = 1
    WHERE (((CFQ_Coord_Corrections.MatchFound)=0) 
    AND ((sp_CFQ_Coord_Corrections.MatchFound)=0) 
    AND ((CFQ_Coord_Corrections.RecImported)=1) 
    AND ((CFQ_Referrals.RecFileName)='COORDCORR_SPOINT') 
    AND ((CFQ_Referrals.RecCombKey)='No.Match') 
    AND ((sp_CFQ_Coord_Corrections.RecImported)=1));
    Error messages seen when executed:
    Msg 156, Level 15, State 1, Line 3
    Incorrect syntax near the keyword 'INNER'.
    Msg 102, Level 15, State 1, Line 10
    Incorrect syntax near 'CFQ_Coord_Corrections'.
    Please help.....
    sp_CFQ_Coord_Corrections is a table and not a stored procedure.
    are these both tables "sp_CFQ_Coord_Corrections" and "CFQ_Coord_Corrections" different ??

  • Hi! Everyone, I have some problems with JOIN and Sub-query; Could you help me, Please?

    Dear Sir/Madam
    I'm a student who is interested in Oracle Database and
    I have some problems with JOIN and Sub-query.
    I hope so many of you could help me.
    if i use JOIN without sub-query, may it be faster or not?
    SELECT field1, field2 FROM tableA INNER JOIN tableB
    if i use JOIN with sub-query, may it be faster or not?
    SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
    Thanks in advance!

    Hi,
    fac30d8e-74d3-42aa-b643-e30a3780e00f wrote:
    Dear Sir/Madam
    I'm a student who is interested in Oracle Database and
    I have some problems with JOIN and Sub-query.
    I hope so many of you could help me.
    if i use JOIN without sub-query, may it be faster or not?
    SELECT field1, field2 FROM tableA INNER JOIN tableB
    if i use JOIN with sub-query, may it be faster or not?
    SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
    Thanks in advance!
    As the others have said, the execution plan will give you a better idea about which is faster.
    If you're trying to see how using (or not using) a sub-query affects performance, make the rest of the queries as similar as possible.  For example, include field3 in both queries, or ignore field3 in both queries.
    In this particular case, I guess the optimizer would do the same thing either way, but that's just a guess.  I can't see your execution plans.
    In general, simpler code is faster, and better in other ways, too.  In this case
    tableB
    is simpler than
    (SELECT field1, field2  FROM tableB)
    Why do you want a sub-query in this example?

  • Dynamic Pivot with Select Into

    I have this Dynamic Pivot which works fine.
    DECLARE @query VARCHAR(4000)
    DECLARE @years VARCHAR(2000)
    SELECT @years = STUFF(( SELECT DISTINCT'],[' + [factor_label]
    FROM [TEMP_lacp_factors]
    ORDER BY '],[' + [factor_label]
    FOR XML PATH('')
    ), 1, 2, '') + ']'
    SET @query =
    'SELECT * FROM
    SELECT [date_],[issue_id],[cusip],[Factor_value],[factor_label]
    FROM [TEMP_lacp_factors]
    )t
    PIVOT (MAX([factor_value]) FOR [factor_label]
    IN ('+@years+')) AS pvt'
    EXECUTE (@query)
    I'm trying to take the results of that and do a SELECT INTO, so I can move the results to another table.  Is this possible?  I didn't find a whole lot online.
    The error that I'm getting is this.
    Caused by: Column name or number of supplied values does not match table definition.
    How can I do this?  Is it even possible?
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Sure, you can create a table with SELECT INTO, but it cannot be a #temptable. Well, it can be a #temptable, but it will disappear as soon as you exit the scope it was created it, that is the dynamic SQL.
    The question is only, what would you do with this table later? Since you don't know the column names, about all work will have to be done through dynamic SQL.
    A dynamic pivot is a non-relational operation. A SELECT statement produces a table, and a table describes a distinct entity, of which the column are distinct and well-defined attributes. Something which your dynamic pivot does not adhere to.
    There is only one thing you can do with your dynamic pivot: returning the data to the client. I don't know what you want to do with that table, but probably you should do that manipulation before the dynamic pivot, because as I said: that is always your
    last step.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Detail differentiation between add query,combined query and sub query

    HI
    I would like to know the detail differentiation between add query,combined query and sub query with  universe
    correct me if I a wrong
    Add query : adding of different query from different universe and also with in same universe.
    Combined query : combining query using operators(Union,intersection,minus)with in same universe.
    Sub query :getting results from the sub query and the result serves as the data for main  query within same universe.

    Hi,
    I would advise you to check the product documentation under http://help.sap.com/
    regards
    Steph

  • Problem with different resultset with same data and same query in Oracle 8.1.7 and 9i

    Hello,
    I have been using this query in oracle 8.1.7
    SELECT
    ID,
    AREA_NO
    FROM MANAGER_AREA MGR
    WHERE COMPANY_ID = :id AND
    (:value < (SELECT COUNT(ROWID)
    FROM MANAGER_WORK MW
    WHERE MW.AREA_ID = MGR.ID AND
    (MW.END_WORK IS NULL OR MW.END_WORK >= SYSDATE)))
    order by AREA_NO;
    In the above query I want to see rows from MANAGER_AREA table depending upon date criteria in the table MANAGER_WORK and also upon the parameter :value i.e if I pass a value as 0 I get to see records for which their is atleast 1 record in MANAGER_WORK with the date criteria and if I pass -1 then I get all the records because minimum value that count(*) would give is 0. The resultset was as expected in 8.1.7.
    A couple of days back I installed PERSONAL 9i to test for testing the basic functionality of our program with the same data. This query fails and irrespective whether I pass -1 or 0 it returns me same dataset which I would have got in case if I pass 0.
    I do not know whether this is a bug that has got introduced in 9i. Can anybody help me with this problem. It would be difficult for me to change the parameter send to this query as the Query is called from many different places.
    Thanks in advance
    Amol.

    I cannot use a Group by and a having statement over here. The problem with 'Group by' and 'having' clause is If I have to make a join between the two tables. When I use join then I get only rows that are linked to each other in the table.
    If I use outer join to solve that problem then I have to take in consideration the other date condition. My previous query use to virtually discard the corelated query result by using -1 as the value. This will not happen in the join query.
    Amol.

  • Discrepancy between Select Expert and SQL Query

    Greetings.  I am having an issue with a report, but I think it's more cosmetic and may not be causing a functional issue...
    When I go into the Report...Select Expert...Record, I see that my criteria for the report is .AND. logic.
    When I go into the SQL Query view, it shows .OR. logic...
    After I verify the database, the SQL query still does not get updated.  Saving and re-opening the report still does not update. 
    Is there any reason this will never match?  Thanks in advance.

    Sorry.  I am on Crystal 12.  Database is SQL 2005.
    I didn't think the detail mattered much, but the select expert shows:
    isnull({NONCONFORMANCE.CLOSED_DATE}) and
    not isnull({NONCONFORMANCE.PRODUCT_ID}) and
    not({NONCONFORMANCE.PRODUCT_ID}= '') and
    not({NONCONFORMANCE.PRODUCT_ID}= ' ')
    SELECT N.NCM_ID, N.NCM_DATE, N.PRODUCT_ID, N.CLOSED_DATE, N.ENTITY_ID
    FROM   NONCONFORMANCE N
    WHERE  N.CLOSED_DATE IS  NULL  AND N.PRODUCT_ID IS  NOT  NULL  AND  NOT (N.PRODUCT_ID='' OR N.PRODUCT_ID=' ') AND N.ENTITY_ID='CHI'
    Now that I look at how the SQL is generated (after cleaning up the statement), it's the negatives that got me.  I originally had a problem with the report that was pulling back blanks and spaces.  I made changes and I didn't pay close enough attention to what exactly changed in the SQL...  It appears to be the way the logic in the Select Expert is converted to SQL.
    I just need to start using Command more often and write my own SQL instead of using the Select Expert!!!

  • Dynamic SQL and Sub Query

    I want need to use dynamic SQL, and include a subquery in the where clause.  However, I am getting a syntax error.
    I have code that looks like this.
        SELECT (p_v_sqlobj_select)
            INTO CORRESPONDING FIELDS OF TABLE <matrix>
          FROM (p_v_sqlobj_from)
          WHERE (p_v_sqlobj_where).
    and I pass it the following bold-faced SQL where clause (please ignore whether the statement makes sense and is the best way to do it - this is just to illustrate).   However, it returns an error.
    select tcode from tstc where tcode in <b>( select min( tcode ) as min from tstc )</b>
    Am I correct in concluding that I cannot pass complex statements, or have I just missed something?
    Thanks for any help.

    Hi,
    Please try with order by clause in select statement and also use descending
          select * from (p_table)
                   into corresponding fields of table <ptab>
                  up to p_rows rows
                  order by <fieldname> descending.
    aRs

  • Dynamic column name with SELECT INTO

    I am trying to build a function that derives a pay amount from a set of business rules. There are about 40 columns that hold various pay amounts and their column names are variations of 4 indicators (day shift, vs night shift, etc.) that I have to dynamically look up, ie here is the ID number and a timecard, now figure out which of the 40 fields to look up to get the pay amount.
    I can determine from the timecard and employee ID which field to look at, but I'm getting hung up with the syntax needed to construct and execute the statement inside the PL/SQL block. I need to RETURN the pay I extract using the function, and I can create the correct SQL statement, but the EXECUTE IMMEDIATE won't accept the SELECT INTO syntax.
    Can someone please suggest a solution? Here is the function:
    create or replace FUNCTION FN_GET_PAYRATE(tc in NUMBER, e in NUMBER, pc in VARCHAR2)
    RETURN NUMBER
    IS
    e_id NUMBER;
    tc_id NUMBER;
    pl_cd VARCHAR2(7);
    shft VARCHAR2(2);
    lvl VARCHAR2(2);
    typ VARCHAR2(2);
    e_typ VARCHAR2(4);
    proj NUMBER;
    hrly VARCHAR2(4);
    payrt NUMBER;
    var_col VARCHAR2(10);
    sql_select VARCHAR2(200);
    sql_from VARCHAR2(200);
    sql_where VARCHAR2(200);
    sql_and1 VARCHAR2(200);
    sql_and2 VARCHAR2(200);
    sql_and3 VARCHAR2(200);
    sql_orderby VARCHAR2(200);
    var_sql VARCHAR2(2000);
    BEGIN
    e_id := e;
    tc_id := tc;
    pl_cd := pc;
    SELECT NVL(SHIFT,'D') INTO shft
    FROM TS_TIMECARD_MAIN
    WHERE TIMECARD_ID = tc_id;
    --DBMS_OUTPUT.PUT_LINE('SHIFT= ' || shft);
    SELECT NVL(PAY_LVL, 1), NVL(PAY_TYPE, 'B'), NVL(RTRIM(EMP_TYPE), 'LHD'), NVL(PROJECT, 001)
    INTO lvl, typ, e_typ, proj
    FROM TS_EMPLOYEES
    WHERE EMP_ID = e_id;
    --DBMS_OUTPUT.PUT_LINE('Level= ' || lvl);
    --DBMS_OUTPUT.PUT_LINE('PAY_TYPE= ' || typ);
    --DBMS_OUTPUT.PUT_LINE('EMP_TYPE= ' || e_typ);
    --DBMS_OUTPUT.PUT_LINE('PROJECT= ' || proj);
    IF e_typ <> 'LHD' THEN
    hrly := 'H';
    ELSE
    hrly := '';
    END IF;
    IF proj <> 001 THEN
    var_col := shft || lvl || typ || hrly;
    --DBMS_OUTPUT.PUT_LINE('RATE COLUMN= ' || var_col);
    sql_select := 'SELECT NVL(' || var_col || ', .01) INTO payrt';
    sql_from := ' FROM TS_PAYRATES';
    sql_where := ' WHERE PROJECT_ID = ' || proj;
    sql_and1 := ' AND ACTIVE = 1';
    sql_and2 := ' AND JOB_TYPE = ' || CHR(39) || e_typ || CHR(39);
    sql_and3 := ' AND PILE_ID = ' || CHR(39) || pl_cd || CHR(39);
    var_sql := sql_select || sql_from || sql_where || sql_and1 || sql_and2 || sql_and3 || sql_orderby;
    DBMS_OUTPUT.PUT_LINE('SQL: ' || var_sql);
    EXECUTE IMMEDIATE var_sql;
    DBMS_OUTPUT.PUT_LINE('RATE= ' || payrt);
    RETURN payrt;
    ELSE
    DBMS_OUTPUT.PUT_LINE('ERROR');
    RETURN 1;
    END IF;
    END;
    I have alternately tried this:
    SELECT NVL(var_col,.01) into payrt
    FROM TS_PAYRATES
    WHERE PROJECT_ID = proj AND ACTIVE = 1
    AND JOB_TYPE = CHR(39) || e_typ || CHR(39)
    AND PILE_ID = CHR(39) || pl_cd || CHR(39);
    as a substitute for the EXECUTE IMMEDIATE block, but I can't seem to use a dynamic substitution for the column name.
    Any help would be greatly appreciated.

    That's the most difficult part - the error messages seem to indicate a problem with the SQL statement in its execution context, because I can take the SQL string by itself and it executes perfectly.
    Here are three variations:
    SELECT INTO
    select fn_get_payrate(21555, 30162, 15) from dual
    ERROR at line 1:
    ORA-00905: missing keyword
    ORA-06512: at "PEOPLENETIF.FN_GET_PAYRATE", line 60
    SQL: SELECT NVL(N4P , .01) INTO payrt FROM TS_PAYRATES WHERE PROJECT_ID = 701 AND ACTIVE = 1 AND JOB_TYPE = 'LHD' AND PILE_ID = '15'
    Without SELECT INTO  (returns NULL)
    SQL> select fn_get_payrate(21555, 30162, 15) from dual;
    FN_GET_PAYRATE(21555,30162,15)
    SQL: SELECT NVL(N4P , .01) FROM TS_PAYRATES WHERE PROJECT_ID = 701 AND ACTIVE = 1 AND JOB_TYPE = 'LHD' AND PILE_ID = '15'
    RATE=
    EXECUTE IMMEDIATE USING
    SQL> select fn_get_payrate(21555, 30162, 15) from dual;
    select fn_get_payrate(21555, 30162, 15) from dual
    ERROR at line 1:
    ORA-01006: bind variable does not exist
    ORA-06512: at "PEOPLENETIF.FN_GET_PAYRATE", line 61
    SQL: SELECT NVL(N4P , .01) FROM TS_PAYRATES WHERE PROJECT_ID = 701 AND ACTIVE = 1 AND JOB_TYPE = 'LHD' AND PILE_ID = '15'

  • Help with select into please

    Good morning everyone,
    I have a problem with my function. I need to do the dynamic select with the SELECT INTO
    create or replace function prueba (p_param IN VARCHAR2) RETURN VARCHAR2
    IS
    v_aux1 VARCHAR2(200);
    v_aux2 VARCHAR2(200);
    BEGIN
    SELECT col1
    INTO v_aux1
    FROM my_table
    WHERE col2 = p_param; --UNION SELECT '1233' FROM DUAL;
    RETURN v_aux1;
    EXCEPTION
    WHEN OTHERS THEN
    RAISE_APPLICATION_ERROR(-20000,SQLERRM );
    --RETURN v_aux2;
    END;
    When I try to call my function with the golden as follows:
    select (prueba('''MON'' UNION SELECT '||chr(039)||'12'||chr(039)||' FROM DUAL')) from dual
    OR
    select (prueba(chr(039)||'MON'||chr(039)||' UNION SELECT '||chr(039)||'12'||chr(039)||' FROM DUAL')) from dual
    I get the error: no data found
    If I use the sentence in Golden or SQLPLUS as follows:
    SELECT col1
    -- INTO aux1
    FROM my_table
    WHERE despaise = 'MON' UNION SELECT '12' FROM DUAL
    It ´s correct, and it return '1233'
    The value 'MON' no exists in my_table.
    If uncommented the sentence "UNION SELECT '1233' FROM DUAL" in my function an I use 'MON' as parameter it´s correct.
    How I can do this using the parameter with the UNION?.
    Thank you very much to all and sorry for my english

    Hi,
    welcome to the forum.
    Please read SQL and PL/SQL FAQ
    When you put some code or output please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    you cannot pass static SQL as part of the string.
    When you call the procedure in either wayselect (prueba('''MON'' UNION SELECT '||chr(039)||'12'||chr(039)||' FROM DUAL')) from dual
    select (prueba(chr(039)||'MON'||chr(039)||' UNION SELECT '||chr(039)||'12'||chr(039)||' FROM DUAL')) from dual
    This result in passing a whole string to your function as'MON' UNION SELECT '12' FROM DUAL
    which translates in your code asSELECT col1
    INTO v_aux1
    FROM my_table
    WHERE col2 = '''MON'' UNION SELECT ''12'' FROM DUAL'
    So it is searching a rows having col2 with value  '''MON'' UNION SELECT ''12'' FROM DUAL'
    Please try to explain what you are trying to achieve and we may help you.
    You could use dynamic SQL to do that but it is not clear what are your business requirement and the approach that you are using does not seem to be correct.
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Report with select list and link to call another report

    Hi,
    I am trying to do 2 reports (REPORT1 and REPORT2).
    The first is a summary report (REPORT1).
    This report will display sales figures for the year. Now, I need to have a select list in the result set that will have 2 options, depending on which option is chosen, I want to call REPORT2 with the select list as a parameter. How can I do this ?
    Let me try to explain what I did.
    I created REPORT1 on Page 100
    SELECT YEAR, sum(YTD_SALES), APEX_ITEM.SELECT_LIST(1,'DEPARTMENT','Department;DEPARTMENT,Division;DIVISION') Drilldown FROM SALES_ANALYSIS WHERE YEAR > 2000
    GROUP BY YEAR ORDER BY YEAR
    I created 2 hidden items namely P100_YEAR and P100_DRILLDOWN
    I also made the column YEAR as a link and specified both P100_YEAR and P100_DRILLDOWN as parameters to be passed.
    Next, I created REPORT2
    SELECT YEAR, DECODE(:P100_DRILLDOWN, 'Department', department, 'Division', Division) dept_div, sum(YTD_SALES) ytd_sales
    FROM SALES_ANALYSIS
    WHERE YEAR = :P100_YEAR
    When I run Report 1, it's fine, when I choose either Department or Division from the Select List and click on the link to call Report 2, report 2 is displayed, but the value being passed for P100_DRILLDOWN is not correct and as a result, I am unable to get correct results for Report 2
    Am I missing something ? Are there any alternate ways to do what I'm doing ?
    Thanks,
    Ashok

    Hi Ashok,
    The link definition will not know the value selected in the list as it is constructed only when the page is being rendered. You would need to create some javascript to handle this. I've done that here: [http://apex.oracle.com/pls/otn/f?p=267:182]
    The link on the EMPNO column has been defined in the HTML Expression setting for the column instead of the Link section. The HTML Expression that I have used is:
    &lt;a href="#" onclick="javascript:doDrilldown('#EMPNO#',this);"&gt;#EMPNO#&lt;/a&gt;And, in the page's HTML Header setting, I have added in:
    &lt;script type="text/javascript"&gt;
    function doDrilldown(empno,group)
    var g;
    var p = group.parentNode;
    while (p.tagName != "TR")
      p = p.parentNode;
    var x = p.getElementsByTagName("SELECT");
    if (x.length &gt; 0)
      g = x[0].value;
    var url = "f?p=&APP_ID.:183:&SESSION.::::P183_EMPNO,P183_GROUP:" + empno + "," + g;
    document.location.href = url;
    &lt;/script&gt;When a link is clicked, the doDrilldown function is called passing in the EMPNO value and the "this" object (which identifies the object triggering the call). The function starts from that object and goes up in the HTML tag tree to the nearest TR tag (the row tag that the link is on) and then finds the first SELECT list item on the row and gets its value. It then constructs a URL using this and the EMPNO value and performs a redirect to the second page (page 183 in this example).
    Andy

  • Problem with call transaction and a query

    Hi,
    Whe have a query that has its own Z tcode, we are working with this "EXIT_SAPLCORF_103"  within the tcode CO11N. Inside the include "ZXCOFU13" we call the query Tcode and it is displayed on screen but with no data.
    The table "itbdcdata" record well the data of the inputs in the query recording so you can see with the WERKS and the number of reserve (3994) in the recording.
    Why the call transaction display the query screen with no data...? and how can i pass the inputs to the query screen so it be executed.
    Thanks on advance.
    David Fúnez
    Tegucigalpa, Honduras.
    This is the recording:
    AQZZZ_USER_GRMA=Z_QUERY_PP_003     1000X                                                                                BDC_CURSOR     SP$00002-LOW
                                                                BDC_OKCODE     =CRET
                                                                S_WERKS-LOW     1202
                                                                SP$00002-LOW           3994
                                                                %ALV     X
    this is the code in the INCLUDE
    *&  Include           ZXCOFU13
    DATA: itbdcdata TYPE bdcdata    OCCURS 0 WITH HEADER LINE,
          optoption TYPE ctu_params.
    REFRESH itbdcdata.
    CLEAR   itbdcdata.
    itbdcdata-program  = 'AQZZZ_USER_GRMA=Z_QUERY_PP_003'.
    itbdcdata-dynpro   = '1000'.
    itbdcdata-dynbegin = 'X'.
    APPEND itbdcdata.
    itbdcdata-fnam = 'BDC_CURSOR'.
    itbdcdata-fval = 'SP$00002-LOW'.
    APPEND itbdcdata.
    itbdcdata-fnam = 'BDC_OKCODE'.
    itbdcdata-fval = '=CRET'.
    APPEND itbdcdata.
    itbdcdata-fnam = 'S_WERKS-LOW'.
    itbdcdata-fval = '1202'.
    APPEND itbdcdata.
    itbdcdata-fnam = 'SP$00002-LOW'.
    itbdcdata-fval = caufvd_imp-rsnum.
    APPEND itbdcdata.
    itbdcdata-fnam = '%ALV'.
    itbdcdata-fval = 'X'.
    APPEND itbdcdata.
    CLEAR optoption.
    optoption-dismode = 'A'. "A is visible
    optoption-updmode = 'S'.
    CALL TRANSACTION 'ZRESV' USING itbdcdata OPTIONS FROM optoption.

    problem solved.

  • Compile .air with selected files and folders

    Can i complie selected files and folders from php so i can get dynamic .air files
    so e.g
    i have 4 different css
    1 css for 1 .air
    2 css for 2.air
    and so on

    Hi,
    If I understand your question correctly, you should be able to do this by writing a script and interacting with ADT via it's command line arguments.  In particular, check out the "Package and Sign an AIR file in one step" section in the Packaging an AIR installation file document.
    Hope this helps,
    Chris

  • Recommendation for case with a clip and protection on all sides, snug fit.

    I'm looking for a case with protection on all sides, with a clip, with a snug fit -- i.e., not designed for ever make / model (not one size fits all). I bought the case at the Apple store with a clip and a snap, but the top of the phone is mostly unprotected (uncovered) and I don't like the flap with the snap because it does not close correctly unless I stop what I'm doing and look at it to make sure the snap lines up (i.e., the flap has too much extra material and does not line up automatically with the snap).

    Otterbox Defender case which provides excellent protection and probably the best protection of all available cases which includes a clip.

  • Problem with SELECT INTO Query

    Why am I always getting 0 for returnvalue in the following query?
    create or replace
    PACKAGE BODY MyPKG AS
    PROCEDURE SelectCount
       returnvalue       OUT      INTEGER
    AS
      BEGIN
    select COUNT(*) from MyTable into returnvalue;
    IF( SQL%ROWCOUNT >= 1 )
      THEN
        returnvalue := 1;
      ELSE
        returnvalue := 0;
      END IF; 
    dbms_output.put_line('returnvalue: ' || returnvalue);
    END SelectCount;
    END MyPKG ;

    Hi,
    When you use an aggregate function, such as COUNT, without a GROUP BY clause, then the query is guaranteed to return exactly 1 row, regadless of whether there are any rows in the table or not.
    Perhaps you meant:
    create or replace
    PACKAGE BODY MyPKG AS
    PROCEDURE SelectCount
       returnvalue       OUT      INTEGER
    AS
      BEGIN
          select COUNT(*) from MyTable into returnvalue;
          dbms_output.put_line('returnvalue: ' || returnvalue);
      END SelectCount;
    END MyPKG ;
    that is, simply lose the IF block.

Maybe you are looking for

  • Oracle VM 3.0, SSDs and hard partitioning

    I am new to virtualization and especially Oracle VM. We have been waiting for Oracle VM 3.0 to come out so that we can build 64 bit hardware drivers (as opposed to 32 Bit in Dom0 on OVM 2.x) for Fusion IO solid state PCI based accelerator cards. Our

  • Sto process find vendor and customer

    we are Creating STO with ME27 tcode from one plant to another plant ie from A120 to S122. Already the configurations are done by someone. Now i took the purchase order xxxxx and open in me23n. As per the process we need to Assign  vendor to Deliverin

  • TFS 2013 Upgrade 3 Admin Console hangs

    Hi, I upgraded TFS 2013 to TFS 2013.3 and it worked ok for few days. Now when i try to access TFS Admin Console it hangs. When I try to access through TWA its d same problem. I did a)Recycle App pool b)Restart the TFS site c)Reboot the server  yet I

  • Importing huge (10 million rows) tables into HANA

    Dear All, i need to import huge tables (40.000.000 records)  into an HANA system, in order to develop a demo system for a customer. I'm planning to use CSV files. Does someone have experience in a task like this? is there a limit to CSV file dimensio

  • HELP - SquirrelMail web login error - PLEASE HELP!!

    When users go to login to the web interface of squirrelmail, they now get the following error. Warning: includeonce(../plugins/imagebuttons/config.php): failed to open stream: No such file or directory in /usr/share/squirrelmail/plugins/image_buttons