Dynamic SQL Qeury.

If the SELECT query has dynamic WHERE clause then in CRM side it fails if the number of records are more than 13000 in table from where we are picking up the values. We have used it many a place in whole application. Is there any way to handle it by configuring System level change rather than changing the code? We have problems in changing the code as it is used in multiple locations in whole custom application.
Example1:
DELETE FROM <table1> WHERE <field1> IN ( SELECT <field1> FROM <table2>
WHERE <field2> = <var2> ).
<table1> has more than 13000 records.
Thank you.
Cheers,
Ashish

Hello Asish,
This is b'coz the SQL statement you've coded exceeds maximum length of the SQL statement for your SAP release.(Search for relevant OSS Notes, you can check ABAP forums as well i remember a discussion on this 1-2 weeks back)
The Open SQL statement with the range (after the 'IN' keyword) is parsed before being forwarded to the DB layer & if your range contains too many recs your DELETE stmt will result in a runtime error.
BR,
Suhas

Similar Messages

  • 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

  • How to rename C00n generic column names in a Dynamic SQL report

    I have a an interface whereby the user can select 1 to 60 (upper limit) columns out of 90 possible columns (using a shuttle) from one table before running a report.
    To construct the SQL that will eventually execute, I'm using a "PLSQL function body returning SQL query" with dynamic SQL. The only problem is that I have to use "Generic Column Names" option to be able to compile the code and end up with c001 to c060 as the column names.
    How can I use the names of the selected columns as the report headings rather than c001, C002... etc?
    I do not know beforehand which columns, or how many columns or the order of the selected columns.
    I know Denes K has a demo called Pick Columns but I can't access his code. I have a hunch though that he may be just using conditions to hide/show the apropriate columns.
    thanks in advance
    PaulP

    Hi Paul
    I would change the Heading Type in the Report Details screen to PLSQL and use the shuttle item to return the column values. e.g.
    RETURN :p1_shuttle;
    I'm assuming the shuttle already has a colon separated list of the column headings in the correct order?
    I hope that helps
    Shunt

  • 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>

  • 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;

  • How to mention numbers in array while creating dynamic sql

    Hi,
    I am creating a dynamic sql and in that I am selecting some rows from the table and storing it into the array.
    I am firing this sql statement within trigger.
    But i got the error:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    I took the same sql statement (the one which was created dynamically) in the procedure and tried to run it but it gave me the same error.
    =========================================================
    Begin
    type NewValueArray is table of varchar2(4000);
    nVal_Array NewValueArray;
    Begin
    Select
    DISCOVERYHOSTNAME,
    DISCOVERYMACPRIMARYPHYSICAL,
    DISCOVERYSERIALNUMBER
    into
    nVal_Array(1),
    nVal_Array(2),
    nVal_Array(3)
    from ALT_42_Consolidated
    where rowid = 'AAEWNEABXAAAAkxAAA';
    EXCEPTION
    WHEN others THEN
    Raise;
    End;
    =========================================================
    I tried using to_number but still the same error.
    Can some body please inform me where I am goofing.
    Thanks!

    I got a different error, but you need to initialise your nval_array and make sure it can hold three values. The following should work:
    declare
      type NewValueArray is table of varchar2(4000);
      nVal_Array NewValueArray := NewValueArray();
    Begin
      nval_array.extend(3);
      Select col1, col2, col3
      into nVal_Array(1), nVal_Array(2), nVal_Array(3)
      from tab1
      where rowid = 'AAAGJZAAGAAAAAWAAV';
    EXCEPTION
      WHEN others THEN
        Raise;
    End;
    /

  • Dynamic SQL and MERGE

    Hi all,
    I'm under 10G r1
    I want to execute a dynamic SQL with merge in it
    when I try with insert ,update it works
    but I just want to use merge if possible
    this is the code
    CREATE OR REPLACE
    PROCEDURE I_COLUMN_CDS_FIXINGS
    v_ticker VARCHAR2,
    v_date DATE,
    v_tenor VARCHAR2,
    v_bid NUMBER,
    v_ask NUMBER)
    AS
    l_column VARCHAR2(80);
    v_column_bid VARCHAR2(80);
    v_column_ask VARCHAR2(80);
    v_source VARCHAR2(60) :='CMAN@BBG';
    v_gen_order pls_integer;
    BEGIN
    SELECT 'CDS_SPREAD_'
    ||v_TENOR
    ||'_BID'
    INTO v_column_bid
    FROM dual;
    SELECT 'CDS_SPREAD_'
    ||v_TENOR
    ||'_ASK'
    INTO v_column_ask
    FROM dual;
    dbms_output.put_line(v_ticker||' '||v_column_ask||' '||v_column_bid||' '||v_bid|| ' '||v_ask||' '||v_date);
    EXECUTE immediate 'MERGE into CDS_FIXINGS C
    using ( select v_ticker,'
    ||v_column_bid
    ||','
    ||v_column_ask
    ||',trunc(v_date) info_date ,v_bid,v_ask from dual ) B
    on (C.cds_ticker=b.v_ticker and c.info_date=b.info_date)
    WHEN MATCHED THEN
    update set '||v_column_bid||'=:1,'||v_column_ask||'=:2 using v_bid,v_ask
    WHEN NOT MATCHED THEN
    INSERT
    CDS_TICKER ,
    INFO_DATE ,
    '||v_column_bid||' ,
    '||v_column_ask||' ,
    SOURCE
    VALUES (:1, :2,:3,:4,:5) ' using v_ticker,
    v_date ,
    v_bid ,
    v_ask ,
    v_source
    ---EXCEPTION
    ---when others then raise;
    end;
    when I launch hte procedure
    exec i_column_cds_fixings('TEST',trunc(sysdate-1),'8Y',4232.01,4234.02);
    I get
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    ORA-06512: at "OWNER_HISTO.I_COLUMN_CDS_FIXINGS", line 26
    ORA-06512: at line 1
    How can I deal with this
    Thanks
    babata
    I get

    Sorry
    this is formatted one
    REATE OR REPLACE PROCEDURE i_Column_cds_FixIngs
    (v_Ticker VARCHAR2,
    v_Date DATE,
    v_Tenor VARCHAR2,
    v_Bid NUMBER,
    v_Ask NUMBER)
    AS
    l_Column VARCHAR2(80);
    v_Column_Bid VARCHAR2(80);
    v_Column_Ask VARCHAR2(80);
    v_Source VARCHAR2(60) := 'CMAN@BBG';
    v_gen_Order PLS_INTEGER;
    BEGIN
    SELECT 'CDS_SPREAD_'
    ||v_Tenor
    ||'_BID'
    INTO v_Column_Bid
    FROM Dual;
    SELECT 'CDS_SPREAD_'
    ||v_Tenor
    ||'_ASK'
    INTO v_Column_Ask
    FROM Dual;
    dbms_Output.Put_Line(v_Ticker
    ||' '
    ||v_Column_Ask
    ||' '
    ||v_Column_Bid
    ||' '
    ||v_Bid
    ||' '
    ||v_Ask
    ||' '
    ||v_Date);
    EXECUTE IMMEDIATE 'MERGE into CDS_FIXINGS C
    using ( select v_ticker,'
    ||v_Column_Bid
    ||','
    ||v_Column_Ask
    ||',trunc(v_date) info_date ,v_bid,v_ask from dual ) B
    on (C.cds_ticker=b.v_ticker and c.info_date=b.info_date)
    WHEN MATCHED THEN
    update set '
    ||v_Column_Bid
    ||'=:1,'
    ||v_Column_Ask
    ||'=:2 USING v_bid,v_ask
    WHEN NOT MATCHED THEN
    INSERT
    CDS_TICKER ,
    INFO_DATE ,
    ||v_Column_Bid
    ||' ,
    ||v_Column_Ask
    ||' ,
    SOURCE
    VALUES
    :1,
    :2,
    :3,
    :4,
    :5
    USING v_Ticker,v_Date,v_Bid,v_Ask,v_Source;
    ---EXCEPTION
    ---when others then raise;
    END;
    /

  • 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 255 bytes per line limit

    I would like to create a Dynamic SQL statement that is longer than 255 bytes. What do I need to do to embed a carriage return or something so that the resultant string is broken up into multiple lines?

    Please ignore. This was a stupid question!

  • Dynamic SQL and GRANT CREATE ANY TABLE

    hi gurus,
    i have a dynamic SQL in a procedure where a table will be created from an existing table without data.
    strSQL:='create table ' || strTemp || ' as select * from ' || strArc || ' where 1=2';
    execute immediate strSQL;
    without GRANT CREATE ANY TABLE for the user, *"ORA-01031: insufficient privileges"* error during execution.
    Is there a way to tackle this issue without providing GRANT CREATE ANY TABLE privilige?
    many thanks,
    Charles

    ravikumar.sv wrote:
    The problem is not because of dynamic sql...It probably has something to do with dynamic SQL or, more accurately, dynamic SQL within a stored procedure.
    From a SQL*Plus command prompt, you can create a table if your account has the CREATE TABLE privilege either granted directly to it or granted to a role that has been granted to your account. Most people probably have the CREATE TABLE privilege through a role (hopefully a custom "developer role" that has whatever privileges you grant to users that will own objects but potentially through the default RESOURCE role). That is not sufficient to create tables dynamically via a definer's rights stored procedure. Only privileges that are granted directly to the user, not those granted via a role, are visible in that case.
    I expect that the DBAs are granting the CREATE ANY TABLE privilege directly to the account in question rather than through whatever role(s) are being used which is why that appears to solve the problem.
    Justin

  • Dynamic SQL and IN CLAUSE from Pro C code

    Hi Guys,
    Tyring to embed sql in Pro C. Here I don't know in hand how many items will be there in the IN Clause of my dynamic sql. Tried this with a loop and then adding actual values to the stement and then executing it. This worked but as this hard coding makes it literal sql and hence hampers performance. Can any one help me with how to put bind variables where we don't know how many of them will be there in a dynamic sql.
    Thanks,

    Dynamic SQL supports user defined types, try passing a collection and using TABLE(CAST(collection)) in the SQL statement.
    In the current approach (creating IN clause at runtime) keep in mind that in a IN clause you can put a maximum of 255 elements...
    Max

  • Dynamic SQL and use of aggregate functions

    Hello Forum members,
    I'm trying to create dynamic SQL in a function module and return the MAX value of a field. 
    I am passing in a parameter called CREATE_FIELD_NAME, and my SQL is
    SELECT MAX(CREATE_FIELD_NAME) INTO (CREATE_DATE) FROM (TABLE_NAME).
    I also tried:
    SELECT MAX((CREATE_FIELD_NAME)) INTO (CREATE_DATE) FROM (TABLE_NAME).
    But abap is not recognizing my variable as a variable in either case, but rather, as a field name.
    Anyone know a way around this?
    Thanks in advance,
    Jeff
    Here is my program:
    FUNCTION ZJLSTEST4.
    ""Local Interface:
    *"  IMPORTING
    *"     VALUE(TABLE_NAME) LIKE  MAKT-MAKTX
    *"     VALUE(CREATE_FIELD_NAME) LIKE  MAKT-MAKTX
    *"     VALUE(UPDATE_FIELD_NAME) LIKE  MAKT-MAKTX
    *"  EXPORTING
    *"     VALUE(MAX_DATE) LIKE  SY-DATUM
    DATA: CREATE_DATE LIKE MCHA-ERSDA VALUE '19000101',
          UPDATE_DATE LIKE MCHA-LAEDA VALUE '19000101'.
    SELECT MAX(CREATE_FIELD_NAME) INTO (CREATE_DATE) FROM (TABLE_NAME).
    ENDSELECT.
    *SELECT MAX((UPDATE_FIELD_NAME)) INTO (UPDATE_DATE) FROM (TABLE_NAME).
    *ENDSELECT.
    IF CREATE_DATE > UPDATE_DATE.
       MAX_DATE = CREATE_DATE.
    ELSE.
       MAX_DATE = UPDATE_DATE.
    ENDIF.
    IF MAX_DATE = '19000101'.
    MAX_DATE = SY-DATUM.
    ENDIF.
    ENDFUNCTION.

    Max is right, you need the spaces, as in my example.
    You might like to try this:
    data: l_CREATE_FIELD_NAME) LIKE MAKT-MAKTX,
          l_UPDATE_FIELD_NAME) LIKE MAKT-MAKTX.
    DATA: CREATE_DATE LIKE MCHA-ERSDA VALUE '19000101',
    UPDATE_DATE LIKE MCHA-LAEDA VALUE '19000101'.
    concatenate 'MAX(' create_name ')' into l_create_name separated by space.
    concatenate 'MAX(' update_name ')' into l_update_name separated by space.
    SELECT SINGLE (l_CREATE_FIELD_NAME)
    INTO CREATE_DATE FROM (table_name).
    SELECT SINGLE (l_updATE_FIELD_NAME)
    INTO updATE_DATE FROM (table_name).
    IF CREATE_DATE > UPDATE_DATE.
    MAX_DATE = CREATE_DATE.
    ELSE.
    MAX_DATE = UPDATE_DATE.
    ENDIF.
    IF MAX_DATE = '19000101'.
    MAX_DATE = SY-DATUM.
    ENDIF.
    If it still fails please post the latest abap code for us to check.

  • 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 PL/SQL

    I have the following scenario:
    User Scott has two tables named USERINFO and EMP with the following description:
    desc USERINFO
    schema varchar2(30)
    desc EMP
    ename varchar2(30)
    empno number(4)
    User Blake has one table named EMP which looks like:
    desc EMP
    ename varchar2(30)
    I want to write a function which would copy the values from Scott's EMP table to Blake's EMP table but I want to get the user Blake's name from USERINFO's schema column. I figured I'd have to use dynamic SQL but am getting some errors when I execute the function. It compiles fine. Below is the code
    CREATE OR REPLACE FUNCTION CopyInfo()
    RETURN VARCHAR2 AS
    name VARCHAR22(30);
    target_schema VARCHAR2(30);
    ret_str CHAR := NULL;
    BEGIN
    SELECT schema INTO target_schema FROM version;
    SELECT ename INTO name FROM scott.emp WHERE empno = 7902;
    DECLARE
    sqlStmt VARCHAR2(1028);
    BEGIN
    sqlStmt := 'INSERT INTO ' || target_schema || '.emp VALUES( name )';
    execute SqlStmt ;
    END;
    ret_str := 't';
    RETURN ret_str;
    END CopyInfo
    When I create the function, it comes back with -
    Function created.
    when I try to execute I get an error as shown below:
    SQL>BEGIN
    2 DBMS_OUTPUT.PUT_LINE( CopyInfo());
    3 END;
    4 /
    ERROR at line 1:
    ORA-00984: column not allowed here
    ORA-06512: at "SCOTT.COPYINFO", line 13
    ORA-06512: at line 2
    Any idea, how to fix this ??? Thanks a lot....

    ---Sorry I meant userinfo not version in the code----
    I have the following scenario:
    User Scott has two tables named USERINFO and EMP with the following description:
    desc USERINFO
    schema varchar2(30)
    desc EMP
    ename varchar2(30)
    empno number(4)
    User Blake has one table named EMP which looks like:
    desc EMP
    ename varchar2(30)
    I want to write a function which would copy the values from Scott's EMP table to Blake's EMP table but I want to get the user Blake's name from USERINFO's schema column. I figured I'd have to use dynamic SQL but am getting some errors when I execute the function. It compiles fine. Below is the code
    CREATE OR REPLACE FUNCTION CopyInfo()
    RETURN VARCHAR2 AS
    name VARCHAR22(30);
    target_schema VARCHAR2(30);
    ret_str CHAR := NULL;
    BEGIN
    SELECT schema INTO target_schema FROM userinfo;
    SELECT ename INTO name FROM scott.emp WHERE empno = 7902;
    DECLARE
    sqlStmt VARCHAR2(1028);
    BEGIN
    sqlStmt := 'INSERT INTO ' || target_schema || '.emp VALUES( name )';
    execute SqlStmt ;
    END;
    ret_str := 't';
    RETURN ret_str;
    END CopyInfo
    When I create the function, it comes back with -
    Function created.
    when I try to execute I get an error as shown below:
    SQL>BEGIN
    2 DBMS_OUTPUT.PUT_LINE( CopyInfo());
    3 END;
    4 /
    ERROR at line 1:
    ORA-00984: column not allowed here
    ORA-06512: at "SCOTT.COPYINFO", line 13
    ORA-06512: at line 2
    Any idea, how to fix this ??? Thanks a lot....

  • 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

  • Can I access two different libraries on the same computer with the remote app?

    I am in the process of upgrading our home network. There is going to be an airport express in each of the main rooms of our house all running to a switch connected to our AirPort Extreme. The reason for this is so we can stream our music in any or al

  • IMac hanging caused by Safari (I think)

    Have been having problems with my iMac hanging which I think is caused by Safari. Safari (5.1.7 )will be working OK and then hang with the spinning wheel. Am then unable to quit and finder hangs in turn and I end up doing a restart with the power but

  • How to start building new screens in ORPOS 13.0.2

    Hi All, I am very new to ORPOS UI implementation/customization. I am in process of customization/ changing the UI for POS Client. Read the Operation Guide and it is very useful to start with. But I am facing difficulties in setting my Eclipse to run

  • HPE-390t Bluetooth issues on Win7 Ultimate

    I have an HPE-390t that is running Win7 Ultimate (which came with it when I purchased it from HP).  Lately, Bluetooth has been very iffy on the machine and I'm not sure if it's a hardware or software issue and how to resolve it either way.  Sometimes

  • DS in IE not working

    Hi all, So I have 2 XML files that it grabs on load, it loads one of them for the paging, but the one for the data will not work I cant figure it out, when I hit the xml file direct it loads up in IE its just like it wont load the DS, this is the URL