Cursor based on variable?

I posted this issue in the APEX forum since I call my procedure through APEX, but I'm including it in here as well since the issue is with my cursor/loop:
In APEX, I have a process that calls apex_mail. I have a cursor/loop that pulls records meeting my criteria and lists them in the body of the mail. This all works. However, I added another field (field b) which in the app is dependent on field a. Rather than having 11 cursors defined that run according to my 'if' statements, I would like one cursor that is equal to the end result of my variable (v_sql). When I run the code below, I receive the following error: ORA-06550: line 11, column 22: PLS-00382: expression is of wrong type ORA-06550: line 11, column 3: PL/SQL: Statement ignored ORA-06550: line 68, column 18: PLS-00221: 'GATHER_USRS_CUR' is not a procedure or is undefined ORA-06550: line 68, column 3: PL/SQL: Statement ignored.
Code:
declare
e_body_1 CLOB;
e_body_2 CLOB;
j_sql CLOB :=null;
v_sql varchar2(2000);
-- Define cursor as SYS_REFCURSOR?
gather_usrs_cur SYS_REFCURSOR;
BEGIN
-- make cursor equal to variable of v_sql
gather_usrs_cur := v_sql;
-- Generate body of e-mail
e_body_1 := 'This e-mail is being generated to inform you that ... Those users are: '||utl_tcp.crlf||utl_tcp.crlf;
e_body_1 := e_body_1||'USER ID, FIRST, LAST, PHONE, E-MAIL'||utl_tcp.crlf;
e_body_1 := e_body_1||'==================================='||utl_tcp.crlf;
e_body_2 := utl_tcp.crlf||'Please review the accounts identified above and inform us .... We appreciate your follow-up regarding the account activity in your State.'||utl_tcp.crlf||utl_tcp.crlf;
e_body_2 := e_body_2||'Should you have any concerns/questions, please respond to the e-mail members on this e-mail.'||utl_tcp.crlf||utl_tcp.crlf;
e_body_2 := e_body_2||' Sincerely,'||utl_tcp.crlf||utl_tcp.crlf;
e_body_2 := e_body_2||' Team'||utl_tcp.crlf;
-- Conditions for determing value of v_sql which would ultimately be reflected in cursor, gather_usrs_cur
v_sql := 'select Q_APEX_ID,
USER_ID,
Q_USER_TYPE,
Q_FIRST,
Q_LAST,
C_PHONE,
C_EMAIL,
C_STATE
from Q_AUDIT
where MATCH = ''Y'' and
UPDT_ID is null and
UPDT_TS is null and
COMMENTS is null and
Q_USER_TYPE = :P32_USER_TYPE ';
if :P32_RO_USER_TYPE <> 'ALL' then
if :P32_RO_USER_TYPE = 1 then
v_sql := v_sql ||' and C_STATE in (''CT'',''MA'',''ME'',''NH'',''RI'',''VT'') ';
end if;
if :P32_RO_USER_TYPE = 2 then
v_sql := v_sql ||' and C_STATE in (''NJ'',''NY'',''PR'',''VI'') ';
end if;
if :P32_RO_USER_TYPE = 3 then
v_sql := v_sql ||' and C_STATE in (''DE'',''DC'',''MD'',''PA'',''VA'',''WV'') ';
end if;
if :P32_RO_USER_TYPE = 4 then
v_sql := v_sql ||' and C_STATE in (''AL'',''FL'',''GA'',''KY'',''MS'',''NC'',''SC'',''TN'') ';
end if;
if :P32_RO_USER_TYPE = 5 then
v_sql := v_sql ||' and C_STATE in (''IL'',''IN'',''MI'',''MN'',''OH'',''WI'') ';
end if;
if :P32_RO_USER_TYPE = 6 then
v_sql := v_sql ||' and C_STATE in (''AR'',''LA'',''NM'',''OK'',''TX'') ';
end if;
if :P32_RO_USER_TYPE = 7 then
v_sql := v_sql ||' and C_STATE in (''IA'',''KS'',''MO'',''NE'') ';
end if;
if :P32_RO_USER_TYPE = 8 then
v_sql := v_sql ||' and C_STATE in (''CO'',''MT'',''ND'',''SD'',''UT'',''WY'') ';
end if;
if :P32_RO_USER_TYPE = 9 then
v_sql := v_sql ||' and C_STATE in (''AZ'',''CA'',''HI'',''NV'') ';
end if;
if :P32_RO_USER_TYPE = 10 then
v_sql := v_sql ||' and C_STATE in (''AK'',''ID'',''OR'',''WA'') ';
end if;
end if;
-- call and loop through cursor for body of e-mail
for usr_rec in gather_usrs_cur
loop
begin
j_sql := j_sql ||usr_rec.user_id||', '||usr_rec.Q_first||', '||usr_rec.Q_last||', '||usr_rec.C_phone||', '||usr_rec.C_email||utl_tcp.crlf;
end;
end loop;
commit;
-- Call mail procedure
apex_mail.send(
P_TO => :P32_E_RECIPIENT,
P_CC => '[email protected], [email protected]',
P_FROM => '[email protected]',
P_BODY => e_body_1||j_sql||e_body_2,
P_SUBJ => 'Q Accounts Requiring Review');
end;
Is it possible to create one cursor that is equal to the 11 possible combinations, based on v_sql? Note that the :P32_X variables are set via buttons/fields in my APEX application. Thanks in advance for your help.

I went ahead and rewrote this for you. Obviously I can't test it so no guarantees....
Are you putting this code directly in APEX? If so, notice how I took ":P32_USER_TYPE" out from being a literal in your string and put in a bind variable.
DECLARE
e_body_1 CLOB;
e_body_2 CLOB;
j_sql CLOB := NULL;
v_sql VARCHAR2 (2000);
usr_rec q_audit%ROWTYPE;
TYPE auditcurtype IS REF CURSOR;
v_audit_cur auditcurtype;
BEGIN
-- Generate body of e-mail
e_body_1 :=
'This e-mail is being generated to inform you that ... Those users are: '
|| UTL_TCP.crlf
|| UTL_TCP.crlf;
e_body_1 :=
e_body_1 || 'USER ID, FIRST, LAST, PHONE, E-MAIL' || UTL_TCP.crlf;
e_body_1 :=
e_body_1 || '===================================' || UTL_TCP.crlf;
e_body_2 :=
UTL_TCP.crlf
|| 'Please review the accounts identified above and inform us .... We appreciate your follow-up regarding the account activity in your State.'
|| UTL_TCP.crlf
|| UTL_TCP.crlf;
e_body_2 :=
e_body_2
|| 'Should you have any concerns/questions, please respond to the e-mail members on this e-mail.'
|| UTL_TCP.crlf
|| UTL_TCP.crlf;
e_body_2 := e_body_2 || ' Sincerely,' || UTL_TCP.crlf || UTL_TCP.crlf;
e_body_2 := e_body_2 || ' Team' || UTL_TCP.crlf;
-- Conditions for determing value of v_sql which would ultimately be reflected in cursor, gather_usrs_cur
v_sql :=
'select *
from Q_AUDIT
where MATCH = ''Y'' and
UPDT_ID is null and
UPDT_TS is null and
COMMENTS is null and
Q_USER_TYPE = :1';
IF :p32_ro_user_type <> 'ALL'
THEN
IF :p32_ro_user_type = 1
THEN
v_sql :=
v_sql
|| ' and C_STATE in (''CT'',''MA'',''ME'',''NH'',''RI'',''VT'') ';
END IF;
IF :p32_ro_user_type = 2
THEN
v_sql := v_sql || ' and C_STATE in (''NJ'',''NY'',''PR'',''VI'') ';
END IF;
IF :p32_ro_user_type = 3
THEN
v_sql :=
v_sql
|| ' and C_STATE in (''DE'',''DC'',''MD'',''PA'',''VA'',''WV'') ';
END IF;
IF :p32_ro_user_type = 4
THEN
v_sql :=
v_sql
|| ' and C_STATE in (''AL'',''FL'',''GA'',''KY'',''MS'',''NC'',''SC'',''TN'') ';
END IF;
IF :p32_ro_user_type = 5
THEN
v_sql :=
v_sql
|| ' and C_STATE in (''IL'',''IN'',''MI'',''MN'',''OH'',''WI'') ';
END IF;
IF :p32_ro_user_type = 6
THEN
v_sql :=
v_sql || ' and C_STATE in (''AR'',''LA'',''NM'',''OK'',''TX'') ';
END IF;
IF :p32_ro_user_type = 7
THEN
v_sql := v_sql || ' and C_STATE in (''IA'',''KS'',''MO'',''NE'') ';
END IF;
IF :p32_ro_user_type = 8
THEN
v_sql :=
v_sql
|| ' and C_STATE in (''CO'',''MT'',''ND'',''SD'',''UT'',''WY'') ';
END IF;
IF :p32_ro_user_type = 9
THEN
v_sql := v_sql || ' and C_STATE in (''AZ'',''CA'',''HI'',''NV'') ';
END IF;
IF :p32_ro_user_type = 10
THEN
v_sql := v_sql || ' and C_STATE in (''AK'',''ID'',''OR'',''WA'') ';
END IF;
END IF;
OPEN v_audit_cur FOR v_sql using :P32_USER_TYPE;
LOOP
FETCH v_audit_cur
INTO usr_rec;
EXIT WHEN v_audit_cur%NOTFOUND;
j_sql :=
j_sql
|| usr_rec.user_id
|| ', '
|| usr_rec.q_first
|| ', '
|| usr_rec.q_last
|| ', '
|| usr_rec.c_phone
|| ', '
|| usr_rec.c_email
|| UTL_TCP.crlf;
END LOOP;
CLOSE v_audit_cur;
-- No need for this, you aren't changing anything
-- COMMIT;
-- Call mail procedure
apex_mail.send (p_to => :p32_e_recipient,
p_cc => '[email protected], [email protected]',
p_from => '[email protected]',
p_body => e_body_1 || j_sql || e_body_2,
p_subj => 'Q Accounts Requiring Review'
END;
Hope this helps,
Steve
Alliance Technologies

Similar Messages

  • Fetch cursor with a variable column number

    Hello guys,
    this is the first time I write to this forum, as far as I remember. hence, if this is not the right place to ask this question, please point me to the right resource.
    I have the following Procedure (the function split splits a string into an array):
    BEGIN
    /* SPLIT IN GROUPS AND BUILD THE PARAMETER STRINGS */
    tokens_in := string_fnc.split(in_groups, '.');
    for i in 1..tokens_in.count loop
    IDX_REM := i;
    sql_par1 := sql_par1 || ', GRP' || i || '.NAME "GROUP_' || i || '"';
    sql_par2 := sql_par2 || ', DEV_XCSA.WFA_GROUP GRP' || i;
    IF i = 1 THEN
    sql_par3 := sql_par3 || ' AND S.ID = GRP1.FK_PARENT_SEC_ID ';
    ELSE
    sql_par3 := sql_par3 || ' AND GRP' || i || '.FK_PARENT_GROUP_ID ( + ) = GRP' || (i-1) || '.ID';
    END IF;
    end loop;
    sql_par3 := sql_par3 || ' AND SGQ.FK_GROUP_ID ( + ) = GRP' || IDX_REM || '.ID';
    /* BUILD THE QUERY STRING */
    sql_stmt := 'SELECT A.NAME "APPRAISAL" , AQ.NAME "PROJECT" , S.NAME "SECTION"';
    sql_stmt := sql_stmt || sql_par1;
    sql_stmt := sql_stmt || ', SGQ.NAME "QUESTION" , SGQ.VALUE "ANSWER"     FROM DEV_XCSA.WFA_APPRAISAL A, DEV_XCSA.WFA_QUESTIONNAIRE AQ, DEV_XCSA.WFA_SECTION S';
    sql_stmt := sql_stmt || sql_par2;                                             
    sql_stmt := sql_stmt || ', DEV_XCSA.WFA_QUESTION SGQ WHERE A.CPHID = ''' ||USER_NAME || ''' AND A.ID = AQ.FK_APPRAISAL_ID     AND AQ.ID = S.FK_QUESTIONNAIRE_ID';
    sql_stmt := sql_stmt || sql_par3;                                             
    /* RUN THE QUERY */
    OPEN QUEST_CUR FOR sql_stmt;
    You can see that now the select statement has a variable number of return columns.
    I would like to fetch the result of the query in a loop assigning the records to variables or to a record variable.
    But after reading the documentation it looks that I can only declare record variables before the query string is built and there is not an easy way to fetch a cursor into a variable number of variables.
    Is it possible to do what I am trying to do? Can you suggest a better approach?
    Please help me,
    TN

    Tremal Naik wrote:
    Ok, thanks to you both.
    Please, bear in mind that I am really a PL/SQL novice and I may have misunderstood BluShadow's hints.
    I will have a closer look at it and let you know my thoughts.Here's a cleaner commented example that should help you to understand what it's doing...
    SQL> CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2) IS
      2    v_v_val     VARCHAR2(4000);
      3    v_n_val     NUMBER;
      4    v_d_val     DATE;
      5    v_ret       NUMBER;
      6    c           NUMBER;
      7    d           NUMBER;
      8    col_cnt     INTEGER;
      9    f           BOOLEAN;
    10    rec_tab     DBMS_SQL.DESC_TAB;
    11    col_num     NUMBER;
    12    v_rowcount  NUMBER := 0;
    13  BEGIN
    14    -- create a cursor
    15    c := DBMS_SQL.OPEN_CURSOR;
    16    -- parse the SQL statement into the cursor
    17    DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
    18    -- execute the cursor
    19    d := DBMS_SQL.EXECUTE(c);
    20    --
    21    -- Describe the columns returned by the SQL statement
    22    DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
    23    --
    24    -- Bind local return variables to the various columns based on their types
    25    FOR j in 1..col_cnt
    26    LOOP
    27      CASE rec_tab(j).col_type
    28        WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000); -- Varchar2
    29        WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);      -- Number
    30        WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);     -- Date
    31      ELSE
    32        DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);  -- Any other type return as varchar2
    33      END CASE;
    34    END LOOP;
    35    --
    36    -- Display what columns are being returned...
    37    FOR j in 1..col_cnt
    38    LOOP
    39      DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' - '||case rec_tab(j).col_type when 1 then 'VARCHAR2'
    40                                                                                when 2 then 'NUMBER'
    41                                                                                when 12 then 'DATE'
    42                                                       else 'Other' end);
    43    END LOOP;
    44    --
    45    -- This part outputs the DATA
    46    LOOP
    47      -- Fetch a row of data through the cursor
    48      v_ret := DBMS_SQL.FETCH_ROWS(c);
    49      -- Exit when no more rows
    50      EXIT WHEN v_ret = 0;
    51      v_rowcount := v_rowcount + 1;
    52      DBMS_OUTPUT.PUT_LINE('Row: '||v_rowcount);
    53      DBMS_OUTPUT.PUT_LINE('--------------');
    54      -- Fetch the value of each column from the row
    55      FOR j in 1..col_cnt
    56      LOOP
    57        -- Fetch each column into the correct data type based on the description of the column
    58        CASE rec_tab(j).col_type
    59          WHEN 1  THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
    60                       DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||v_v_val);
    61          WHEN 2  THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
    62                       DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||v_n_val);
    63          WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
    64                       DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'));
    65        ELSE
    66          DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
    67          DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||v_v_val);
    68        END CASE;
    69      END LOOP;
    70      DBMS_OUTPUT.PUT_LINE('--------------');
    71    END LOOP;
    72    --
    73    -- Close the cursor now we have finished with it
    74    DBMS_SQL.CLOSE_CURSOR(c);
    75  END;
    76  /
    Procedure created.
    SQL> exec run_query('select empno, ename, deptno from emp where deptno = 10');
    EMPNO - NUMBER
    ENAME - VARCHAR2
    DEPTNO - NUMBER
    Row: 1
    EMPNO : 7782
    ENAME : CLARK
    DEPTNO : 10
    Row: 2
    EMPNO : 7839
    ENAME : KING
    DEPTNO : 10
    Row: 3
    EMPNO : 7934
    ENAME : MILLER
    DEPTNO : 10
    PL/SQL procedure successfully completed.
    SQL> exec run_query('select * from emp where deptno = 10');
    EMPNO - NUMBER
    ENAME - VARCHAR2
    JOB - VARCHAR2
    MGR - NUMBER
    HIREDATE - DATE
    SAL - NUMBER
    COMM - NUMBER
    DEPTNO - NUMBER
    Row: 1
    EMPNO : 7782
    ENAME : CLARK
    JOB : MANAGER
    MGR : 7839
    HIREDATE : 09/06/1981 00:00:00
    SAL : 2450
    COMM :
    DEPTNO : 10
    Row: 2
    EMPNO : 7839
    ENAME : KING
    JOB : PRESIDENT
    MGR :
    HIREDATE : 17/11/1981 00:00:00
    SAL : 5000
    COMM :
    DEPTNO : 10
    Row: 3
    EMPNO : 7934
    ENAME : MILLER
    JOB : CLERK
    MGR : 7782
    HIREDATE : 23/01/1982 00:00:00
    SAL : 1300
    COMM :
    DEPTNO : 10
    PL/SQL procedure successfully completed.
    SQL> exec run_query('select * from dept where deptno = 10');
    DEPTNO - NUMBER
    DNAME - VARCHAR2
    LOC - VARCHAR2
    Row: 1
    DEPTNO : 10
    DNAME : ACCOUNTING
    LOC : NEW YORK
    PL/SQL procedure successfully completed.
    SQL>As you can see, you can use DBMS_SQL to query any SQL string you like, regardless of the number of returned columns and their datatypes and the DBMS_SQL package can tell your code all the information it needs to know so that it can read the names, datatypes and data from that query.

  • Sorting records dynamically in REF cursor, based upon a dynamic field

    Hi,
    I have a REF CURSOR built by using row type, table type and PIPELINE function. I have opened the ref cursor now. I would like to update a field called 'RANK' based upon 'RATIO' field in the REF CURSOR. i.e order the records in the ref cursor by RATIO field and then update the RANK as 1, 2, 3, 4, ....
    Aim: I want to update a field in the REF CURSOR based upon another numeric field.
    Please help me.
    OPEN sales FOR
    SELECT RANK, ratio
    FROM TABLE (fngetfundholdingsale (in_primarykey, in_flag));
    loop
    fetch sales into sale1;
    exit when sales%notfound;
    --I want to update sale1.rank based upon ratio
    end loop;
    Thanks
    Ashok

    Try to use NDS (Native Dynamic SQL):
    l_order := 'ratio';
    OPEN sales FOR
    'SELECT rank' ||
    '  FROM TABLE (fngetfundholdingsale (:in_primarykey, :in_flag))' ||
    ' ORDER BY ' || l_order
      USING in_primarykey, in_flag;Regards,
    Zlatko

  • Best practices for setting environment based static variables?

    I have a set of static string variables that hold the url location of modules in a project. These locations change depending on whether I'm building for development, staging or production.
    What's the best way to set static variables in this way?

    I don't know if this is best practice, but here's the solution I've come up with.
    The root domain is accessible within the swf via a node on a loaded xml file. So I created a simple method that sets a url variable based on that domain node.
    The domain-based url variable is then used within the static string variables that define the location of the modules.
    Simplified like so:
    var domain:String = xml.node.value;
    static var bucketLocation:String = getLocation()
    static var moduleLocation:String = bucketLocation + "modulename.swf";
    function getLocation():String
         var loc:String
         switch (domain) {
              case stagingUrl:
                  loc = "pathToAmazonStagingBucket";
                   break;
              case productionUrl:
                   loc = "pathToAmazonProductionBucket";
                   break;

  • How to select different Querys based on Variable Value

    Hi guys i need to know how to select different Querys, based on variable values selected by the user, i try to do it using a Web Template but i don´t know how to program a Dynamic Query.....
    I hope sombody could help me with this
    Message was edited by: Oscar Diaz

    Hi Diaz,
    Can you explain the exact scenario which you are looking for!!!
    regards
    Happy Tony

  • Slow performance when using cursor with bind variable

    i'm facing the problem mentioned in the subject.
    whenever i use the bind variable it would take more than 5mins to fetch 157 records, but if i hardcode the value ( not using variable ) it would take only 10sec to fetch 157 records.
    can anyone give me some guide to solve this problem? thank you..
    Code :
    DECLARE
    cursor cur1(l_startdate IN varchar2,l_enddate IN varchar2) IS
    select * from shipment ship where ship.insertion_date >= to_date(l_startdate,'DD-MM-YYYY HH24:MI:SS') and ship.insertion_date < to_date(l_enddate ,'DD-MM-YYYY HH24:MI:SS')
    TYPE shipment_aat IS TABLE OF cur1%ROWTYPE INDEX BY PLS_INTEGER;
    l_shpt shipment_aat;
    limit_in INTEGER := 100;
    BEGIN
    v_startdate := '10-06-2008 14:00:00';
    v_enddate := '10-06-2008 17:00:00';
    OPEN C_shpt(v_startdate,v_enddate);
    LOOP --start shipment loop   
    FETCH C_shpt BULK COLLECT INTO l_shpt LIMIT limit_in;
         FOR indx IN 1 .. l_shpt.COUNT
    LOOP
    DBMS_OUTPUT.PUT_LINE('l_shpt value ' || l_shpt(indx).ship_number || '/' || l_shpt(indx).insertion_date);
    END LOOP;
    EXIT WHEN l_shpt.COUNT < limit_in;
    END LOOP; -- end of shipment loop
    CLOSE cur1;
    END;

    When your query takes too long ...

  • Error when executing a scenario based on Variable type Latest Value

    Hi,
    I have created two ODI varaible -
    1) filename of type as "Historize"
    2) id of type as "Historize"
    I have 2 Models -
    1) One is based on FIle Technology with resource name as #CUSTOMER.filename (dynamic filename) (TARGET)
    2) second is based on Oracle technology which contains two relational tables (SOURCE)
    I have an interface in which one-to-one mapping is done from source to target.
    At the junction of two source tables..i have put a query as "CUSTOMER_PAYMENT.CUSTID=CUSTOMER_DETAILS.CUSTID and CUSTOMER_DETAILS.CUSTID !=(#id)"
    Package:
    drag and drop two ODI variables , interface
    Connect two ODI variable to interface and define the variable type as "Declare Variable" in the package.
    Define filename as the firststep.
    filename(firststep)-----------------------------
    INTERFACE
    id---------------------------------------------------
    It is working fine with java callout and command prompt. It is not working when i invoke it on desginer.
    It gives me error:
    java.sql.SQLException: ORA-00936: missing expression
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:316)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:282)
         at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:639)
         at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:185)
         at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:503)
         at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:965)
         at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:535)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1051)
         at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2984)
         at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3026)
         at com.sunopsis.sql.SnpsQuery.executeQuery(SnpsQuery.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execCollOrders(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSqlI.treatTaskTrt(SnpSessTaskSqlI.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandScenario.treatCommand(DwgCommandScenario.java)
         at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
         at com.sunopsis.dwg.cmd.e.i(e.java)
         at com.sunopsis.dwg.cmd.g.y(g.java)
         at com.sunopsis.dwg.cmd.e.run(e.java)
         at java.lang.Thread.run(Unknown Source)
    Similary when i define the variable type as "Latest Value/Niot Persistent"...giving me same error as above...but working finw with java and command prompt.
    Thanks
    Edited by: user12420305 on Aug 31, 2010 10:42 PM

    Hi,
    My Package contains:
    First step : customerid and custFileName
    Second step : interface
    Type of both the variables in package is "Declare"
    customerid : type Alphanumeric - Historize
    custFileName : type Alphanumeric - Historize
    generate a scenario of the package and execute it.
    custFileName : abc.txt customerid : 2
    The file is created but it is giving me error for customer id.
    Operator Description:
    select     
         CUSTOMER_DETAILS.CUSTID CUSTOMER_ID,
         CUSTOMER_DETAILS.LAST_NAME || CUSTOMER_DETAILS.FIRST_NAME CUSTOMERNAME,
         CUSTOMER_DETAILS.ADDRESS ADDRESS,
         CUSTOMER_PAYMENT.PAYMENTID PAYMENT_ID,
         CUSTOMER_PAYMENT.AMOUNT AMOUNT
    from     ODITEST1.CUSTOMER_DETAILS CUSTOMER_DETAILS, ODITEST1.CUSTOMER_PAYMENT CUSTOMER_PAYMENT
    where      (1=1)
    And (CUSTOMER_PAYMENT.CUSTID=CUSTOMER_DETAILS.CUSTID and CUSTOMER_DETAILS.CUSTID !=(#CUSTOMER.customerid))
    Operator Execution:
    936 : 42000 : java.sql.SQLException: ORA-00936: missing expression
    java.sql.SQLException: ORA-00936: missing expression
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:316)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:282)
         at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:639)
         at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:185)
         at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:503)
         at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:965)
         at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:535)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1051)
         at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2984)
         at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3026)
         at com.sunopsis.sql.SnpsQuery.executeQuery(SnpsQuery.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execCollOrders(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSqlI.treatTaskTrt(SnpSessTaskSqlI.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandScenario.treatCommand(DwgCommandScenario.java)
         at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
         at com.sunopsis.dwg.cmd.e.i(e.java)
         at com.sunopsis.dwg.cmd.g.y(g.java)
         at com.sunopsis.dwg.cmd.e.run(e.java)
         at java.lang.Thread.run(Unknown Source)
    When i try to execute the scenario from command promt/java callout ..it is working fine.
    Thanks.

  • Assigning a query dynamically to a cursor based on IF ELSE condotion

    hello guys,
    we are facing a problem while creating a procedure.
    The procedure has been recreated in ORACLE from SQL SERVER 2005.
    the problem is that in SQL server we can assign a query dynamically to a cursor so that it will be called at execution time.But this is not the case in oracle, i.e in Oracle its not allowed to assign a query to a cursor dynamically(OR IS IT...!!!)
    the code is
    vr_SQL varchar2(400);
    declare
       cursor ord_cur  ;  <-----cursor declaration
      begin
       If v_pIsScrutiny = 0 then   +<--------------second condition+
          vr_SQL:='Select NVL(ServiceID,0)  ServiceID,OrdQty,+<-------query assignment to a variable+
              NVL(DrugID,0) DrugID,NVL(ServiceAmount,0) Rate,OrdDtlID 
              from Orderdtl inner join ordermst on Orderdtl.OrdID = ordermst.OrdID 
              Where Orderdtl.OrdID in (Select OrdID From Ordermst Where OrdVisitID = vr_visitid  
              and TO_CHAR(ordermst.OrdDate,''DD-MON-YYYY'') 
              Between TO_CHAR(vr_pActivationDate,''DD-MON-YYYY'') 
              and TO_CHAR(vr_pExpiryDate,''DD-MON-YYYY'') 
              ) And NVL(Orderdtl.Cancelled,0) = 0 And NVL(Orderdtl.PackageID,0) = 0 
              and NVL(Orderdtl.DrugID,0) = 0;';
        Else  +<--------------first condition+
            Update OrderDtl Set PackageID = 0 , AllocationID = 0 , ConsumptionID = 0 
            Where OrdID in (Select OrdID From Ordermst Where OrdVisitID = vr_visitid)  
            And AllocationID = v_pHCPAllocationID; 
           vr_SQL:= 'Select NVL(ServiceID,0)  ServiceID, +<-------query assignment to a variable+
           OrdQty,NVL(DrugID,0)  DrugID,NVL(ServiceAmount,0)
            Rate,OrdDtlID 
           from Orderdtl inner join ordermst on Orderdtl.OrdID = ordermst.OrdID 
           Where Orderdtl.OrdID in (Select OrdID From Ordermst Where OrdVisitID = vr_visitid  
           and TO_CHAR(ordermst.OrdDate,''DD-MON-YYYY'') 
           Between TO_CHAR(vr_pActivationDate,''DD-MON-YYYY'') 
           and TO_CHAR(vr_pExpiryDate,''DD-MON-YYYY'') 
           ) And NVL(Orderdtl.Cancelled,0) = 0 And NVL(Orderdtl.PackageID,0) = 0;'; 
        end if;
           ord_cur is vr_SQL; +<----------query assigned to a cursor variable+
        ord_rec ord_cur%ROWTYPE;
       if not ord_cur%ISOPEN then
            open ord_cur;
       end if;
        loop
        fetch ord_cur into ord_rec;
        exit when ord_cur%NOTFOUND;So currently we are stuck with this problem.
    Any solution would be of great help..
    thank you

    841363 wrote:
    hello guys,
    we are facing a problem while creating a procedure.
    The procedure has been recreated in ORACLE from SQL SERVER 2005.
    the problem is that in SQL server we can assign a query dynamically to a cursor so that it will be called at execution time.But this is not the case in oracle, i.e in Oracle its not allowed to assign a query to a cursor dynamically(OR IS IT...!!!)The problem is that you are thinking in SQL Server terms and Oracle just isn't SQL Server.
    You need to consider using ref cursors for such things (sys_refcursor) e.g.
    SQL> CREATE OR REPLACE PACKAGE reftest IS
      2    PROCEDURE test(P_no in number, cur_o OUT sys_refcursor);
      3  end;
      4  /
    Package created.
    SQL>
    SQL> CREATE OR REPLACE PACKAGE body reftest as
      2    PROCEDURE test(P_no in number, cur_o OUT sys_refcursor) as
      3      myexc exception;
      4    BEGIN
      5      if P_no = 1 then
      6        open cur_o for select empno, ename from emp;
      7      elsif p_no =2 then
      8        open cur_o for select deptno, dname from dept;
      9      else
    10        RAISE myexc;
    11      END IF;
    12    exception
    13      when myexc then
    14        raise_application_error(20991,'input must be 1 or 2');
    15    end ;
    16  end reftest;
    17  /
    Package body created.
    SQL> var x refcursor;
    SQL> exec reftest.test(1,:x);
    PL/SQL procedure successfully completed.
    SQL> print x;
         EMPNO ENAME
          7369 SMITH
          7499 ALLEN
          7521 WARD
          7566 JONES
          7654 MARTIN
          7698 BLAKE
          7782 CLARK
          7788 SCOTT
          7839 KING
          7844 TURNER
          7876 ADAMS
          7900 JAMES
          7902 FORD
          7934 MILLER
    14 rows selected.
    SQL> exec reftest.test(2,:x);
    PL/SQL procedure successfully completed.
    SQL> print x;
        DEPTNO DNAME
            10 ACCOUNTING
            20 RESEARCH
            30 SALES
            40 OPERATIONS
    SQL>

  • Setting session variable names based on variables in a loop

    I am trying to set up a loop that sets up a list of variables based upon a list, by looping over the list and setting the session.NAME:
    <CFLOOP list="#fieldnames#" index="fieldname">
    <cfset session.#fieldname# = "1">
    </CFLOOP>
    It does not seem to like session.A_CF_VARIABLE . so session.#fieldname# does not work, I get an error
    A CFML variable name cannot end with a "." character.
    The variable session. ends with a "." character. You must supply an additional structure key or delete the "." character.
    Do I have to wrap it a different way?
    Thanks
    Mark

    ahh. great. that fixed the loop problem. My second problem now appears that I am not picking up the correct data.
    My test data has a form post with field names EMAIL and GENDER, and then I was trying to write session.email = VALUE_OF_FORM_FOR_EMAIL .. session.gender = VALUE_OF_FORM_FOR_GENDER, but what I am actually doing is writing the values EMAIL and GENDER into the session. so session.email has the value EMAIL.. and not what I typed into the form.
    I guess it's because the fieldname in the index is also used as the name in the form and it's confusing it, so it goes for the wrong one, not the value from the form.
    the alternative would be to append something to the name of each field in the form.. so email is F_email and F_gender... although i tried this and using <CFSET session[fieldname] = "F_#fieldname"> but that threw an error, maybe just a formatting issue. I'd prefer to try and make it work without appending anything to the form names
    Here's some test code that has the form fields hard coded -->
    <CFSET fieldnames="email,gender">
    <CFSET email = "[email protected]">
    <CFSET gender = "M">
    <CFLOOP list="#fieldnames#" index="fieldname">
    <cfset session[fieldname] = '#fieldname#'>
    </CFLOOP>
    Thanks once again for the help
    Mark

  • Reg. cursor based delete! Little Urgent!

    Hi all,
    While accessing for a change now, i need to delete the values that came out of the cursor.
    For an Exting functionality: I am fetching few values by a cursor and i am starting a loop for executing few condtions based on the records available in the cursor. there after i am explicitly closing the cursor. The issue i have now is, since i am using the loop the pointer would be in some row x or y or z after executing the loop. Now, my question is, If i delete by using the where current of clause by giving the cursor will all the rows that came from the cursor be deleted? Before Planning the above way, i am moving the close cursor statement towards the end of my Function.
    The existing functional code is like below:
    CURSOR ship_unit_det_cur IS SELECT CNTNR_I
              FROM SHIP_UNIT_DET
              WHERE SHIP_UNIT_I = prm_cnt_i;
    Some set of statements
    BEGIN
    OPEN ship_unit_det_cur;
    FETCH ship_unit_det_cur INTO var_cnt_i;
    if ship_unit_det_cur%NOTFOUND then /* if empty */
    if(prm_log_err = 'Y') then
    err_ret_code2 := dsh_insert_drvt_evnt (prm_cnt_i, 'SHP', 'DVRT',
                   SYSDATE, USER, prm_hi_lvl_strg_i,
                             NULL, prm_load_grp_i, prm_dvrt_mthd_i, 8109);
    end if;
    commit;
    return 8109;
    end if;
    LOOP
    FETCH ship_unit_det_cur INTO var_cnt_i;
    EXIT WHEN ship_unit_det_cur%NOTFOUND;
    stproc_loc := 'dsh_load 2';
    err_ret_code := dsh_load_cntnrs_pkg.dsh_load (var_cnt_i,
                   var_prm_cnt_par_i,
                   prm_load_grp_i,
                   prm_hi_lvl_strg_i,
                   prm_dvrt_mthd_i,
                   prm_store_door_assn_i,
                   dummy,
                   prm_pgm_n,
                   'Y',
    NULL);
    if(err_ret_code = 8999) then /* on system error, always quit */
    stproc_loc := 'LoadDet 2';
    errdesc := prm_cnt_i || ' Failed fo load detail for ' || var_cnt_i;
    RAISE SYSTEM_ERROR;
    end if;
    END LOOP;
    CLOSE ship_unit_det_cur;
    END;
    Some set of statements
    Now delete the shipping unit information
    BEGIN
    stproc_loc := 'DletShipUnit';
    savepoint DELETE_SHIP_UNIT;
    delete from ship_unit_det where ship_unit_i = prm_cnt_i;
    if(prm_reusbl_f = 'N') then -- non-reusable master
    delete from shipping_unit where ship_unit_i = prm_cnt_i;
    end if;
    EXCEPTION
    WHEN OTHERS THEN
    rollback to DELETE_SHIP_UNIT;
    stproc_loc := 'DelShUn';
    errdesc := prm_cnt_i || ' Failed to delete shipping unit';
    RAISE SYSTEM_ERROR;
    END;
    In the above Begin and End Block, For the new proposed change functional code, i need to delete based on cursor. Hence forth i am planning to add the for update clause in my Cursor statement to lock the cursor values till i execute the delete.
    And in delete i am using the where current of clause. Now the question is where do i put the commit? As you can see in the above block, after i replace the delete by following,
    -- delete from ship_unit_det where ship_unit_i = prm_cnt_i;
    delete from ship_unit_det where current of ship_unit_det_cur;
    to unlock the cursor i need to place a commit. If some operation fail in the if condition below the proposed change, the rollback to the save point need to happen! so, can i place the commit in the place below Exception and end statement like:
    EXCEPTION
    WHEN OTHERS THEN
    rollback to DELETE_SHIP_UNIT;
    stproc_loc := 'DelShUn';
    errdesc := prm_cnt_i || ' Failed to delete shipping unit';
    RAISE SYSTEM_ERROR;
    COMMIT;
    CLOSE ship_unit_det_cur;
    END;
    Or Is there any other way to process the same?

    How about the Commit statement? Is that ok, if i give
    it between the Exception and the End?
    Like the below:
    EXCEPTION
    WHEN OTHERS THEN
    rollback to DELETE_SHIP_UNIT;
    stproc_loc := 'DelShUn';
    errdesc := prm_cnt_i || ' Failed to delete
    shipping unit';
    RAISE SYSTEM_ERROR;
    COMMIT;
    CLOSE ship_unit_det_cur;
    END;You do realise that the moment the RAISE system_error is encountered this block is left and the COMMIT and CLOSE ship_unit_det_cur will never be executed, right?

  • Launch url based on variable

    ok, this seems like it should be easy but im having problems,
    using Flash CS3 and AS 2.
    i have a variable named county, and variable named printUrl.
    when you push a county button it shows "the County" in the
    county field. what i want to do is have a button to load the url
    based on the county in a new window.
    frame one i have: printUrl = "mi/" +county+".html" ;
    on the button i have : getURL(printUrl, "_blank", "");
    it doesnt work, any help?
    zodoria

    ok, this seems like it should be easy but im having problems,
    using Flash CS3 and AS 2.
    i have a variable named county, and variable named printUrl.
    when you push a county button it shows "the County" in the
    county field. what i want to do is have a button to load the url
    based on the county in a new window.
    frame one i have: printUrl = "mi/" +county+".html" ;
    on the button i have : getURL(printUrl, "_blank", "");
    it doesnt work, any help?
    zodoria

  • Dynamic image display (based on variable attribute) in Web application?

    Hi experts,
    I am using a Web Template (from the Web application designer) based on a BEx Query.
    This web template displays a logo (jpg image) and the report. 
    Is there a way to add another image to my web app and having the right logo displayed depending on a characteristic (sales organization for example) chosen in the variable screen (before the first rendering)?
    Thanks for your help.
    Points will be given to useful answers.
    Cheers,
    Olivier

    Thanks for your helpful answers guys.
    Andrey's tutorial helped me to catch the sales org variable value in a variable named salesorg (Script Item in the web template as well as Data Provider Info Item).
    Now could you explain how/where to use this variable to swith images? Is this still in the same Script_item where i should be able to "hide" / "show" the following XHTML tag?:
    <img   etc .......     img<
    Thanks for your help, I'm a bit confused on this last point (and not so comfortable with Java Script).
    Olivier
    Edited by: SAP_BW_USER_49 on Nov 23, 2011 3:32 PM

  • Limit columns based on variable value

    Gurus,
       My requirement;
       User will enter a value "A" in the variable and based on the value i need to limit
       the columns in the output. for example in the query designer i have 6 fields in
       Rows, in Free Chars i have the field with variable which user will enter. if the value
       entered is "A" only 4 fields should appear on the report else if value is "B" only
       the other 2 fields should appear.
       Is there a way accomplish this...please suggest
    Thanks with points in advance...

    Geni,
    Are u using the Excel based Analyzer as your Front End?
    If so you can run a small VBA (on event SAPBEXonrefresh) that will hide columns based on the value of the cell that displays the value of the variable that the user is setting.
    See code i posted in Re: How do I make cells "0" and not blank for an example.
    Is this what you are after?
    Hope it helps,
    Gili

  • Bex query that returns variable number of columns based upon variable value

    I have a request to create a query that, at excution time, has a variable for 'nbr of months', and based on the value entered by the user, returns data for only the specified number of months. Value that can be entered can vary from 1 to 12. A simple example is, if the user enters 1, then they would only want to see one column, and if they entered 6, then they'd like to see 6 columns in the workbook.  All suggestions on how to implement this dynamic columns on a workbook will be appreciated.
    Thanks.
    BN

    Hi,
    Do this->
    1) first create a New Structure in Rows-> Place your New Selection and drag your KF.
    2) Nw Create a New Formual under this structure. Now Create a Formula variable ( "ZFVXXX")with user-entry and ready for input and dimension as NUmber. and place in formula area. And hide this formula.
    3)Now Create a New Customer-Exit variable on 0CALMONTH name as "ZCECMON" with following atrribute->Mandatory, Range(Interval) and remove check for Ready for entry.
    4)Drag your 0CALMONTH in Rows above That Structure and restrict it to "ZCECMON".
    5) Now go to CMOD and write this code.
    INCLUDE ZXRSRU01 *
    DATA: L_S_RANGE TYPE RSR_S_RANGESID. 'In global area
    DATA: LOC_VAR_RANGE LIKE RRRANGEEXIT. 'In global area
    DATA: zmonth like /bi0/0calmonth.
    CASE I_VNAM.
    WHEN 'ZCECMON'.
    IF i_step = 2.
    LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
    WHERE VNAM = 'ZFVXXX'.
    zyear = sy-datum(4).
    zmonth = sy-datum+4(2).
    l_s_range-low = zmonth.
    zmonth = zmonth + loc_var_range-low.
    l_s_range-HIgh = zmonth.
    l_s_range-sign = 'I'.
    l_s_range-opt = 'BT'.
    APPEND l_s_range TO e_t_range.
    ENDIF.
    ENDCASE.
    6) activate the porject and go to rsrt and run there first.
    Regards,
    San!
    Message was edited by: San!

  • Cursor (fetching two variables)

    Experts,
    I have a table with two columns for a cursor. The first column is server name and the second is DB name. I have a table x in all the DBs in all the servers and I want to select from that table in all the DBs in all the servers.
    I was trying to use a cursor to pass server name and DB name and add the dbo.x to select all from the table x. so like
              SELECT   *
               FROM @SERVER_NAME.@DB_NAME.dbo.x
    How can I use a cursor to pass (fetch values) the variable for the @SERVER_NAME.@DB_NAME
    help truly appreciated
    ebro

    DECLARE @SeverName VARCHAR(200) -- server name
    DECLARE @Database VARCHAR(200) --DB name
    DECLARE @sql varchar(max)
    set @sql =''
    DECLARE db_cursor CURSOR FOR
    SELECT @sql=@sql+ 'SELECT '''+name+''' SeverName, name AS [Database]
    FROM ['+ name+'].master.sys.databases where name NOT IN (''master'',''tempdb'',''model'',''msdb'',''ReportServer'',''ReportServerTempDB'') Union All '
    FROM sys.servers
    WHERE [product] = 'SQL Server'
    SET @sql=substring(@sql,1,len(@sql)-len('Union All '))--Remove an extra union all from the end
    PRINT @sql
    EXEC(@sql)
    OPEN db_cursor
    FETCH NEXT FROM db_cursor INTO @SeverName, @Database
    WHILE @@FETCH_STATUS = 0
    BEGIN
    declare @querySQL nvarchar(1000) =
    N'select top 2 * from ' + QuoteName(@SeverName) + N'.' + QuoteName (@Database) + N'.dbo.X';
    exec @querySQL;
    FETCH NEXT FROM db_cursor INTO @SeverName , @Database
    END
    CLOSE db_cursor
    DEALLOCATE db_cursor
    Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com

Maybe you are looking for