How to store sql statement in oracle table?

I tried it in this way:
SQL> insert into sql_text values('select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21
JAN-2010' and BILL_STATUS='INV'');
insert into sql_text values('select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-
010' and BILL_STATUS='INV'')
ERROR at line 1:
ORA-00917: missing comma
Please help to solve it, i can't use concatenation (||),
coz
'select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-2010' and BILL_STATUS='INV' 'it is dynamic.

user2060331 wrote:
No sql statement is a dynamic value inserted by a user for executing it on SQl prompt.Then use q-literals:
SQL> ACCEPT stmt PROMPT "Enter statement: "
Enter statement: select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-2010' and BILL_STATUS='INV'
SQL> insert into sql_text values('&stmt');
old   1: insert into sql_text values('&stmt')
new   1: insert into sql_text values('select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-2010' and BILL_STATUS='INV'')
insert into sql_text values('select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-2010' and BILL_STATUS='INV'')
ERROR at line 1:
ORA-00917: missing comma
SQL> insert into sql_text values(q'[&stmt]');
old   1: insert into sql_text values(q'[&stmt]')
new   1: insert into sql_text values(q'[select invoice,invoice_dt,DT_INVOICED from PS_BI_HDR where DT_INVOICED= '21-JAN-2010' and BILL_STATUS='INV']')
1 row created.
SQL> SY.

Similar Messages

  • How to store XML data into Oracle Table

    I had trouble to store XML data into Oracle Table with XDK (Oracle 8.1.7 ). The error is:
    C:\XDK_Java_9_2\xdk\demo\java\Test>java testInsert Dept.xml
    <Line 1, Column 1>: XML-0108: (Fatal Error) Start of root element expected.
    Exception in thread "main" oracle.xml.sql.OracleXMLSQLException: Start of root element expected.
    at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:2263)
    at oracle.xml.sql.dml.OracleXMLSave.insertXML(OracleXMLSave.java:1333)
    at testInsert.main(testInsert.java:8)
    Here is my xml file:
    <?xml version = '1.0'?>
    <ROWSET>
    <ROW num="1">
    <DEPTNO>10</DEPTNO>
    <DNAME>ACCOUNTING</DNAME>
    <LOC>NEW YORK</LOC>
    </ROW>
    <ROW num="2">
    <DEPTNO>20</DEPTNO>
    <DNAME>RESEARCH</DNAME>
    <LOC>DALLAS</LOC>
    </ROW>
    <ROW num="3">
    <DEPTNO>30</DEPTNO>
    <DNAME>SALES</DNAME>
    <LOC>CHICAGO</LOC>
    </ROW>
    <ROW num="4">
    <DEPTNO>40</DEPTNO>
    <DNAME>OPERATIONS</DNAME>
    <LOC>BOSTON</LOC>
    </ROW>
    </ROWSET>
    and here is structure of table:
    Name Null? Type
    DEPTNO NOT NULL NUMBER(2)
    DNAME VARCHAR2(14)
    LOC VARCHAR2(13)
    and here is my Java Code:
    import java.sql.*;
    import oracle.xml.sql.dml.OracleXMLSave;
    public class testInsert{
         public static void main(String[] args) throws SQLException{
              Connection conn = getConnection();
              OracleXMLSave sav = new OracleXMLSave(conn,"scott.tmp_dept");
              sav.insertXML(args[0]);
              sav.close();
              conn.close();
         private static Connection getConnection()throws SQLException{
              DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
              Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@amt-ebdev01:1521:mydept","scott","tiger");
              return conn;
    Could you help me ? Thanks !

    The problem is that you need to pass avalid URL , Document...
    Please try this code instead:
    import java.net.*;
    import java.sql.*;
    import java.io.*;
    import oracle.xml.sql.dml.OracleXMLSave;
    public class testInsert
    public static void main(String[] args) throws SQLException{
    Connection conn = getConnection();
    OracleXMLSave sav = new OracleXMLSave(conn,"scott.temp_dept");
    URL url = createURL(args[0]);
    sav.insertXML(url);
    sav.close();
    conn.close();
    private static Connection getConnection()throws SQLException{
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@dlsun1982:1521:jwxdk9i","scott","tiger");
    return conn;
    // Helper method to create a URL from a file name
    static URL createURL(String fileName)
    URL url = null;
    try
    url = new URL(fileName);
    catch (MalformedURLException ex)
    File f = new File(fileName);
    try
    String path = f.getAbsolutePath();
    // This is a bunch of weird code that is required to
    // make a valid URL on the Windows platform, due
    // to inconsistencies in what getAbsolutePath returns.
    String fs = System.getProperty("file.separator");
    if (fs.length() == 1)
    char sep = fs.charAt(0);
    if (sep != '/')
    path = path.replace(sep, '/');
    if (path.charAt(0) != '/')
    path = '/' + path;
    path = "file://" + path;
    url = new URL(path);
    catch (MalformedURLException e)
    System.out.println("Cannot create url for: " + fileName);
    System.exit(0);
    return url;

  • How to store Html File in Oracle Table?

    Hai,
    I want to store Html File(s) into oracle Table. How can I do it?.
    Please help me. Html File size can be maximum 40 MB .
    Regards
    Suresh

    If it's just pure HTML it's nothing more than astring so you could store it as such.
    Most databases have a limitation on the maximum number
    of characters that a string can hold. With 30MB of
    text, a CLOB (Character Large OBject) is the
    preferrable type but a BLOB (Binary Large OBject) can
    also be used.
    ;o)
    V.V.Right, right. But, I kind of doubt that an html file takes up 30MB, can you imagine browsing a web site, regardless of your connection, with pages that size? We're talking ~125,000 line of pure HTML code (no images)!

  • How to execute SQL statement with oracle jdev

    Please I'm a beginner in oracle jdeveloper. I want to know how to use and execute sql statememt within oracle Jdeveloper 10 g release 3 to manipulate objects in oracle database. I want for e.g. to Enable/disable trigger using sql statement "ALTER TRIGGER trigername DISABLE" explicitly. Please tell me how to proceed.
    i am sure you can help me
    Sincerly yours.

    Hi,
    Using following tutorial http://www.oracle.com/technology/obe/ADF_tutorial_1013/10131/index.htm
    you will found how to connect from Jdev to a database (chapter 1 or 2 ?). Then you just have to go under Tool>SQL*Plus or Tools>SQL Worksheet depending on what you need.
    Luck,
    Tif

  • How to synchronize Sql Server when Oracle table has trigger

    Hi
    I have a trigger which will update/insert the data into a Oracle table.
    I have an interface which normally moves the data from Oracle table to SQL Server table.
    Is there any way which will update/insert the data into SQL Server table whenever any trigger fires on Oracle table.
    Thanks,
    Ganesh

    ODI's CDC capabilities can be used to propogate changes from Oracle to SQL Server. If your trigger inserts/updates on an oracle table, then ODI's CDC should pick that up. If you have a scenario which does a WaitForLogData on your Oracle table, it can kick off the interface to transfer the journal data whenever that happens.

  • How to store an image in oracle table

    hi
    i have created table,in that i want to store an imege(it may be any form of image like jpeg,bmp and so)
    i need coding for that in sql

    depends where are your images and how you will store it.
    you need some front end application to read the images and store it in the tables.
    eg Oracle Forms (READ_IMAGE_FILE), Java.
    if not place the images on the databas server.
    create directory objects for the path on which the images are there.
    use DBMS_LOB to read the files and save to the database tables.

  • How to store image in the oracle database 10.2. using File Maker 10.

    Hi.,
    I want to store image, media file in the oracle database using File Maker as a front end.
    I connect Oracle using odbc from file maker. There are table and in that table there a column "pict" of blob type. but this column is not showing in the file maker.
    2. Here I can not change the data type of any column.
    Now how to store images in the oracle table using odbc or any other tool.
    Regards,
    Shyam

    I wrote an example for my students, you can find it here. It's using PHP as the front end but all you need to do is know how and leverage the stored procedures. All code is downloadable in zip files from the blog.
    http://blog.mclaughlinsoftware.com/php-programming/oracle-lob-processing/

  • Where to run SQL statements in Oracle Database 11gR1 ?

    Folks,
    Hello. I have just installed Oracle Database 11gR1 and login to Database Control page. There are 4 tabs on the top: Database, Setup, Preference, Help and Logout.
    I just create a table "table1" in "Database" tap. But I don't see anywhere to run SQL statement such as Select, Insert, Update.
    Can any folk tell me where to run SQL statements in Oracle Database 11gR1 ?
    Or
    Can any folk provide a User Manual for Oracle DB 11gR1 ?

    You can run from a terminal or install an SQL client and connect from there.
    http://www.articlesbase.com/databases-articles/how-to-install-oracle-11g-client-1793770.html
    Best Regards
    mseberg
    Assuming you have an oracle OS user on Linux you can try typing sqlplus at you OS command prompt. Generally you will have a .bash_profile with setting like this:
    # User specific environment and startup programs
    PATH=$PATH:$HOME/bin
    export PATH
    # Oracle Settings
    TMP=/tmp; export TMP
    TMPDIR=$TMP; export TMPDIR
    export ORACLE_BASE=/u01/app/oracle
    export ORACLE_HOME=/u01/app/oracle/product/11.2.0
    #export DISPLAY=localhost:0.0
    export TZ=CST6CDT 
    export ORACLE_SID=ORCL
    export ORACLE_TERM=xterm
    #export TNS_ADMIN= Set if sqlnet.ora, tnsnames.ora, etc. are not in $ORACLE_HOME/network/admin
    export NLS_LANG=AMERICAN;
    LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
    export LD_LIBRARY_PATH
    # Set shell search paths
    PATH=/usr/sbin:$PATH; export PATH
    export PATH=$PATH:$ORACLE_HOME/bin
    # CLASSPATH:
    CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
    CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
    export EDITOR=vi
    set -o vi
    PS1='$PWD:$ORACLE_SID >'Edited by: mseberg on Jul 11, 2011 3:18 PM

  • Execute the sql statement stored in table

    friends i m in complication that, how can i execute sql statement which is stored in database table.
    how can i fetch that particular statement from table and make it execute!!!
    Thanks in advance

    I think we should stop at this point and have a little think.
    My understanding is that your plan is to do the following
    -Execute a Dynamic SQL statement which is constructed from values in several columns in a table (Bad idea to begin with)
    -The result of the execution is then loaded into PL/SQL.....not sure how you are handling different column lists but I'll assume you are not having to convert every column value to a VARCHAR2
    -The values returned are then used in an INSERT statement
    So basically your goal here is to take some data from one table and insert it into another table by moving data from SQL to PL/SQL then back to SQL in an elaborate, dynamic way. This is a costly waste of resources and will not scale (this is before we get to the problem of having to read the SQL statement from a table in the first place)
    I would recommend looking the INSERT SELECT statement here: http://psoug.org/reference/insert.html
    This will get the job done in one go. If you really do need it to be dynamic (which you don't, trust me) then you can still store this statement in your "dynamic SQL" table and execute it using EXECUTE IMMEDIATE although I can say for sure that you're going to run into more problems down the line with this architecture, it won't scale very well, and you'll probably waste at least *1* day of your time every week trying to fix a bug caused by the removal of a table, change to a column name etc.......
    However if you believe that storing SQL in a table is the best solution to your problem then go ahead.....at least when you find out that it isn't you'll have learned a valuable lesson.

  • Adding a field to an sql statement in Oracle Reports error ORA-00933

    We have been requested to add a field that already exists in the table referred to by the sql statement in Oracle Reports Builder. The report was set up by a consultant about 3 yrs ago and we don't really have much skill in this area. What is happening when I try to modify the SQL statement, either adding a field or deleting a field to the SELECT statement, causes an error message preventing the statement from being saved. The only way out of the error message is to click Cancel. The error message is
    ORA-00933:SQL command not properly ended
    ORDER BY Program ==> NAME
    Even adding or deleting a space anywhere in the SQL statement causes the error (not adding any new fields). A coworker found that if we comment out the ORDER BY, the statement will accept the new field in the SELECT section, however then we lose the order by functionality. I would like to add one additional field before the FROM. Not sure if any additional data are needed. Thank you.
    SELECT p.person_uid PIDM_KEY, p.id_number ID,
                   p.full_name_lfmi name,            
                    p.BIRTH_DATE, p.GENDER Sex,
                    Decode(a.residency,'D',p.Primary_ethnicity,'F')  Ethn,
                    a.academic_period TERM,        
                    CASE WHEN :p_group_by = 'PROGRAM' THEN a.program
                                 ELSE ' '
                    END AS Program,
                    a.COLLEGE, a.degree, a.major, ' ' rule,
                    a.STUDENT_POPULATION,a.STUDENT_LEVEL,    a.application_status Status,  a.application_status_date app_sts_dte,
                    ad.decision_date1 Last_Dec_Date,
                    ad.decision1||' '||ad.decision2||' '|| ad.decision3||' '|| ad.decision4||' '|| ad.decision5 Decisions,
                    /*  Deposit Date uses the last term entered in :p_term parameter string */
                    (SELECT MAX(deposit_effective_date) FROM usf_as_deposit WHERE account_uid = a.person_uid &term_clause group by account_uid)   AS "DEPOSIT DATE",     
                    ph.phone as PHONE,
                    CASE WHEN PS.FIRST_CONTACT IN ('NET','PAP','COM','COP') THEN PS.First_Contact
                     ELSE CASE WHEN ps.latest_contact IN ('NET','PAP','COM','COP') THEN PS.Latest_Contact
                                ELSE '  '
                                END
                    END AS FIRST_CONTACT,
                    DECODE(:p_address,'Y',REPLACE(adr.street1||' '||adr.street2||' '||adr.street3||' '||adr.city||','||adr.state||' '||adr.nation||' '||adr.zip,'  ',' '),' ') as  address, adr.nation, adr.state,
                    goremal_email_address email, a.residency, a.application_date, p.primary_ethnicity, c.cohort
    FROM MST_ADMISSIONS_APPLICATION A,
               MST_PERSON p,mst_pre_student PS,  Admissions_Cohort c, usf_v_phone_pr_ma ph,
               MST_admissions_decision_slot AD, usf_v_email, usf_v_address_dr_lr_ma_pr adr
    WHERE a.PERSON_UID = p.person_uid
            AND a.curriculum_priority  = 1
            AND a.person_uid = ps.person_uid
           AND a.person_uid = ad.person_Uid(+)
           AND a.person_uid = goremal_pidm(+)
           AND a.person_uid = adr.pidm(+)
           AND a.person_uid = ph.pidm(+)
           AND ph.rnum(+) = 1
           AND a.person_uid = c.person_uid(+)
           AND a.academic_period = c.academic_period(+)
      &Where_Clause
           /*    TAKE OUT FOLLOWING LINE AFTER DATA IS CLEANED UP  */
            AND NOT(p.id_number = '00000000'   OR SUBSTR(p.id_number,1,1) = 'B'  OR UPPER(p.full_name_lfmi)  LIKE '%TESTING%')
           AND  a.application_status_date >= NVL(:p_as_of_date,sysdate-8000)
           AND a.academic_period = ad.academic_period(+)
            AND a.application_number = ad.application_number(+)
            AND a.degree <> 'ND'    /*   AND a.college <> 'LW'                         --  Does not need non-degree and law students    */
           &Cohort_Clause 
    ORDER BY Program  &ORDER_CLAUSE

    Hi Denis,
    I tried your suggestion. The good thing is that adding the comma allowed me to be able to add a.campus to the select statement, unfortunately, another error message happened.
    ORA-00936: missing expression SELECT p . person_uid PIDM_KEY ,
    p . id_number , p . full_name_lfmi name , p . BIRTH_DATE , p . GENDER Sex ,
    Decode ( a . residency , 'D' , p . Primary_Ethnicity , 'F' ) Ethn , a . academic_period TERM ,
    CASE WHEN : P_group_by = 'PROGRAM THEN a I started over and tried only putting in the comma and get the same message even though I didn't add campus. After that, removed the comma which led to the ORA-00933 error message. So once again, I had to close the file without saving, in order for the report to run at all.

  • How to find sql statement with Unix process pid

    Hi
    how to find sql statement with Unix process pid
    is there any view to find that.
    please if so let me know
    Thanks in advance

    this is how I am doing this:
    oracle 7352340 7459066 0 07:47:10 - 0:00 oracleJDERED (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
    oracle 7459066 5386396 2 07:47:10 pts/1 0:01 sqlplus
    select sid,serial# from v$session where process='7459066';
    SID SERIAL#
    2178 6067
    select sql_text
    from
    v$sqlarea a,
    v$session b
    where a.hash_value = b.sql_hash_value
    and b.sid = 2178
    ;

  • How can i extract data from oracle table  to flat file or excel spread shee

    Hello,
    DB Version is 10.1.0.3.0
    How can i extract data from oracle table to flat file or excel spread sheet by using sub programs?
    Regards,
    D

    Here what I did
    SET NEWPAGE 0
    SET SPACE 0
    SET LINESIZE 80
    SET PAGESIZE 0
    SET ECHO OFF
    SET FEEDBACK OFF
    SET VERIFY OFF
    SET HEADING OFF
    SET MARKUP HTML OFF SPOOL OFF
    Sql> SPOOL bing
    select * from -------;
    SPOOL OFF;
    I do not see file.
    I also tried
    Sql> SPOOL /tmp/bing
    select * from -------;
    SPOOL OFF;
    But still not seeing the fie,

  • How to Capture  sql statement

    we have 1 server oracle and many clients.
    when client sends sql statement to server.How to Capture sql statement to analysis berfore it sent to server and execution.
    Edited by: 955185 on Aug 27, 2012 4:22 AM

    955185 wrote:
    yes. how to do this?Check these link all of them talking about Already executed sql in database by Users , but i don't know if what you ask is possible since they already connect to database
    If you attending to analysis sql read the below links and start your analysis,
    Last executed sql
    http://www.databasejournal.com/features/oracle/article.php/3373701/Watching-SQL-Execute-on-Oracle---Part-I.htm
    http://stackoverflow.com/questions/55899/how-to-see-the-actual-oracle-sql-statement-that-is-being-executed

  • How to export data from a Oracle table to a delimited file?

    I know how to load delimited file into a table, but how to export
    data from a Oracle table to a delimited file?
    Thanks in advance.

    Try looking at this link, it's long but there's three different solutions discussed in it. If you look at Barbara Boehmer's
    solution in her posts in the link below you'll see that she's addressed your concerns with spool files.
    Re: utl_smtp and triggers

  • Sql statement in a table not accepting variable

    I have the following problem on 10.1.0.3.0 with varialbe in an execute immediate statement
    here is the code that I am using
    declare
    remote_data_link varchar2(25) := 'UDE_DATATRANSFER_LINK';
    FROM_SCHEMA VARCHAR2(40) := 'UDE_OLTP';
    l_last_process_date date := to_date(to_char(sysdate,'mm-dd-yyyy hh:mi:ss'),'mm-dd-yyyy hh:mi:ss') - 1;
    stmt varchar2(4000) := 'MERGE into applicant_adverseaction_info theTarget USING (select * from '||FROM_SCHEMA||'.applicant_adverseaction_info@'||remote_data_link||' where last_activity > :l_last_process_date ) theSource ON(theTarget.applicant_id = theSource.applicant_id) WHEN MATCHED THEN UPDATE SET theTarget.cb_used = theSource.cb_used, theTarget.cb_address = theSource.cb_address, theTarget.scoredmodel_id = theSource.scoredmodel_id, theTarget.last_activity = theSource.last_activity WHEN NOT MATCHED THEN INSERT(CB_USED, CB_ADDRESS, SCOREDMODEL_ID, APPLICANT_ID, LAST_ACTIVITY) values(theSource.cb_used, theSource.cb_address, theSource.scoredmodel_id, theSource.applicant_id, theSource.last_activity)';
    stmt2 varchar2(4000) := 'MERGE into edm_application theTarget USING (select * from '||from_schema||'.edm_application@'||remote_data_link||' where last_activity > :l_last_process_date) theSource ON (theTarget.edm_appl_id = theSource.edm_appl_id) WHEN MATCHED THEN UPDATE SET theTarget.APP_REF_KEY = theSource.APP_REF_KEY, theTarget.IMPORT_REF_KEY = theSource.IMPORT_REF_KEY, theTarget.LAST_ACTIVITY = theSource.LAST_ACTIVITY WHEN NOT MATCHED THEN INSERT (EDM_APPL_ID, APP_REF_KEY, IMPORT_REF_KEY, LAST_ACTIVITY) values(theSource.EDM_APPL_ID, theSource.APP_REF_KEY, theSource.IMPORT_REF_KEY, theSource.LAST_ACTIVITY)';
    v_error varchar2(4000);
    T_MERGE VARCHAR2(4000);
    stmt3 varchar2(4000);
    BEGIN
    select merge_sql
    INTO T_MERGE
    from transfertables
    where table_name= 'edm_application';
    remote_data_link:= 'UDE_DATATRANSFER_LINK';
    FROM_SCHEMA := 'UDE_OLTP';
    --DBMS_OUTPUT.PUT_LINE(SUBSTR(stmt2,1,200));
    --STMT2 := T_MERGE;
    dbms_output.put_line(from_schema||' '||remote_data_link||' '||l_last_process_date);
    EXECUTE IMMEDIATE stmt2 using l_last_process_date;
    --execute immediate stmt3 ;
    dbms_output.put_line(from_schema||' '||remote_data_link||' '||l_last_process_date);
    dbms_output.put_line(substr(stmt2,1,200));
    commit;
    EXCEPTION
    WHEN OTHERS THEN
    V_ERROR := SQLCODE||' '||SQLERRM;
    v_ERROR := V_ERROR ||' '||SUBSTR(stmt2,1,200);
    DBMS_OUTPUT.PUT_LINE(V_ERROR);
    --dbms_output.put_line(substr(stmt2,1,200));
    END;
    This works perfectly
    but if I change it to get the same statement in a db table
    declare
    remote_data_link varchar2(25) := 'UDE_DATATRANSFER_LINK';
    FROM_SCHEMA VARCHAR2(40) := 'UDE_OLTP';
    l_last_process_date date := to_date(to_char(sysdate,'mm-dd-yyyy hh:mi:ss'),'mm-dd-yyyy hh:mi:ss') - 1;
    stmt varchar2(4000) := 'MERGE into applicant_adverseaction_info theTarget USING (select * from '||FROM_SCHEMA||'.applicant_adverseaction_info@'||remote_data_link||' where last_activity > :l_last_process_date ) theSource ON(theTarget.applicant_id = theSource.applicant_id) WHEN MATCHED THEN UPDATE SET theTarget.cb_used = theSource.cb_used, theTarget.cb_address = theSource.cb_address, theTarget.scoredmodel_id = theSource.scoredmodel_id, theTarget.last_activity = theSource.last_activity WHEN NOT MATCHED THEN INSERT(CB_USED, CB_ADDRESS, SCOREDMODEL_ID, APPLICANT_ID, LAST_ACTIVITY) values(theSource.cb_used, theSource.cb_address, theSource.scoredmodel_id, theSource.applicant_id, theSource.last_activity)';
    stmt2 varchar2(4000) := 'MERGE into edm_application theTarget USING (select * from '||from_schema||'.edm_application@'||remote_data_link||' where last_activity > :l_last_process_date) theSource ON (theTarget.edm_appl_id = theSource.edm_appl_id) WHEN MATCHED THEN UPDATE SET theTarget.APP_REF_KEY = theSource.APP_REF_KEY, theTarget.IMPORT_REF_KEY = theSource.IMPORT_REF_KEY, theTarget.LAST_ACTIVITY = theSource.LAST_ACTIVITY WHEN NOT MATCHED THEN INSERT (EDM_APPL_ID, APP_REF_KEY, IMPORT_REF_KEY, LAST_ACTIVITY) values(theSource.EDM_APPL_ID, theSource.APP_REF_KEY, theSource.IMPORT_REF_KEY, theSource.LAST_ACTIVITY)';
    v_error varchar2(4000);
    T_MERGE VARCHAR2(4000);
    stmt3 varchar2(4000);
    BEGIN
    select merge_sql
    INTO T_MERGE
    from transfertables
    where table_name= 'edm_application';
    remote_data_link:= 'UDE_DATATRANSFER_LINK';
    FROM_SCHEMA := 'UDE_OLTP';
    --DBMS_OUTPUT.PUT_LINE(SUBSTR(stmt2,1,200));
    STMT2 := T_MERGE;
    dbms_output.put_line(from_schema||' '||remote_data_link||' '||l_last_process_date);
    EXECUTE IMMEDIATE stmt2 using l_last_process_date;
    --execute immediate stmt3 ;
    dbms_output.put_line(from_schema||' '||remote_data_link||' '||l_last_process_date);
    dbms_output.put_line(substr(stmt2,1,200));
    commit;
    EXCEPTION
    WHEN OTHERS THEN
    V_ERROR := SQLCODE||' '||SQLERRM;
    v_ERROR := V_ERROR ||' '||SUBSTR(stmt2,1,200);
    DBMS_OUTPUT.PUT_LINE(V_ERROR);
    --dbms_output.put_line(substr(stmt2,1,200));
    END;
    I get ora-00900 invalid sql statement
    can somebody explain why this happens
    Thanks

    I agree with jan and anthony. Your post is too long and ill-formatted. However here's my understanding of your problem (with examples though slightly different ones).
    1- I have a function that returns number of records in a any given table.
      1  CREATE OR REPLACE FUNCTION get_count(p_table varchar2)
      2     RETURN NUMBER IS
      3     v_cnt number;
      4  BEGIN
      5    EXECUTE IMMEDIATE('SELECT count(*) FROM '||p_table) INTO v_cnt;
      6    RETURN v_cnt;
      7* END;
    SQL> /
    Function created.
    SQL> SELECT get_count('emp')
      2  FROM dual
      3  /
    GET_COUNT('EMP')
                  14
    2- I decide to move the statement to a database table and recreate my function.
    SQL> CREATE TABLE test
      2  (stmt varchar2(2000))
      3  /
    Table created.
    SQL> INSERT INTO test
      2  VALUES('SELECT count(*) FROM p_table');
    1 row created.
    SQL> CREATE OR REPLACE FUNCTION get_count(p_table varchar2)
      2     RETURN NUMBER IS
      3     v_cnt number;
      4     v_stmt varchar2(4000);
      5  BEGIN
      6     SELECT stmt INTO v_stmt
      7     FROM test;
      8     EXECUTE IMMEDIATE(v_stmt) INTO v_cnt;
      9     RETURN v_cnt;
    10  END;
    11  /
    Function created.
    SQL> SELECT get_count('emp')
      2  FROM dual
      3  /
    SELECT get_count('emp')
    ERROR at line 1:
    ORA-00942: table or view does not exist
    ORA-06512: at "SCOTT.GET_COUNT", line 8
    ORA-06512: at line 1
    --p_table in the column is a string and has nothing to do with p_table parameter in the function. And since there's no p_table table in my schema function returns error on execution. I suppose this is what you mean by "sql statement in a table not accepting variable"
    3- I rectify the problem by recreating the function.
      1  CREATE OR REPLACE FUNCTION get_count(p_table varchar2)
      2     RETURN NUMBER IS
      3     v_cnt number;
      4     v_stmt varchar2(4000);
      5  BEGIN
      6     SELECT replace(stmt,'p_table',p_table) INTO v_stmt
      7     FROM test;
      8     EXECUTE IMMEDIATE(v_stmt) INTO v_cnt;
      9     RETURN v_cnt;
    10* END;
    SQL> /
    Function created.
    SQL> SELECT get_count('emp')
      2  FROM dual
      3  /
    GET_COUNT('EMP')
                  14
    Hope this gives you some idea.-----------------------
    Anwar

Maybe you are looking for

  • Installing 2 hard drives Problems

    I have a k7n2 Delta ILSR and I just finished building it and setting up the bios and everything seems to be running pretty good.  Currently, I have one hard drive (seagate) installed and I want to install a second hard drive (western digital  caviar)

  • Ps keeps crashing after shortcuts stop working and image get screwed up when using the hand tool

    Hi, ive been having problems with Photoshop Cs4 for a while. I work with big photo files and when i have alot of layers and use the hand tool to move throughout the image this happens: http://i94.photobucket.com/albums/l114/cogubr/Screenshot2010-04-2

  • Database storage vs. File system

    Hi, We'll be setting up a new Oracle UCM 10g* environment in a production scenario - we have access to high-speed SAN for file storage, but we can also use an Oracle 11g database for file storage (using the File Store Provider) - the database's table

  • Puzzled about this kernel panic

    I got this while using an external DJ controller (Traktor S2) last night.  I'm very good about keeping the software and drivers up to date (last update was this month): Interval Since Last Panic Report:  749485 sec Panics Since Last Report:         

  • My iCloud account was installed wrong no in or out mail

    MY iCloud account was installed incorrectly won't let me change primary server or edit email address