Dynamic If Statment

Is it possible to create an if statment with dynamic logical tests?  For example, I have a .csv file that has a file name in the first column, and the columns after that have random tag data.  The first row of the .csv is a header (so it's pretty much just ignored), the second row is the file and tags to be compared to the others, the third row is the header for the file name column and all of the tag category columns after that, and below that are all the files and their tags to be compare row 2 to.  The problem is, not every category of files has the same number of tags, and not all tags may be necessary for the comparison, so I was going to have a dialog window of checkboxes come up listing the header row's non-null tag columns as individual checkboxes.  The if statement would then need to compare all of the selected columns to the other listed files (the on row 4 and below) to find any that contain the exact same tags as the source file (the one in row 2).
Below is kind of a rough mock-up of what I'm trying to do.
var baseTag = [];
baseTag = data[1].split(','); //the comparison row's columns loaded to the baseTag array
if(checkbox1.value) tag1 = true;
if(checkbox2.value) tag2 = true;
if(checkbox3.value) tag3 = true;
///etc. etc.///
//check for any files that match
for(i=3;i<data.length;i++) { //data being the array containing all the rows of the .csv
     var tag = [];
     tag = data[i].split(',');
     if(baseTag[1] == tag[1] && baseTag[2] == tag[2] && baseTag[3] == tag[3] /*etc*/) { //this needs to be set up so that if tag2 = false, it doesn't do the "baseTag[2] == tag[2]" check; but if it's true, it does check it
          open(tag[0]);
Anyway, any ideas on how to do this?  I have the feeling it's something simple, but just can't seem to figure it out.  Thanks in advance for any help!
dgolberg

Hey Michael, thanks for the reply.  The array labelled "baseTag" holds the data for a single row in a .csv file (for simplicity, we'll say it's the very first row).  The array labelled "tag" holds the data for all the remaining rows of the .csv file.  So for example, the .csv might look something like below when opened with a spreadsheet program:
File Name
Tag1
Tag2
Tag3
FileName1.format
wood
dark
strong
FileName2.format
wood
light
strong
FileName3.format
wood
medium
light
FileName4.format
wood
dark
strong
FileName1.format is the file we're doing the check on using the tag columns to the right, and if it finds a match using those tags, it opens the file listed in column 1.  So the script would need to make sure all tags match the first row's tags (in this example, only FileName4.format would match FileName1.format's tags).  However, there may be instances where I wish to exclude one of the columns from the check (for example, only check for matches of tag 1 and 3).  So this would require that the if statement's check only look for matches of the tag1 and tag3 columns while ignoring Tag2 (so now FileName2.format would also match).  Essentially, instead of being:
if(baseTag[1] == tag[1] && baseTag[2] == tag[2] && baseTag[3] == tag[3]) {
          open(tag[0]);
it would then be:
if(baseTag[1] == tag[1] && baseTag[3] == tag[3]) {
          open(tag[0]);
if I decide to have it exclude the tag2 column.
The issue I'm having is making this change to the if statement be dynamic (without a huge mess of inefficient code).  Your mention of a switch statement sounds interesting.  I'm not the greatest programmer yet (pretty much just the really basic stuff) so I hadn't heard about this statement yet; but I'll certainly be looking it up now.  Anyway, hope the info helps clarify it a little better.

Similar Messages

  • TSQL - Dynamic Query Case statment update issue - to update table by left shifting the rows

    Hi all
    I need an help on my tsql query in 2000 to fix the case statement.
    I have a table like shown below.
    On this table where ever I see PortID as 101 and 105 I need to remove it and shift the rows from right to left.
    ie on First row PortID1 is 101 so I need to remove it and replace it with PortId2 and similarly PortID2 replaced my PortID3 and so on.
    ie like on excel if you delete cell we need to shift the rows to left .
    I wrote an dynamic update statement i,m not sure on the assigning dynamic case statment.
    CREATE TABLE [TravelRank]
    [Destination] [varchar] (50) NULL,
    [PortID1] [int] NULL ,
    [Distance1] [int] NULL ,
    [Rating1] [int] NULL ,
    [PortID2] [int] NULL ,
    [Distance2] [int] NULL ,
    [Rating2] [int] NULL ,
    [PortID3] [int] NULL ,
    [Distance3] [int] NULL ,
    [Rating3] [int] NULL ,
    [PortID4] [int] NULL ,
    [Distance4] [int] NULL ,
    [Rating4] [int] NULL
    INSERT into [TravelRank]
    select 'Virgin Islands','101','10','5','102','20','5','103','31','5','109','41','5'
    Union all
    select 'Guinea','101','15','3','102','22','3','105','32','2','110','45','4'
    Union all
    select 'Benin ','102','12','4','106','28','4','104','33','3','109','48','2'
    Union all
    select 'Ecuador','102','18','5','101','29','5','108','34','1','111','45','5'
    Union all
    select 'Belarus ','103','17','4','105','24','4','108','45','4','112','46','3'
    Union all
    select 'Cook Islands','105','11','2','108','23','2','101','32','2','107','42','4'
    Here is my code to fix
    declare @SQL varchar(4000)
    declare @left varchar(1)
    declare @right varchar(1)
    select @left = '1',@right = '2'
    while @left < 4
    begin
    select @SQL = '
    update t1.PortID' + @left + ' = t2.PortID' + @right + '
    t1.Distance' + @left + ' = t2.Distance' + @right + '
    t1.Rating' + @left + ' = t2.Rating' + @right + '
    'case @left
    when '1' then
    ' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
    t1.PortID' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+2 as varchar(1)) +'
    t1.PortID' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+3 as varchar(1)) +'
    t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
    t1.Distance' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+2 as varchar(1)) +'
    t1.Distance' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+3 as varchar(1)) +'
    t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
    t1.Rating' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+2 as varchar(1)) +'
    t1.Rating' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+3 as varchar(1)) +'
    ' when '2' then
    ' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
    t1.PortID' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+2 as varchar(1)) +'
    t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
    t1.Distance' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+2 as varchar(1)) +'
    t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
    t1.Rating' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+2 as varchar(1)) +'
    ' when '3' then
    ' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
    t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
    t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
    ' when '3' then
    ' t1.PortID' + @left + ' = null '
    t1.Distance' + @left + ' = null '
    t1.Rating' + @left + ' = null '
    else '' end'
    from [TravelRank] t1
    inner join [TravelRank] t2
    on t1.destination = t2.destination
    where t1.PortID1 = 101'
    print @SQL
    -- exec (@SQL)
    select @left = cast(cast(@left as int) + 1 as varchar(1))
    , @right = cast(cast(@right as int) + 1 as varchar(1))
    end
    Thanks a lot in advance.

    declare @SQL varchar(4000)
    declare @left varchar(1)
    declare @right varchar(1)
    select @left = '1',@right = '2'
    while @left < 4
    begin
    select @SQL = '
    update t1.PortID' + @left + ' = t2.PortID' + @right + '
    t1.Distance' + @left + ' = t2.Distance' + @right + '
    t1.Rating' + @left + ' = t2.Rating' + @right + '
    '+CASE @left
    when '1' then
    ' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
    t1.PortID' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+2 as varchar(1)) +'
    t1.PortID' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+3 as varchar(1)) +'
    t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
    t1.Distance' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+2 as varchar(1)) +'
    t1.Distance' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+3 as varchar(1)) +'
    t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
    t1.Rating' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+2 as varchar(1)) +'
    t1.Rating' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+3 as varchar(1)) +'
    ' when '2' then
    ' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
    t1.PortID' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+2 as varchar(1)) +'
    t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
    t1.Distance' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+2 as varchar(1)) +'
    t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
    t1.Rating' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+2 as varchar(1)) +'
    ' when '3' then
    ' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
    t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
    t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
    ' when '3' then
    ' t1.PortID' + @left + ' = null '+
    ' t1.Distance' + @left + ' = null '+
    ' t1.Rating' + @left + ' = null '
    else '' END + '
    from [TravelRank] t1
    inner join [TravelRank] t2
    on t1.destination = t2.destination
    where t1.PortID1 = 101'
    print @SQL
    -- exec (@SQL)
    select @left = cast(cast(@left as int) + 1 as varchar(1))
    , @right = cast(cast(@right as int) + 1 as varchar(1))
    end
    You were missing a couple of concats. This runs now, but I'm not completely sure if it's the output you were expecting.

  • Execute Dynamic SQL statement using procedure builder

    i want to execute a dynamic SQL statment using procedure builder not using forms
    because my statement depending on a variable table name
    i know that i can do that from forms using
    FORMS_DDL('SQL_STAT');
    but i wanna to use the procedure builder
    which function i should use and how?
    please explain in example if you don't mind.
    thanks

    Hi,
    You can very well use DBMS_SQL Package supplied by Oracle for doing this.
    Search for DBMS_SQL in OTN. You will get all info regarding this.
    Regards.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by itslul:
    i want to execute a dynamic SQL statment using procedure builder not using forms
    because my statement depending on a variable table name
    i know that i can do that from forms using
    FORMS_DDL('SQL_STAT');
    but i wanna to use the procedure builder
    which function i should use and how?
    please explain in example if you don't mind.
    thanks<HR></BLOCKQUOTE>
    null

  • Switch statment

    hey
    is there any way to create dynamic switch statment ?
    if not what will be your solution of having something similar ?
    thx
    Mike

    When people start asking questions about dynamic code flow it usually means that they need some refactoring and/or to use an appropriate collection.

  • Dynamic REF Cursor with Dynamic Fetch - Urgent

    i have a pl/sql package with generates dynamic SQL statments. my problem is i want to open this SQL statment dynamically and fetch data in dynamic variable.
    declare
    type type_temp is REF CURSOR;
    cur_temp type_temp;
    mv_sql varchar2(4000);
    begin
    -- this will be dunamically generated and
    -- hence could have any no. of columns.
    mv_sql := select f1, f2, f3, f4 from table_temp;
    open cur_temp for mv_sql;
    fetch cur_temp into c1, c2, c3, c4;
    close cur_temp;
    end;
    problem is my sql statment will have N no. of columns how can i fetch this N no. of columns.

    Very hard problem, because ref cursors do not (directly) support description!
    Se mine (non-ideal) solution (it may be doable, but it isn't very practical
    or easily maintainable):
    1. "Generic" package
    CREATE OR REPLACE PACKAGE dyn_fetch IS
    TYPE ref_cur_t IS REF CURSOR;
    g_query VARCHAR2 (32000);
    g_count NUMBER;
    g_desc_tab DBMS_SQL.DESC_TAB;
    varchar2_type CONSTANT PLS_INTEGER := 1;
    number_type CONSTANT PLS_INTEGER := 2;
    date_type CONSTANT PLS_INTEGER := 12;
    rowid_type CONSTANT PLS_INTEGER := 11;
    char_type CONSTANT PLS_INTEGER := 96;
    long_type CONSTANT PLS_INTEGER := 8;
    raw_type CONSTANT PLS_INTEGER := 23;
    mlslabel_type CONSTANT PLS_INTEGER := 106;
    clob_type CONSTANT PLS_INTEGER := 112;
    blob_type CONSTANT PLS_INTEGER := 113;
    bfile_type CONSTANT PLS_INTEGER := 114;
    PROCEDURE describe_columns;
    FUNCTION record_def RETURN VARCHAR2;
    END;
    CREATE OR REPLACE PACKAGE BODY dyn_fetch IS
    PROCEDURE describe_columns IS
    l_cur INTEGER;
    BEGIN
    l_cur := DBMS_SQL.OPEN_CURSOR;
    DBMS_SQL.PARSE (l_cur, g_query, DBMS_SQL.NATIVE);
    DBMS_SQL.DESCRIBE_COLUMNS (l_cur, g_count, g_desc_tab);
    DBMS_SQL.CLOSE_CURSOR (l_cur);
    EXCEPTION
    WHEN OTHERS THEN
    IF DBMS_SQL.IS_OPEN (l_cur) THEN
    DBMS_SQL.CLOSE_CURSOR (l_cur);
    END IF;
    RAISE;
    END;
    FUNCTION record_def RETURN VARCHAR2 IS
    l_record_def VARCHAR2 (32000);
    l_type VARCHAR2 (100);
    l_col_type PLS_INTEGER;
    l_col_max_len PLS_INTEGER;
    l_col_precision PLS_INTEGER;
    l_col_scale PLS_INTEGER;
    BEGIN
    FOR i IN 1..g_count LOOP
    l_col_type := g_desc_tab(i).col_type;
    l_col_max_len := g_desc_tab(i).col_max_len;
    l_col_precision := g_desc_tab(i).col_precision;
    l_col_scale := g_desc_tab(i).col_scale;
    IF l_col_type = varchar2_type THEN
    l_type := 'VARCHAR2(' || l_col_max_len || ')';
    ELSIF l_col_type = number_type THEN
    l_type := 'NUMBER(' || l_col_precision || ',' || l_col_scale || ')';
    ELSIF l_col_type = date_type THEN
    l_type := 'DATE';
    ELSIF l_col_type = rowid_type THEN
    l_type := 'ROWID';
    ELSIF l_col_type = char_type THEN
    l_type := 'CHAR(' || l_col_max_len || ')';
    -- ELSIF l_col_type = ...
    -- long_type, raw_type ...
    END IF;
    l_record_def := l_record_def || ' col_' || i || ' ' || l_type || ',';
    END LOOP;
    l_record_def := RTRIM (l_record_def, ',');
    RETURN l_record_def;
    END;
    END;
    Note that procedure "record_def" creates columns names as col_1 (col_2 ...)
    because SELECT clause in your query can be without aliases, for example
    "SELECT deptno || dname FROM dept".
    2. Your package which returns query nad ref cursor
    CREATE OR REPLACE PACKAGE test IS
    PROCEDURE set_query (p_query VARCHAR2 := NULL);
    FUNCTION ref_cur RETURN dyn_fetch.ref_cur_t;
    END;
    CREATE OR REPLACE PACKAGE BODY test IS
    PROCEDURE set_query (p_query VARCHAR2 := NULL) IS
    l_query VARCHAR2 (32000) :=
    ' SELECT e.empno, e.ename,' ||
    ' e.deptno, d.dname' ||
    ' FROM emp e,' ||
    ' dept d' ||
    ' WHERE e.deptno = d.deptno';
    BEGIN
    IF p_query IS NULL THEN
    dyn_fetch.g_query := l_query;
    ELSE
    dyn_fetch.g_query := p_query;
    END IF;
    END;
    FUNCTION ref_cur RETURN dyn_fetch.ref_cur_t IS
    l_ref_cur dyn_fetch.ref_cur_t;
    BEGIN
    OPEN l_ref_cur FOR dyn_fetch.g_query;
    RETURN l_ref_cur;
    END;
    END;
    Why we need two separate procedures (functions) in your package ?
    a) Receiving program must use dynamic SQL, but in dynamic block we can access
    only PL/SQL code elements that have global scope (standalone functions and procedures,
    and elements defined in the specification of a package).
    Unfortunately, cursor variables cannot be defined in the specification of a package
    (cannot be global variables).
    b) Receiving program must get the column list before ref cursor.
    So, we have two options: call (in receiving program) the same function two times
    (once to get the column list and once to return a ref cursor)
    or use one procedure (or function) for returning query (to get the column list)
    and second function for returning a ref cursor.
    3. Your receiving program
    CREATE OR REPLACE PROCEDURE test_fetch_ref_cur (p_query VARCHAR2 := NULL) IS
    l_statement VARCHAR2 (32000);
    FUNCTION process_def RETURN VARCHAR2 IS
    l_process_def VARCHAR2 (32000);
    BEGIN
    l_process_def := 'DBMS_OUTPUT.PUT_LINE (';
    FOR i IN 1 .. dyn_fetch.g_count LOOP
    l_process_def := l_process_def || ' l_record.col_' || i || ' || ''>>'' || ';
    END LOOP;
    l_process_def := RTRIM (l_process_def, ' || ''>>'' || ') || ');';
    RETURN l_process_def;
    END;
    BEGIN
    test.set_query (p_query);
    dyn_fetch.describe_columns;
    l_statement :=
    ' DECLARE' ||
    ' TYPE record_t IS RECORD (' ||
    dyn_fetch.record_def || ');' ||
    ' l_record record_t;' ||
    ' l_ref_cur dyn_fetch.ref_cur_t;' ||
    ' BEGIN' ||
    ' l_ref_cur := test.ref_cur;' ||
    ' LOOP' ||
    ' FETCH l_ref_cur INTO l_record;' ||
    ' EXIT WHEN l_ref_cur%NOTFOUND;' ||
    process_def ||
    ' END LOOP;' ||
    ' CLOSE l_ref_cur;' ||
    ' END;';
    EXECUTE IMMEDIATE l_statement;
    END;
    You can test this with:
    SET SERVEROUTPUT ON;
    EXECUTE test_fetch_ref_cur;
    Note that we can try to use more generic solution:
    CREATE OR REPLACE PACKAGE dyn_fetch IS
    -- SAME AS BEFORE, PLUS:
    PROCEDURE fetch_ref_cur (
    p_function_ref_cur VARCHAR2,
    p_process_def VARCHAR2);
    END;
    CREATE OR REPLACE PACKAGE BODY dyn_fetch IS
    -- SAME AS BEFORE, PLUS:
    PROCEDURE fetch_ref_cur (
    p_function_ref_cur VARCHAR2,
    p_process_def VARCHAR2)
    IS
    l_statement VARCHAR2 (32000);
    BEGIN
    l_statement :=
    ' DECLARE' ||
    ' TYPE record_t IS RECORD (' ||
    record_def || ');' ||
    ' l_record record_t;' ||
    ' l_ref_cur dyn_fetch.ref_cur_t;' ||
    ' BEGIN' ||
    ' l_ref_cur := ' ||
    p_function_ref_cur || ';' ||
    ' LOOP' ||
    ' FETCH l_ref_cur INTO l_record;' ||
    ' EXIT WHEN l_ref_cur%NOTFOUND;' ||
    p_process_def ||
    ' END LOOP;' ||
    ' CLOSE l_ref_cur;' ||
    ' END;';
    EXECUTE IMMEDIATE l_statement;
    END;
    END;
    CREATE OR REPLACE PROCEDURE test_fetch_ref_cur (p_query VARCHAR2 := NULL) IS
    FUNCTION process_def RETURN VARCHAR2 IS
    -- SAME AS BEFORE
    END;
    BEGIN
    test.set_query (p_query);
    dyn_fetch.describe_columns;
    dyn_fetch.fetch_ref_cur (
    p_function_ref_cur => 'test.ref_cur',
    p_process_def => process_def);
    END;
    Regards,
    Zlatko Sirotic

  • Query HELP : Dynamic TSql statement using Union

    Hi All
    I want to UNION the resultset from 2 dynamic T-SQL statements on SQL 2000.
    I have to calculate the sum of Amount for each serial.
    I modified the query to use Dynamic SQL as the code is bit complex.
    begin
    DECLARE @Sql_A NVARCHAR(2000)
    DECLARE @Sql_B NVARCHAR(2000)
    Insert into #temp
    SELECT [SERIAL], 'AMOUNT' = SUM(AMOUNT)
    FROM
    set @Sql_A = '(SELECT ''SERIAL'' = SERIAL_A, ''AMOUNT'' = AMOUNT
    FROM [dbo].[TableA] )'
    UNION ALL
    set @Sql_B = '( SELECT 'SERIAL' = SERIAL_B, 'AMOUNT' = AMOUNT
    FROM [dbo].[TableB] )'
    AS A GROUP BY [SERIAL]
    end
    I dont get it rite even If i use it like exec (@Sql_A+ UNION + @Sql_B)
    Please advise me the best way to group the dynamic Tsql statments.
    Create table TableA (Serial_A int, Amount float)
    Go
    INSERT INTO TableA (Serial_A ,Amount) VALUES('1','10')
    INSERT INTO TableA (Serial_A ,Amount) VALUES('1','10')
    INSERT INTO TableA (Serial_A ,Amount) VALUES('2','10')
    INSERT INTO TableA (Serial_A ,Amount) VALUES('2','10')
    INSERT INTO TableA (Serial_A ,Amount) VALUES('3','10')
    Go
    Create table TableB (Serial_B int, Amount float)
    Go
    INSERT INTO TableB (Serial_B ,Amount) VALUES('1','20')
    INSERT INTO TableB (Serial_B ,Amount) VALUES('1','15')
    INSERT INTO TableB (Serial_B ,Amount) VALUES('2','5')
    INSERT INTO TableB (Serial_B ,Amount) VALUES('3','10')
    INSERT INTO TableB (Serial_B ,Amount) VALUES('4','10')
    Go
    Create table #temp
    Serial int, Amount float
    begin
    Insert into #temp
    SELECT [SERIAL], 'AMOUNT' = SUM(AMOUNT)
    FROM
    SELECT 'SERIAL' = SERIAL_A, 'AMOUNT' = AMOUNT
    FROM [dbo].[TableA]
    UNION ALL
    SELECT 'SERIAL' = SERIAL_B, 'AMOUNT' = AMOUNT
    FROM [dbo].[TableB]
    AS A GROUP BY [SERIAL]
    end
    SELECT * FROM #temp
    drop table #temp
    Thanks a lot in advance.

    You need to append to a variable and execute the dynamic sql as below:
    Drop table TableB,TableA
    Create table TableA (Serial_A int, Amount float)
    Go
    INSERT INTO TableA (Serial_A ,Amount) VALUES('1','10')
    INSERT INTO TableA (Serial_A ,Amount) VALUES('1','10')
    INSERT INTO TableA (Serial_A ,Amount) VALUES('2','10')
    INSERT INTO TableA (Serial_A ,Amount) VALUES('2','10')
    INSERT INTO TableA (Serial_A ,Amount) VALUES('3','10')
    Go
    Create table TableB (Serial_B int, Amount float)
    Go
    INSERT INTO TableB (Serial_B ,Amount) VALUES('1','20')
    INSERT INTO TableB (Serial_B ,Amount) VALUES('1','15')
    INSERT INTO TableB (Serial_B ,Amount) VALUES('2','5')
    INSERT INTO TableB (Serial_B ,Amount) VALUES('3','10')
    INSERT INTO TableB (Serial_B ,Amount) VALUES('4','10')
    Go
    Create table #temp
    Serial int, Amount float
    begin
    DECLARE @Sql_A NVARCHAR(2000)
    DECLARE @Sql_B NVARCHAR(2000)
    set @Sql_A = 'SELECT [SERIAL], ''AMOUNT'' = SUM(AMOUNT)
    FROM (SELECT ''SERIAL'' = SERIAL_A, ''AMOUNT'' = AMOUNT
    FROM [dbo].[TableA]
    UNION ALL
    SELECT ''SERIAL'' = SERIAL_B, ''AMOUNT'' = AMOUNT
    FROM [dbo].[TableB] )AS A GROUP BY [SERIAL]
    Insert into #temp
    Exec(@sql_A)
    end
    SELECT * FROM #temp
    drop table #temp

  • JTable scrolling problem...

    I am having a problem with my JTable scrolling to show the newest added row. I have it working, but it jumps. Here is my problem.
    I have the enter key acting like the tab key. I can force the scroll to the active cell but it jumps to row 0 for just a split second.
    I know the problem is the way that I handle the Enter key. When I press enter I drop a cell down but then I force it back up.
    Does any one know how to fix this? Here is some of the code that I am using...
    if (event.getKeyChar() == '\n')
    int r = tblDetailEntry.getSelectedRow();
    int c = tblDetailEntry.getSelectedColumn();
    if(r == 0)
    r = curBill.billDetail.size();
    c--;
    if(r <= curBill.billDetail.size())
    r--;
    if(c == curBill.CODE)
    c = 0;
    if(r == curBill.billDetail.size() - 1)
    detailEntry.addLine();     
    r = curBill.billDetail.size() - 1;               
    else
    r++;
    Rectangle rect = tblDetailEntry.getCellRect(r, 0, true);
    tblDetailEntry.scrollRectToVisible(rect);
    tblDetailEntry.editCellAt(r,c + 1);
    tblDetailEntry.setRowSelectionInterval(r,r);
    tblDetailEntry.setColumnSelectionInterval(c + 1,c + 1);     
    }

    My app is a bit more complex. It includes search criteria (Textboxes) and a
    submit button which will write a dynamic SQL statment, execute and fill a table > thin an internal scrollpaneIt doesn't matter that you are using a "dynamic SQL statement". Whats important is how you build your TableModel and the TableModel you are using. I gave you an example that will use the DefaultTableModel and will work for a single row or 1,000 rows in the ResultSet.
    Your question didn't state whether you are using the the DefaultTableModel or a custom TableModel. If you are using a custom TableModel, then chances are you have an error in you TableModel.
    In no way am I asking for you or anyone else to supply me with code. Only a
    possible step in the right direction. This is exactly what my example did. It proved to you that it works. So you look at your code and see what the differences are between one that works and one that doesn't. The example has three basic lines of code to build a scrollable table:
    JTable table = new JTable(data, columnNames);
    JScrollPane scrollPane = new JScrollPane( table );
    getContentPane().add( scrollPane );
    I don't know how is can get any simpler than that, so I would have no idea what to suggest you are doing wrong. Are you mixing AWT and Swing components?

  • Dynamic field in select statment.

    Hello,
    I created a report in which i have two checkboxes in the selection screen. The first checkbox is for the option to bring or not, initial purchase requisitions (BANFN) from EKPO and the second is to bring initial or not, RFQs
    (ANFNR). I want the select statment to have this form:
    select ...
    from ekpo
    into g_table
    where ..
    and dynamic field = " ".
    Can this be done ?
    i tried to put it as a string but it didnt work. (data: dynamic field type string value "EKPO-BANFN")
    P.S i know that it can be by writing the same select code twice.
    I just wonder if this can be done by this way
    \Regards.

    Hey Nick,
    I have more conditions than the one i said before , should all be in the lv_where_clause ?
    check my code.
    DATA: G_CHBFLD type STRING.
    G_CHBFLD = 'P~BANFN = '' " '.
    FORM SELECT_DATA_EKPO_EKKO.
      SELECT  .....
          FROM EKPO AS P INNER JOIN EKKO AS K
            ON PEBELN = KEBELN
              INTO CORRESPONDING FIELDS OF TABLE GT_EKPOEKKO
                WHERE K~EBELN IN S_EBELN
                AND K~AEDAT IN S_AEDAT
                AND K~BSTYP IN S_BSTYP
                and ( G_CHBFLD ) .   -
    > //DEBUGER ")" is not a valid comparison operator. comparison operator.

  • Dynamic table name in select statment

    hai,
    Please help me....
    oracle 9i i am using.
    i have four tables abc_121,
    abc_122,
    abc_123,
    abc_124.
    i want to pick records from a table.table name should be prepared dynamically.
    i.e., i want to pick records from a quarter table of this year.(ex: abc_124). using sql statement only.
    i have tried..but i couldn't...... pls help me...

    ramadurga.v wrote:
    oracle 9i i am using.
    i have four tables abc_121,
    abc_122,
    abc_123,
    abc_124.
    i want to pick records from a table.table name should be prepared dynamically.
    i.e., i want to pick records from a quarter table of this year.(ex: abc_124). using sql statement only.Create a partition view. E.g.
    create or replace view abc as
    select * from abc_121
    union all
    select * from abc_122
    union all
    ...For the partition view approach to correctly work (doing "partition pruning"), you need to have a constraint on the column that identifies that partition.
    In other words, you cannot use the table name as an attribute to identifies its data content. Foe example, you can have tables YEAR2001_Q1 and YEAR2001_Q2. However, the year and quarter also need to be in the table itself - e.g. columns YEAR and QUARTER.
    For table YEAR2001_Q1, the YEAR column needs to have a check constraint that ensures it is always 2001. And a check constraint for column QUARTER to ensure that it is always 1.
    If these conditions are met, then a select from the partition view using +"where YEAR=2001 and QUARTER=2"+ will result in only table YEAR2001_Q2 to be used and not other tables like YEAR2001_Q1.
    See {message:id=10539404} for an example.

  • Tyring to dynamically create SQL statment for an SQL Calendar

    Is there a way to dynamically create an SQL statement that an SQL Calendar would use. I don't see an option to create a PL/SQL Calendar.
    For example I want to pass a table name, and the corresponding date column to items on the calendar page, and then have the SQL Calendar use those to fields to display the number of records loaded into the specified table. I've written the following but it doesn't work:
    'SELECT count(*), ' || :P8_SOURCE_DATE || ' FROM ' || :P8_SOURCE_TABLE || ' GROUP BY ' || :P8_SOURCE_DATE;
    Does anyone know if there is a why to create a PL/SQL Calendar?

    Jason,
    it is possible, though not so simple as with a report.
    What you need to do is to create a pipelined function, that returns your date and count data. This pipelined function can be the base of a pseudo-table, which can be used in a select. For the pipelined function you need to define types for one row and a table to define the return-type for your function:
    create or replace type calendar_row as object (date_time date, description varchar2(250));
    create type calendar_table as table of calendar_row;
    Then you can create the package with the function:
    ================================================
    create or replace package dyn_calendar is
    procedure set_query(i_query in varchar2);
    function view_source return calendar_table pipelined;
    end;
    create or replace package body dyn_calendar is
    v_query varchar2(100) := null;
    procedure set_query(i_query in varchar2) is
    begin
    v_query := i_query;
    end;
    function view_source return calendar_table pipelined is
    TYPE cursor IS REF CURSOR;
    c_cal cursor;
    v_date_time date := null;
    v_description varchar2(100) := null;
    r_cal calendar_row;
    begin
    open c_cal for v_query;
    fetch c_cal into v_date_time, v_description;
    loop
    exit when c_cal%notfound;
    r_cal := calendar_row(v_date_time, v_description);
    pipe row(r_cal);
    fetch c_cal into v_date_time, v_description;
    end loop;
    return;
    end;
    end;
    ================================================
    Now you can set query in a PL/SL region before the calendar:
    dyn_calendar.set_query(SELECT count(*), ' || :P8_SOURCE_DATE || ' FROM ' || :P8_SOURCE_TABLE || ' GROUP BY ' || :P8_SOURCE_DATE);
    and you can base your calendar on the query:
    select * from table(dyn_calendar(view_source))
    Good luck,
    Dik

  • Return statment for dynamic LOV - exception handling

    Hello All,
    Good Morning.
    Oracle 11g, apex 3.2.1
    I am having an dynamic LOV with a return statement.
    code :-
    ==========================
    declare
    owner varchar2(12) :='';
    stmt varchar2(4000) :='';
    No_Records_Exception exception ;
    phase varchar2(30);
    year varchar2(30);
    month_quarter varchar2(30);
    begin
    stmt :='select distinct famid d, famid r from '
    ||:P1_SCHEMA||'.'||'FMLY';
    return stmt;
    exception
    when No_Records_Exception then
    raise_application_error (-20998 , ' Schema does not exist ' );
    when OTHERS then
    raise_application_error (-20999,' Select the schema first ' );
    end;
    ===================
    My question is - why the exception is not handled when there are no table found.
    Am getting the following errr ..
    Error: ORA-06550: line 1, column 120: PL/SQL: ORA-00903: invalid table name ORA-06550: line 1, column 7: PL/SQL: SQL Statement ignored performing List of Values query: "select distinct famid d, famid r from .FMLY".
    Pls let me know how to handle this error.. if the table is invalid.
    scenario for poping this error:-
    ==================
    I am having three "select list with redirect" items and one radio group ( having two Radion buttons - Relation , Famid )
    The requirement is when the user selects Famid radio then the lov is suppose to populate the multiselect list with famid values from table P2D2008M05.FMLY and the schema P2D2008M05 is selected from three list items
    P2D, 2008 , M05 one from each item .
    If the schema is not selected and the user selects radio famid , then the error is coming , I need to put a validation or error handling mechanism when in which ,if the user selects famid radio and the schema is not selected , I need to raise an exception with proper error message to the user saying that the schema is not selected.
    Pls helpin this regard.
    Thanks/kumar.

    Hi,
    Your exception is for function that return select.
    Error is raised when Apex procedures try use select your function returns.
    You need test your select inside function or create validations
    Your function could look something like this
    DECLARE
      stmt    VARCHAR2(4000);
      l_count NUMBER;
    BEGIN
      IF NVL(:P1_SCHEMA,'%'||'null%') = '%'||'null%' THEN
        raise_application_error (-20999,' Select the schema first ' );
      END IF;
      SELECT COUNT(1) INTO l_count FROM all_users WHERE username = :P1_SCHEMA ;
      IF l_count = 0 THEN
        raise_application_error (-20998 , ' Schema does not exist ' );
      END IF;
      stmt :='select distinct famid d, famid r from ' ||:P1_SCHEMA ||'.' ||'FMLY';
      RETURN stmt;
    END;That is just example, I did not test it. And I think it is not good idea raise errors inside LOV function.
    You should use Apex after submit validations
    Br,Jari

  • How to find table name(s) in a dynamic query

    In one of our (9iAS PORTAL)applications, any user can able to run their query statment and get output. All queries will be executed as dynamic SQL thru' a common shema/user who has 'SELECT' privilege on all tables but all users don't have this privilege on all tables. Now, before executing any query I need to find out what are the table name(s) used in this query to check the privilege for the respective user. How do I extract all table names being used in a dynamic query?.
    Thanks
    -Krishnamurthy

    I guess that his users log in to application first, then application uses one account to log in to database, so application are not direct database user since all users share the same account to database. If so, when a user lgins in, you may write it down from application to a database audit table, and you need to write down the dynamic query to the database audit table too, then you may query that audit table to find out. up to here, it looks that your application has to do more to assign what role to a user running the application, since database does not know what user is assessing it.

  • Smartform of a particular employee with dynamic actions

    Hi All,
    I am making an HR smartform - pulling data from infotypes  - so I am using logical database pnp. Now Everytime I enter the personal number in the PNP screen, it gives me form with correct data of respective employee.
    I want to club this smart form's driver program to a dynamic action, so the personal number would ne chosen dynamically. For that I believe we have to choose HR report category from program attributes of driver program as '0000003'.
    If I  do that and hardcode the employee number it do not takes it but it starts printing smartforms of all the employees - even if I keep the report category as 0000001, it asks for a personal number at runtime,n do not takes hardcoded value - The getpernr statment is not fetching up the data for that particular employee but it pulls data for all employees.
    Please suggest how could I use the hard coded value of pernr to get the resp3ective data in the smartform. Do I have to create another report category - a new one? if so how?
    If u have any sample code? Please share it.
    Thanks
    Ribhu

    Hi Suresh, I was just testing it by hardcoding, wheather it takes the pernr from places other than input box of the report category. Right.
    Below is the code. If you want to know anything else, Please let me know.
    Thanks
    Ribhu
    Here is the code:
    REPORT  ZHRtest.
    tables : q0008, pa0001, pa0000, pa0002, pa0014, pa0021, pa0022, pa0008, pa0006, pernr, t500p,t530, t512t, t510, t526, t529t, t528t,
             M_PLOMC, T7INA3, T7INB5, T7INB7, T518B.
    infotypes : 0000, 0001, 0002, 0014, 0021, 0022, 0008, 0006, 0105, 9003.
    data : E_DATE   TYPE SY-DATUM, " Date
           E_ORGUNIT TYPE ORGEH, " Organizational Unit
           E_PERSNO     TYPE P_PERNR, " Personnel Number
    DATA : WS_UCOMM LIKE SY-UCOMM.
    data: begin of pers_tab occurs 0,
    E_SLAB1MIN     TYPE     PIN_MINBS,
    E_SLAB1MAX     TYPE     PIN_MAXBS,
    E_SLAB1INCR     TYPE     PIN_AMINC,
    E_SLAB2MIN     TYPE     PIN_MINBS,
    E_SLAB2MAX     TYPE     PIN_MAXBS,
    E_SLAB2INCR     TYPE     PIN_AMINC,
    end of pers_tab.
    DATA: BEGIN OF WAGETYPES,
    E_LGA LIKE P0008-LGA01,
    E_BET LIKE P0008-BET01,
    E_pernr like pernr-pernr,
    END OF WAGETYPES.
    data : E_lga like pa0008-lga01,
           E_bet like pa0008-bet01.
    data: count type i.
    data : v_year(4) type c,
    v_mon(2) type c,
    v_date like sy-datum,
    v_date1 like sy-datum.
    data : v_formname type tdsfname ,
           v_fmname type rs38l_fnam.
    data: i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
    i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.
    DATA : WAGETYPES1 LIKE BAPIP0008P OCCURS 0 WITH HEADER LINE.
    data: begin of temp_tab occurs 0 ,
    t_minbs type PIN_MINBS,
    t_maxbs type PIN_MAXBS,
    t_aminc type PIN_AMINC,
    end of temp_tab.
    data: hr_pernr like p0000-pernr, " persno of hr emp
    plans_hr like p0001-plans . " position text.
    constants : c_x type c value 'X', " Sign
    c_pernr(8) type n value '00000000', " Pernr
    c_val1(2) type c value '31', " Date Type
    c_val2(2) type c value '12', " Date Type
    c_val like p0041-dar01 value '01', " Date Type
    c_1 like pernr-persg value '1', " Emp Group
    c_type like hrp1001-otype value ' ', " Object Type
    c_date1 like sy-datum value '18000101', " Date
    c_date2 like sy-datum value '99991231', " Date
    r_all value 'X'.
    selection-screen begin of block b2 with frame title text-001.
    selection-screen begin of line.
    parameter pdf radiobutton group smf.
    selection-screen comment 5(20) text-002.
    parameter prn radiobutton group smf.
    selection-screen comment 40(20) text-003.
    selection-screen end of line.
    selection-screen skip 3.
    selection-screen begin of line.
    selection-screen comment 3(30) text-007.
    selection-screen end of line.
    selection-screen begin of line.
    selection-screen comment 5(30) text-004.
    parameter p1 radiobutton group pg.
    selection-screen end of line.
    selection-screen begin of line.
    selection-screen comment 5(30) text-005.
    parameter p2 radiobutton group pg.
    selection-screen end of line.
    selection-screen begin of line.
    selection-screen comment 5(30) text-006.
    parameter p3 radiobutton group pg.
    selection-screen end of line.
    Selection-screen end of block b2.
    ws_ucomm = sy-ucomm.
    *CLEAR PERNR.
    *CLEAR PNPPERNR.
    At selection-screen.
      perform validate_screen.
    start-of-selection.
      perform get_period.
    PERNR-PERNR = 27.<b> <<<<< ----- this is where i tried to hard code</b>
    PNPPERNR-LOW = 27.
      get pernr .
    LOOP AT PERNR.
    *IF PNPPERNR-LOW NE PERNR-PERNR.
    *CLEAR PERNR.
    *ELSE. EXIT.
    *ENDIF.
    *ENDLOOP.
    **PNPPERNR-HIGH = ''.
    E_PERSNO = PNPPERNR-LOW.
      rp_provide_from_last p0000 space pnpbegda pnpendda.
      rp_provide_from_last p0002 space pnpbegda pnpendda .
      rp_provide_from_last p0021 space pnpbegda pnpendda.
      rp_provide_from_last p0022 space pnpbegda pnpendda.
      rp_provide_from_last p9003 space pnpbegda pnpendda.
      describe table p0008 lines count.
      describe table p0001 lines count.
      PERFORM FORM_SELECTION changing P1 P2 P3."<----
    To get the fathers name.
      select FAVOR FANAM from pa0021 into corresponding fields of p0021 where pernr = E_PERSNO and FAMSA = '11'.
        if sy-subrc = 0.
          E_FIRSTNAME = P0021-FAVOR.
          E_LASTNAME = P0021-FANAM.
        endif.
      endselect.
    FORM validate_screen .
    CLEAR PERNR. <b><<<<< ----- this is where i tried to hard code</b>
    PERNR-PERNR = '00000027'.
    PNPPERNR = '00000027'.
    **PNPPERNR-HIGH = ''.
      E_PERSNO = pnppernr-low.
      p9003-pernr = 27.
    *E_PERSNO = p9003-pernr.
    pnppernr-low = E_PERSNO.
    clear sy-index.
    loop at pnppernr.
    endloop.
    if sy-index GT 1.
       message 'Enter only one personal number' type 'E'.
    endif.
    if pnppernr-low is initial.
    PNPPERNR-LOW = '27'.
    message 'enter a personal number' type 'E'.
    endif.
    ENDFORM.                    " validate_screen

  • Export query results to flat file with dynamic filename

    Hi
    Can anybody can point me how to dynamic export query serults set to for example txt file using process flows in OWB.
    Let say I have simple select query
    select * from table1 where daterange >= sysdate -1 and daterange < sysdate
    so query results will be different every day because daterange will be different. Also I would like to name txt file dynamicly as well
    eg. results_20090601.txt, results_20090602.txt, results_20090603.txt
    I cant see any activity in process editor to enter custom sql statment, like it is in MSSQL 2000 or 2005
    thanks in advance

    You can call existing procedures from a process flow the procedure can create the filename with whatever name you desire. OWB maps with file as target can also create a file with a dynamic name defined by an expression (see here ).
    Cheers
    David

  • Dynamic Rule based implementation in PL/SQL

    Hi,
    We are trying to implement a dynamic rule based application in Oracle 9i. Its simple logic where we store expressions as case statments and actions seperated by commas as follows.
    Rule: 'Age > 18 and Age <65'
    True Action: 'Status = ''Valid'' , description = ''age in range'''
    False Action: 'Status =''Invalid'', Description=''Age not in range'''
    Where Age,Status, description are all part of one table.
    One way of implementing this is fire rule for each record in the table and then based on true or false call action as update.
    i.e
    select (case when 'Age > 18 and Age <65' then 1 else 0 end) age_rule from tableX
    (above query will in in a cursor xcur)
    Then we search for
    if age_rule = 1 then
    update tablex set Status = ''Valid'' , description = ''age in range'' where id=xcur.id;
    else
    update tablex set Status =''Invalid'', Description=''Age not in range'' where id=xcur.id;
    end if;
    This method will result in very slow performance due to high i/o. We want to implement this in collection based method.
    Any ideas on how to dynamically check rules and apply actions to collection without impact on performance. (we have nearly 3million rows and 80 rules to be applied)
    Thanks in advance

    Returning to your original question, first of all, there is a small flaw in the requirements, because if you apply all the rules to the same table/cols, than the table will have results of only last rule that was processed.
    Suppose rule#1:
    Rule: 'Age > 18 and Age <65'
    True Action: 'Status = ''Valid'' , description = ''age in range'''
    False Action: 'Status =''Invalid'', Description=''Age not in range'''
    and Rule#2:
    Rule: 'Name like ''A%'''
    True Action: 'Status = 'Invalid'' , description = ''name begins with A'''
    False Action: 'Status =''Invalid'', Description=''name not begins with A'''
    Then after applying of rule#1 and rule#2, results of the rule#1 will be lost, because second rule will modify the results of the first rule.
    Regarding to using collections instead of row by row processing, I think that a better approach would be to move that evaluating cursor inside an update statement, in my tests this considerably reduced processed block count and response time.
    Regarding to the expression filter, even so, that you are not going to move to 10g, you still can test this feature and see how it is implemented, to get some ideas of how to better implement your solution. There is a nice paper http://www-db.cs.wisc.edu/cidr2003/program/p27.pdf that describes expression filter implementation.
    Here is my example of two different methods for expression evaluation that I've benchmarked, first is similar to your original example and second is with expression evaluation moved inside an update clause.
    -- fist create two tables rules and data.
    drop table rules;
    drop table data;
    create table rules( id number not null primary key, rule varchar(255), true_action varchar(255), false_action varchar(255) );
    create table data( id integer not null primary key, name varchar(255), age number, status varchar(255), description varchar(255) );
    -- populate this tables with information.
    insert into rules
    select rownum id
    , 'Age > '||least(a,b)||' and Age < '||greatest(a,b) rule
    , 'Status = ''Valid'', description = ''Age in Range''' true_action
    , 'Status = ''Invalid'', description = ''Age not in Range''' false_action
    from (
    select mod(abs(dbms_random.random),60)+10 a, mod(abs(dbms_random.random),60)+10 b
    from all_objects
    where rownum <= 2
    insert into data
    select rownum, object_name, mod(abs(dbms_random.random),60)+10 age, null, null
    from all_objects
    commit;
    -- this is method #1, evaluate rule against every record in the data and do the action
    declare
    eval number;
    id number;
    data_cursor sys_refcursor;
    begin
    execute immediate 'alter session set cursor_sharing=force';
    for rules in ( select * from rules ) loop
    open data_cursor for 'select case when '||rules.rule||' then 1 else 0 end eval, id from data';
    loop
    fetch data_cursor into eval, id;
    exit when data_cursor%notfound;
    if eval = 1 then
    execute immediate 'update data set '||rules.true_action|| ' where id = :id' using id;
    else
    execute immediate 'update data set '||rules.false_action|| ' where id = :id' using id;
    end if;
    end loop;
    end loop;
    end;
    -- this is method #2, evaluate rule against every record in the data and do the action in update, not in select
    begin
    execute immediate 'alter session set cursor_sharing=force';
    for rules in ( select * from rules ) loop
    execute immediate 'update data set '||rules.true_action|| ' where id in (
    select id
    from (
    select case when '||rules.rule||' then 1 else 0 end eval, id
    from data
    where eval = 1 )';
    execute immediate 'update data set '||rules.false_action|| ' where id in (
    select id
    from (
    select case when '||rules.rule||' then 1 else 0 end eval, id
    from data
    where eval = 0 )';
    end loop;
    end;
    Here are SQL_TRACE results for method#1:
    call count cpu elapsed disk query current rows
    Parse 37 0.01 0.04 0 0 0 0
    Execute 78862 16.60 17.50 0 187512 230896 78810
    Fetch 78884 3.84 3.94 2 82887 1 78913
    total 157783 20.46 21.49 2 270399 230897 157723
    and this is results for method#2:
    call count cpu elapsed disk query current rows
    Parse 6 0.00 0.00 0 0 0 0
    Execute 6 1.93 12.77 0 3488 170204 78806
    Fetch 1 0.00 0.00 0 7 0 2
    total 13 1.93 12.77 0 3495 170204 78808
    You can compare this two methods using SQL_TRACE.

Maybe you are looking for

  • Nike+ ipod not working since upgrading to ios5

    I used to link my phone to the Matrix machines which are Nike+ iPod compliant. It used to be fine, I used to run, the runs were never displayed as historic data on the phone but when I synced my phone with iTunes it used to update the website. This w

  • Multi-module Maven and Flash Builder 4

    Sorry for cross-posting this, but I responded to: http://forums.adobe.com/message/3235768#3235768 which was posted in the Flex forum, and this is more about Flash Builder. The issue is that content assist doesn't work with a multi-module maven projec

  • Turning off Incredibe location notice on power up

    I have mobile defense installed in the unlikely event that my phone is ever stolen. However on startup it always ask if I would like to turn location off. As gps is fairly important for mobile defense to work...sort of defeats the purpose to ask a th

  • What is better for college? An iPad air or an iPad mini with retina display?

    I'm currently a junior in high school and I'll be graduating in the summer of 2015. My parents, well mostly dad, are planning on buying me the iPad air with 128 GB of memory. I got curious and went to look at the price and compare models and I saw th

  • How to call one form to another form in JDeveloper

    hai, i am new to JDeveloper. i am having 2 forms contains some textfields and buttons. when i click button in one form then the second form opens and the first forms also appears remains in back. any one knows about this just tell how to do this. tha