ORACLE DYNAMIC SQL

i am writing generic code for deletion based on DYN input table.
i have problem to build SQL AND CALUSE.
HERE IS THE CODE.
STEP 1: CREATE INPUT TABLE
TABLE : DYN
APP_MODEULE APP_MODEULE_ID SNO EMPNO
X123 CAR 1 1
X145 CAR 2 1
STEP 1: CREATE GENERATE SP TO DELETE
CREATE OR REPLACE PROCEDURE TESTING_SQL
P VARCHAR2 , --- APP_MODULE
S VARCHAR2 , -- APP_MODEULE_ID
C INTEGER , -- SNO
F INTEGER) -- EMPNO
AS
cursor c_tables
is
select
TABLE_NAME FROM dyn WHERE APP_MODULE = P AND app_module_ID = S;
cursor c_cols
is
select i.column_name
from all_tab_columns i
where i.owner = 'XXX'
and i.table_name IN ( SELECT TABLE_NAME FROM dyn WHERE APP_MODULE = P AND app_module_ID = S )
order by column_id;
where_clause VARCHAR2(32767);
and_clause VARCHAR2(32767);
begin
for rec in c_tables loop
where_clause := NULL ;
for col in c_cols loop
if where_clause is NULL then
where_clause := ' WHERE ' || col.column_name || '=' || C ;
else
where_clause := where_clause || ' AND ' || col.column_name || '=' || F;
end if;
end loop;
begin
EXECUTE IMMEDIATE 'DELETE FROM '||REC.table_name|| where_clause ;
dbms_output.put_line(REC.table_name||', '||SQL%ROWCOUNT);
-- commit;
exception
when others then
dbms_output.put_line(REC.table_name||', '||SQLERRM);
rollback;
end;
end loop;
end;
set serveroutput off
spool off
PL/SQL RUN CALL: ( I HOPE I HAVE PROBLEM WITH BUILDING WHERE CLAUSE & AND CONDITION,PLEASE HELP ME TO RESOLVE THIS ISSUE )
SET SERVEROUTPUT ON
DECLARE
P VARCHAR2(32767);
S VARCHAR2(32767);
BEGIN
P := NULL;
S := NULL;
VINLOAD.TESTING_SQL ( 'CTS', 'CAR' , 3, 472863 );
--MMIT;
END;
WHILE RUNNING I AM GETTING ERROR: PLEASE HELP ME TO FIX THIS ISSUE
ORA-00933: SQL command not properly ended

user4485803 wrote:
i am writing generic code for deletion based on DYN input table.BAD, NON-SCALABLE & INEFFICIENT way to code!
i have problem to build SQL AND CALUSE.
HERE IS THE CODE.
STEP 1: CREATE INPUT TABLE
TABLE : DYN
APP_MODEULE APP_MODEULE_ID SNO EMPNO
X123 CAR 1 1
X145 CAR 2 1
STEP 1: CREATE GENERATE SP TO DELETE
CREATE OR REPLACE PROCEDURE TESTING_SQL
P VARCHAR2 , --- APP_MODULE
S VARCHAR2 , -- APP_MODEULE_ID
C INTEGER , -- SNO
F INTEGER) -- EMPNO
AS
cursor c_tables
is
select
TABLE_NAME FROM dyn WHERE APP_MODULE = P AND app_module_ID = S;
cursor c_cols
is
select i.column_name
from all_tab_columns i
where i.owner = 'XXX'
and i.table_name IN ( SELECT TABLE_NAME FROM dyn WHERE APP_MODULE = P AND app_module_ID = S )
order by column_id;
where_clause VARCHAR2(32767);
and_clause VARCHAR2(32767);
begin
for rec in c_tables loop
where_clause := NULL ;
for col in c_cols loop
if where_clause is NULL then
where_clause := ' WHERE ' || col.column_name || '=' || C ;
else
where_clause := where_clause || ' AND ' || col.column_name || '=' || F;
end if;
end loop;
begin
EXECUTE IMMEDIATE 'DELETE FROM '||REC.table_name|| where_clause ;
dbms_output.put_line(REC.table_name||', '||SQL%ROWCOUNT);
-- commit;
exception
when others then
dbms_output.put_line(REC.table_name||', '||SQLERRM);
rollback;
end;
end loop;
end;
set serveroutput off
spool off
PL/SQL RUN CALL: ( I HOPE I HAVE PROBLEM WITH BUILDING WHERE CLAUSE & AND CONDITION,PLEASE HELP ME TO RESOLVE THIS ISSUE )
SET SERVEROUTPUT ON
DECLARE
P VARCHAR2(32767);
S VARCHAR2(32767);
BEGIN
P := NULL;
S := NULL;
VINLOAD.TESTING_SQL ( 'CTS', 'CAR' , 3, 472863 );
--MMIT;
END;
WHILE RUNNING I AM GETTING ERROR: PLEASE HELP ME TO FIX THIS ISSUE
ORA-00933: SQL command not properly endedThe standard advice when (ab)using EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
Then print the variable before passing it to EXECUTE IMMEDIATE.
COPY the statement & PASTE into sqlplus to validate its correctness.
delete, remove, & eliminate all EXCEPTION code
For reason why check these links.
http://tkyte.blogspot.com/2007/03/dreaded-others-then-null-strikes-again.html
http://tkyte.blogspot.com/2008/01/why-do-people-do-this.html
http://tkyte.blogspot.com/2007/03/challenge.html

Similar Messages

  • Whether timestamp types are supported in oracle dynamic sql?

    Oracle has two dynamic sql models. The old and the new ANSI model. I wish to know where and how the timestamp oracle data types are supported.
    I am having trouble setting the timestamp data through pro*c using old dynamic sql. I tried to set it to raw 11 bytes and use type 187 (timestamp) and it segfaults! I try now to set it to string type and oracle says invalid month! I tried even using nls_timestamp_format setting but no luck. Obviously some thing is amiss.
    Can some body help me?
    I need this info rather urgently.
    Thanks.

    Yes it is possible
    TO_DATE(:variable,'FORMAT') in dynamic SQL

  • Dynamic SQL : passing table name as parameter

    Hi
    I have a SQL query (a store procedure )  that i want to convert to PLSQL
    This is a part of my SQL query that i am trying to to find a solution for it, because i cant convert it to oracle :
    DECLARE lookupTableRow CURSOR FOR
      SELECT TableName FROM SYS_LookUpTable
      OPEN lookupTableRow
      FETCH NEXT FROM lookupTableRow INTO @tableName
      WHILE @@FETCH_STATUS=0
      BEGIN
      SET @sql='SELECT * FROM '+@tableName
    EXECUTE sp_executesql @sql
      IF @counter=0
      BEGIN
      INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table', @tableName)
      END
      ELSE
      BEGIN
      INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table'+CONVERT(NVARCHAR(10),@counter), @tableName)
      END
      SET @counter=@counter+1
      FETCH NEXT FROM lookupTableRow INTO @tableName
      END
      CLOSE lookupTableRow
      DEALLOCATE lookupTableRow
    As i understand i can't use ORACLE dynamic sql (execute immediate) when the table name is a parameter
    Furthermore when i execute this dynamic query in my SQL store procedure each SELECT statement return me as a result the relevant table rows , those result are different in each loop .
    So i cant do this too with ORACLE dynamic sql .
    Please advice for any solution
    * how can i use dynamic sql with table name as parameter ?
    * how can i use a "dynamic" cursor, in order to be able to display the dynamic results ?
    Thanks for the advice

    Hi,
    b003cf5e-e55d-4ff1-bdd2-f088a662d9f7 wrote:
    Hi
    I have a SQL query (a store procedure )  that i want to convert to PLSQL
    This is a part of my SQL query that i am trying to to find a solution for it, because i cant convert it to oracle :
    DECLARE lookupTableRow CURSOR FOR
      SELECT TableName FROM SYS_LookUpTable
      OPEN lookupTableRow
      FETCH NEXT FROM lookupTableRow INTO @tableName
      WHILE @@FETCH_STATUS=0
      BEGIN
      SET @sql='SELECT * FROM '+@tableName
    EXECUTE sp_executesql @sql
      IF @counter=0
      BEGIN
      INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table', @tableName)
      END
      ELSE
      BEGIN
      INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table'+CONVERT(NVARCHAR(10),@counter), @tableName)
      END
      SET @counter=@counter+1
      FETCH NEXT FROM lookupTableRow INTO @tableName
      END
      CLOSE lookupTableRow
      DEALLOCATE lookupTableRow
    As i understand i can't use ORACLE dynamic sql (execute immediate) when the table name is a parameter
    Furthermore when i execute this dynamic query in my SQL store procedure each SELECT statement return me as a result the relevant table rows , those result are different in each loop .
    So i cant do this too with ORACLE dynamic sql .
    Please advice for any solution
    * how can i use dynamic sql with table name as parameter ?
    * how can i use a "dynamic" cursor, in order to be able to display the dynamic results ?
    Thanks for the advice
    I have a SQL query (a store procedure )  that i want to convert to PLSQL
    I doesn't help when you use one term to mean another thing.
    SQL is a language used in both Oracle and other products, such as Microsoft's SQL Server. I don't know much about SQL Server, but Oracle (at least) doesn't support stored procedures in SQL itself; they have to be coded in some other language, such as PL/SQL.  
    As i understand i can't use ORACLE dynamic sql (execute immediate) when the table name is a parameter
    If the table name is a parameter (or only known at run-time for any reason), that's exactly the kind of situation where you MUST use dynamic SQL.
    The number of columns that a query produces (and their datatypes) is fixed when you compile a query, whether that query is dynamic or not.  If you have multiple queries, that produce result sets with different numbers of columns, then you can't combine them into a single query.  The best you can do with one query is to add NULL columns to some of the queries so they all produce the same number of columns.
    If you're just displaying the results, there might not be any reason to combine separate result sets.  Just display one result set after another.
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Can we use Dynamic SQL in Oracle Reports ?

    Hi ,
    Can we use Dynamic SQL in Oracle Reports ?
    If yes please give some examples .
    Thanx
    srini

    I believe the built-in package SRW.Do_Sql is what you are looking for
    Example from the document:
    /* Suppose you want to create a "table of contents" by getting the
    ** first character of a columns value, and page number on which its
    ** field fires to print. Assume that you want to put the "table of
    contents"
    ** into a table named SHIP. You could write the following construct:
    DECLARE
    PAGE_NO NUMBER;
    PAGE_FOR INDEX NUMBER;
    SORT_CHAR CHAR(1);
    CMD_LINE CHAR(200);
    BEGIN
    SORT_CHAR := :SORT_NAME ;
    IF :CALLED = Y THEN
         SRW.GET_PAGE_NUM(PAGE_FOR_INDEX);
         SRW.USER_EXIT(RWECOP PAGE_FOR_INDEX
         P_START_PAGENO);
         SRW.MESSAGE(2,TO_CHAR(:P_START_PAGENO));
    END IF;
    SRW.GET_PAGE_NUM(PAGE_NO);
    CMD_LINE := INSERT INTO SHIP VALUES
                          (||SORT_CHAR||,||TO_CHAR(PAGE_NO)||);
    SRW.MESSAGE(2,CMD_LINE);
    SRW.DO_SQL(CMD_LINE);
    COMMIT;
    EXCEPTION
      WHEN DUP_VAL_ON_INDEX THEN
            NULL;
      WHEN SRW.DO_SQL_FAILURE THEN
            SRW.MESSAGE(1,FAILED TO INSERT ROW INTO SHIP TABLE);
      WHEN OTHERS THEN
           COMMIT;
    END;

  • Dynamic SQL and Oracle stored procedures

    Does anybody has any experience with invoking an Oracle stored procedures
    with output parameters, using dynamic SQL from Forte?
    Thanks,
    Dimitar

    I would be interested. We are currently using a homegrown DataMapper architecture with the Microsoft OracleClient. I would like to move to ODP.Net once a production version supporting ADO.Net 2.0 is available. After that, I would then like to look at using an off the shelf persistence framework such as EntitySpaces, NHibernate or IdeaBlade's DevForce.

  • Delcare Cursor using Dynamic SQL using PL/SQL in Oracle 7.3.4

    In Oracle 7.3.4, can I declare a cursor at run time using Dynamic SQL. From the sample code in this website, it seems that Oracle 8 support this function. Please help. Thanks a lot.
    If I can do this on Oracle 7.3.4, could you give me some sample codes? Thanks.
    Regards,
    Raymond

    Hi,
    Try using the the following code where you can dynamically build the Valid Select stmt. and call that where ever you want.
    declare
    Type Cur_ref Is Ref Cursor;
    C_ref Cur_ref;
    V_Str Varchar2(100);
    V_Name Varchar2(100);
    Begin
    V_Str := 'Select Ename from Scott.emp Where empno = 7369';
    Open C_Ref for V_Str;
    Fetch C_ref Into V_Name;
    close C_Ref;
    dbms_output.put_line(V_Name);
    End;
    regards
    gaurav
    null

  • Oracle to MS SQL porting - dynamic sql - cursors

    I have a stored procedure written for oracle which needs to be ported to MS SQL. Used SSMA to do that but the dynamic sql statements are not getting ported and are the same. Below is a dynamic sql from the SP after making changes with SSMA.
    SET @dsql_statement =
    'declare '
    +
    ' p table_name%rowtype;'
    +
    ' c table_name%rowtype;'
    +
    ' TYPE DAT IS REF CURSOR;'
    +
    ' type dtt is table of table_name1%rowtype index by binary_integer;'
    +
    ' d dtt;'
    +
    ' aRC DAT;'
    +
    ' sq varchar2(1000);'
    +
    ' i NUMBER:=0;'
    +
    ' attributeLabel nvarchar2(255);'
    +
    ' attributename nvarchar2(255);'
    +
    ' attributetype nvarchar2(255);'
    +
    ' fkvalue nvarchar2(255);'
    +
    ' defaultfield nvarchar2(80);'
    +
    ' tablename nvarchar2(80);'
    +
    ' primarykeyfield nvarchar2(80);'
    +
    ' begin '
    +
    ' sq:=''SELECT * FROM mdbadmin.table_name WHERE lower(COLUMN1) IN'
    +
    ' (''''update'''',''''insert'''') AND COLUMN2 >= '
    +
    ISNULL(CAST(@COLUMN2 AS nvarchar(max)), '')
    +
    +
    ' ORDER BY COLUMN3,COLUMN2 ASC'';'
    +
    ' open aRC for sq;'
    +
    ' fetch aRC into c;'
    +
    ' loop '
    +
    ' fetch aRC into p;'
    +
    ' exit when aRC%NOTFOUND;'

    Some thing like
    dsql_statement :=  'begin '
    || ' for I in (SELECT * FROM mdbadmin.table_name WHERE lower(COLUMN1) IN '
    || ' (''update'',''insert'') AND COLUMN2 >= '
    || 'NVL(to_char('||'@COLUMN2'||'), '''') '
    || ' ORDER BY COLUMN3,COLUMN2 ASC ) '
    || 'loop '
    || 'end loop; '
    || 'end; '
    you can use for loop instead

  • Dynamic SQL in non oracle Data Template

    Hi All
    I am currently working on a project with BI Publisher and we are developing on an OBIEE data source using data templates.
    Does anyone know how to handle dynamic sql &Lexicals when your only data source is OBIEE.
    I have found some code in the help which doesn't seem to work.
    {$ if ${P_COUNTRY} = '*,*' $}
    WHERE "Customers"."Country" in (&P_COUNTRY)
    {$ elsif ${P_COUNTRY} = '*' $}
    WHERE "Customers"."Country" = :P_COUNTRY
    {$ else $}
    {$ endif $}
    Thanks
    Andy

    Hi Andy,
    If you are using Answers as data source, Dynamic query is not possible.

  • Avoid Hard Parsing for executing dynamic SQL using DUAL table Oracle

    I want to know if dynamic sql statements involving DUAL table can be modified to remove HARD PARSING.
    We have several SQL statements are stored in configuration table, here is sample example
    -- query 1 before replacing index values as stored in config table ---
    select count(*) from dual where  'REPLACE_VALUE_OF_INDEX_3' IN ('K')
    AND (('REPLACE_VALUE_OF_INDEX_13' IN ('1053','1095','1199') ) OR ('REPLACE_VALUE_OF_INDEX_13' IN ('1200') ))
    AND 'REPLACE_VALUE_OF_INDEX_2' IN ('6')
    AND 'REPLACE_VALUE_OF_INDEX_15' IN ('870001305')
    -- query 1 after replacing index values--
    select count(*) from dual where  'REPLACE_VALUE_OF_INDEX_10' IN ('K')
    AND (('1030' IN ('1053','1095','1199') ) OR ('1030' IN ('1200') ))
    AND '2' IN ('6')
    AND 'X' IN ('870001305')
    -- query 2 before replacing index values as stored in config table --
    select count(*) from dual where  'REPLACE_VALUE_OF_INDEX_5' IN ('361A','362A')
    AND 'REPLACE_VALUE_OF_INDEX_22' BETWEEN '200707' AND '200806'
    -- query 2 after replacing index values--
    select count(*) from dual where  '3MAA' IN ('361A','362A') AND '201304' BETWEEN '200707' AND '200806'

    If I got it right you have some (maybe lots of) conditions stored in a table (be patient - it's my interpretation)
    create table eb_conditions as
    select 1 rid,q'{:5 IN ('361A','362A') AND :3 BETWEEN '200707' AND '200806'}' cndtn from dual union all
    select 2,q'{:2 IN ('361A','362A') AND :3 BETWEEN '200707' AND '200806'}' from dual union all
    select 3,q'{:1 IN ('K') AND ((:2 IN ('1053','1095','1199') ) OR (:4 IN ('1200') )) AND :3 IN ('6') AND :5 IN ('870001305')}' from dual
    RID
    CNDTN
    1
    :5 IN ('361A','362A') AND :3 BETWEEN '200707' AND '200806'
    2
    :2 IN ('361A','362A') AND :3 BETWEEN '200707' AND '200806'
    3
    :1 IN ('K') AND ((:2 IN ('1053','1095','1199') ) OR (:4 IN ('1200') )) AND :3 IN ('6') AND :5 IN ('870001305')
    and you have to check the conditions using values stored in an array
    I used a table instead: the vl at rid = 1 representing the value of bind variable :1 in eb_conditions table and so on ...
    create table eb_array as
    select 1 rid,'K' vl from dual union all
    select 2,'1199' from dual union all
    select 3,'200803' from dual union all
    select 4,'1000' from dual union all
    select 5,'870001305' from dual
    RID
    VL
    1
    K
    2
    1199
    3
    200803
    4
    1000
    5
    870001305
    You want to check the conditions using select count(*) from dual where <condition with binds substituted fron the array>
    Judging from the title Hard Parsing represents the major problem and you cannot avoid it since every condition to be verified is different from every other condition.
    I think your best bet is not to evaluate conditions row by row - context shift cannot be avoided and there might be more than one for each iteration.
    So try to do it in a single step:
    declare
    w_cndtn varchar2(4000);
    w_clob  clob;
    w_cursor sys_refcursor;
    one number;
    two number;
    begin
      dbms_lob.createtemporary(w_clob,false);
      for rw in (select rid,
                        max(cndtn) cndtn,
                        listagg(val,',') within group (order by rn)||',' usng
                   from (select c.rid,c.cndtn,c.rn,c.bind,
                                replace(rtrim(c.bind),':'||to_char(v.rid),''''||v.vl||'''') val
                           from (select rid,
                                        cndtn,
                                        regexp_substr(cndtn,':\d+ ',1,level) bind,
                                        level rn
                                   from eb_conditions
                                 connect by level <= regexp_count(cndtn,':')
                                        and prior rid = rid
                                        and prior sys_guid() is not null
                                ) c,
                                eb_array v
                          where instr(c.bind,':'||v.rid||' ') > 0
                  group by rid
      loop
        w_cndtn := rw.cndtn;
        while instr(w_cndtn,':') > 0
        loop
          w_cndtn := replace(w_cndtn,trim(regexp_substr(w_cndtn,':\d+ ',1,1)),substr(rw.usng,1,instr(rw.usng,',') - 1));
          rw.usng := substr(rw.usng,instr(rw.usng,',') + 1);
        end loop;
        w_cndtn := 'select '||to_char(rw.rid)||' cndtn_id,count(*) from dual where '||w_cndtn||' union all ';
        w_clob := w_clob ||' '||w_cndtn;
      end loop;
      w_clob := substr(w_clob,1,instr(w_clob,'union all',-1,1) - 1);
      open w_cursor for w_clob;
      loop
        fetch w_cursor into one,two;
        exit when w_cursor%notfound;
        dbms_output.put_line(to_char(one)||':'||to_char(two));
      end loop;
      dbms_lob.freetemporary(w_clob);
    end;
    1:0
    2:0
    3:0
    Statement processed.
    Regards
    Etbin

  • Check Results of Dynamic SQL- Oracle

    Hi,
    Can anyone help me to know if I can use a check to verify if a Dynamic SQL query returns NO ROWS.
    Suppose:
    LC_SQL := 'select * from tableA'
    EXECUTE IMMEDIATE LC_SQL;
    I now need to check if on execution LC_SQL fetches 0 rows.

    Few modifications required.
    declare
    v_count number;
    lc_sql varchar2(200);
    begin
    LC_SQL := 'select count(*) from tableA';
    EXECUTE IMMEDIATE LC_SQL into V_COUNT;
    IF V_COUNT = 0
         then
              dbms_output.put_line('NO ROWS RETURNED');
        else
            dbms_output.put_line('Data Exists');
    end if;
    end;
    BTW, if the requirement is to check if data is there in the table or not, there is no need of using Dynamic SQL. If you are checking the data for multiple tables and table names are dynamic, then you need to go with Dynamic SQL.
    Ishan

  • NULL and dynamic SQL

    If table testrh2 has the following columns and data
    col1 --> NULL
    col2 --> 2
    and table testrh has the following columsn and data
    col1 --> NULL
    How could I write a dynamic SQL statement to join on the nulls? I've written the following block as a starting point.
    declare
    cursor c1 is select col1 from isis.testrh;
    lval varchar2(1000);
    lval2 varchar2(1000);
    begin
    for r1 in c1 loop
    lval := 'select col2 from isis.testrh2 where col1 = '||r1.col1;
    execute immediate lval into lval2;
    dbms_output.put_line(lval2);
    end loop;
    end;

    You can't compare null values with '=' in Oracle SQL.
    Null can only be compared with <column> is null .
    You can see it when you try these two queries:
    select * from dual where null is null;  -- you will see one row
    select * from dual where null=null;  -- you will see no rowsThat's why you have to write something like
    (<column1>=<column1>   or   (<column1> is null and <column2> is null))This should also work with null:
    decode(<column1>,<column2>,1,0)=1By the way, why do you use dynamic sql?
    lval := 'select col2 from isis.testrh2 where col1 = '||r1.col1;
    I think you could replace your two lines ( lval:= ... AND execute immediate) by this:
    begin
      select col2
      into lval
      from isis.testrh2
      where decode(col1,r1.col1,1,0)=1;
      dbms_output.put_line('lval='||lval);
    exception
    when no_data_found then
      dbms_output.put_line('no data found'); -- or whatever you want
    end;Edited by: hartmutm on 02.10.2010 23:54

  • Unique id in dynamic sql

    hi all,
    I am using oracle 10g version.
    I have one table but i do not have any unique id to identify the row.
    I want to have a unique id temporarily in my select statement (dynamic sql) in a stored procedure while fetching the results, so that i can return my results along with the unique id through the cursor.
    Please help me...
    Thanks in advance to all...

    it depends if you have a more than one column that you can uniquely identify and put them together by concatenating you can have a unique id. or a rowid might help you to temporarily identify a row.
    SQL> select e.* from employee e;
    FNAME           MINIT LNAME           SSN       BDATE       ADDRESS                        SEX       SALARY SUPERSSN         DNO
    John            B     Smith           123456789 09-Jan-1965 731 fONDREN, hOUSTON, TX       M       30000.00 333445555          5
    Frankin         T     Wong            333445555 08-Dec-1955 683 Voss, Houston,Tx           M       40000.00 888665555          5
    Alicia          J     Zelaya          999887777 19-Jul-1968 3321Castle, Spring, TX         F       25000.00 987654321          4
    Jennifer        S     Wallace         987654321 20-Jun-2041 291 Berry, Bellaire, TX        F       43000.00 888665555          4
    Ramesh          K     Narayan         666884444 15-Sep-1962 975 Fire Oak, Humble, TX       F       38000.00 333445555          5
    Joyce           A     English         453453453 31-Jul-1972 5631 Rice,Houston,TX           F       25000.00 333445555          5
    Ahmad           V     Jabbar          987987987 29-Mar-1969 980 Dallas,Houston, TX         M       25000.00 987654321          4
    James           E     Borg            888665555 10-Nov-2037 450 Stone, Houston, TX         M       55000.00                    1
    8 rows selected
    SQL> select rowid, e.* from employee e;
    ROWID              FNAME           MINIT LNAME           SSN       BDATE       ADDRESS                        SEX       SALARY SUPERSSN         DNO
    AAD8pbAAJAAAJ4fAAA John            B     Smith           123456789 09-Jan-1965 731 fONDREN, hOUSTON, TX       M       30000.00 333445555          5
    AAD8pbAAJAAAJ4fAAB Frankin         T     Wong            333445555 08-Dec-1955 683 Voss, Houston,Tx           M       40000.00 888665555          5
    AAD8pbAAJAAAJ4fAAC Alicia          J     Zelaya          999887777 19-Jul-1968 3321Castle, Spring, TX         F       25000.00 987654321          4
    AAD8pbAAJAAAJ4fAAD Jennifer        S     Wallace         987654321 20-Jun-2041 291 Berry, Bellaire, TX        F       43000.00 888665555          4
    AAD8pbAAJAAAJ4fAAE Ramesh          K     Narayan         666884444 15-Sep-1962 975 Fire Oak, Humble, TX       F       38000.00 333445555          5
    AAD8pbAAJAAAJ4fAAF Joyce           A     English         453453453 31-Jul-1972 5631 Rice,Houston,TX           F       25000.00 333445555          5
    AAD8pbAAJAAAJ4fAAG Ahmad           V     Jabbar          987987987 29-Mar-1969 980 Dallas,Houston, TX         M       25000.00 987654321          4
    AAD8pbAAJAAAJ4fAAH James           E     Borg            888665555 10-Nov-2037 450 Stone, Houston, TX         M       55000.00                    1
    8 rows selected
    SQL>

  • Dynamic sql and cursors

    We are running an oracle sql procedure that uses a LOT of dynamic sql. We are using a 3rd party package (SQR) as a sort of shell to run the sql procedure. The 3rd party package passes to us an oracle error. This error says, in effect, that there are no inactive database cursors available and that the sql program is too large to process. We conclude from this that we must increase one or more of the cursor parameters in init.ora (v$parameters). Is this the correct assumption? If not, does anyone know what we can do? We'd prefer not to break up the sql procedure into smaller pieces.

    increase the parameter for open cursors.
    check, wether all cursors in your programs are closed in time, or if you are using ref cursors from front-ends (e.g. Java JDBC) that this front-ends close these ref cursors , too.
    If you want to decrease the size of procedures get rid of comments, superfluos spaces, tabs, etc.
    keep a commented version outside vor documentation purposes.
    Hope thsi helps

  • Dynamic SQL and PL/SQL Gateway

    This question is kind of out of curiosity...I had created a procedure that used some dynamic sql (execute immediate), and was trying to use it on pl/sql gateway. I kept getting page not found errors until I removed the execute immediate statement, and reverted to using static sql statements.
    I am just curious, is dynamic sql not supported at all with pl/sql gateway?
    Thanks
    Kevin

    > Relax damorgan, no need to be condescending. Of course I read the docs ..
    Well, you're one of the few that actually read the docs.. And one of many that lacked to state any real technical details for forum members to understand the actual problem, the actual error, and what the environment is that this is happening in.
    Remember that you came to this forum for forum members to help you. In order for us to do that, you need to help us understand
    - your problem
    - your environment
    - what you have tried
    What PL/SQL Gateway do you refer to? Thus is an old term for an old product - today in Oracle there are two "gateways" into the PL/SQL engine via HTTP. Via Apache/mod_plsql and via the internal Java servlet web engine called EPG inside Oracle.
    As for what the "Gateway" access to the PL/SQL engine via HTTP.. whether it supports EXECUTE IMMEDIATE or not is like asking if a car "supports" soft drinks or not (just because a human that may consume soft drinks acts as the driver of the car). Not sensible or relevant at all.
    mod_plsql creates an Oracle session to the database instance, and executes a PL/SQL procedure in the database. This is no different from any other client connection to Oracle. Oracle has no clue that the client is mod_plsql and not TOAD or Java or VB or PHP or Perl or whatever else.
    So how can this support or not support the EXECUTE IMMEDIATE command? Does PL/SQL support EXECUTE IMMEDIATE? Well duh...
    Why do you get a generic 404? Because the PL/SQL call made by mod_plsql failed with an unhandled exception. mod_plsql gets that exception and now what? Was a valid HTP buffer created for it to stream to the web browser? If the buffer perhaps partially completed? All that mod_plsql knows is that it asked for a HTP buffer via that PL/SQL call and it got an exception in return.
    A 404 HTTP error is the only reasonable and logical response for it to pass to the web browser in this case.
    PS. to see why mod_plsql fail, refer to the access_log and error_log of that Apache httpd server

  • Dynamic SQL and Data with Single Quotes in it.

    Hi There,
    I have a problem in that I am using dynamic SQL and it happens that one of the columns does contain single quotes (') in it as part of the data. This causes the resultant dynamic SQL to get confused as the single quote that is part of the data is taken to mean end of sting, when in fact its part of the data. This leaves out a dangling single quote that was meant to enclose the string. Here is my dynamic SQL and the result of the parsed SQL that I have captured:
    ****Dynamic SQL*****
    l_sql:='select NOTE_TEMPLATE_ID '||
    'FROM TMP_NOTE_TEMPLATE_VALUES '||
    'where TRIM(LEGACY_NOTE_CODE)='''||trim(fp_note_code)||''' '||
    'and TRIM(DISPLAY_VALUE)='''||trim(fp_note_text)||''' ';
    execute immediate l_sql INTO l_note_template_id;
    Because the column DISPLAY_VALUE contains data with single quotes, the resultant SQL is:
    ******PARSED SQL************
    select NOTE_TEMPLATE_ID
    FROM TMP_NOTE_TEMPLATE_VALUES
    where TRIM(LEGACY_NOTE_CODE)='INQ' and TRIM(DISPLAY_VALUE)='Cont'd'
    And the problem lies with the single quote between teh characters t and d in the data field for DISPLAY_ITEM. How can I handle this?
    Many thanks,

    I have been reliably informed that if one doesn't enclose char/varchar2 data items in quotes, the right indices may not be usedI am into oracle for past 4 years and for the first time i am hearing this.
    Your reliable source is just wrong. Bind variables are variables that store your value and which are used in SQL. They are the proper way to use values in your SQL. By default all variables in PL/SQL is bind variable.
    When you can do some thing in just straight SQL just do it. Dynamic SQL does not make any sense to me here.
    Thanks,
    Karthick.

Maybe you are looking for

  • Error while updating Curve 9300 OS to Os6 Pls help!

    While I was updating my Blackberry Curve 9300 this notice popped up "An error has occurred while downloading software for your device.  Please verify your Internet connection or try again later, if the problem persists." My internet connection is fin

  • Active business Vendor List

    Hi, Can you please let me know any report for active business vendor standard report to execute past 1 year. We can try from BSIK and BSAK but any other way to extract only vendor master list which has business with us. Best Regards, RK

  • PageMaker 7 +Acrobat Pro 9.0

    Acrobat Pro 7 installed a pdf icon to print to pdf with embedded fonts in PageMaker 7. Will Acrobat 9 do the same thing? I lost that icon and ability when I installed the trial version of Acrobat 9 and am hoping it was due to the trial, not having th

  • HELP! Deleted a Keychains file. X509

    a Keychains folder that contained the X509 certificates was accidentally deleted. I now cannot use Mail. How can I get this back on my system correctly?

  • Forward / Reverse Button on Slideshow

    Maybe I need to re-word my last post - I have made a slideshow which I want to play thru so I removed the "stop" action. But how do I incorporate a "forward" and "back" button that would also work if hit?