Custom SQL statement on the fly

Is it possible to construct dynamic SQL statement in DB adapter on the fly?

One Solution is pass your sql statement to the procedure and fire it from the procedure.
stmt_str := 'INSERT INTO ' || tablename || ' VALUES
(:deptno, :dname, :loc)';
EXECUTE IMMEDIATE stmt_str
USING deptnumber, deptname, location;
refer this thread Dynamic database adapter
--Prasanna                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Tool to see sql plan on the fly

    I am looking for some tools to identify the execution plan of SQLs currently running. It has to be easy and quick, feedback from any body with experience on that is greatly appreciated.

    When you create a SQL statement with the custom sql option, you can use ? or # as parameter placeholders. Each placeholder will have an associated element in the schema that is created for the sql statement. It is my experience that string values passed in via the parameters are treated as string literals, that is, as if they are wrapped in single quotes.
    I tested this by setting up the following custom sql statement: "select ? from Applications". I passed in "Name" as the parameter value and received a result set that contained several rows containing "Name". Which means the statement that was executed was "select 'Name' from Applications".
    So, you may be able to get this to work in a limited fashion if you can account for the injected single quotes, but I don't think you will be able to pass in whole sql statements. Which is probably a good thing as you could expose yourself to sql injection attacks.

  • How to pass the bind variable value to the sql statement of the LOV

    Hi,
    I am using Forms 10g builder.
    I have a text item which will be populated by a LOV when i press a button, but i have a bind variable in the SQL statement of the LOV. That bind variable should be replaced by a value which is derived from a radio group in the same data block.
    For Ex: ( )radio1 ( )radio2
    before i click on the push button, I'll select one of the radio button above,so my question is how to assign this radio group value to the bind variable in the sql statement in the LOV?
    Pl any hint is appreciated!
    Thanks
    Reddy

    The variable can be taken into account in the SELECT order contained in the Record Group used by the LOV.
    e.g. Select ... From ... Where column = :block.radio_group ...Francois

  • Can the format of a SQL Statement modify the execution time of an SQL ....

    Can the format of a SQL Statement modify the execution time of an SQL statement?
    Thanks in advance

    It depends on:
    1) What oracle version are you using
    2) What do you mean for "format"
    For example: if you're on Oracle9i and changing format means changing the order of the tables in the FROM clause and you're using Rule Based Optimizer then the execution plan and the execution time can be very different...
    Max
    [My Italian Oracle blog|http://oracleitalia.wordpress.com/2009/12/29/estrarre-i-dati-in-formato-xml-da-sql/]

  • XML Publisher - can we specify multiple SQL statements in the report?

    Hi there,
    can we specify multiple SQL statements in the report with XML Publisher?
    Regards,
    Liviu

    Could we eventually generate with the Wizards available in XML Publisher desktop 5.6.2 an xml file with a structure like the one given below? The reason is to facilitate creation of the two rowsets. Thanks, Liviu.
    <?xml version="1.0" encoding="UTF-8"?>
    <DATA>
         <ROWSET2>
              <ROW2>
                   <FIELD1>Query1</FIELD1>
                   <FIELD2>field2</FIELD2>
                   <FIELD3>field3</FIELD3>
              </ROW2>
         </ROWSET2>
         <ROWSET>
              <ROW>
                   <FIELD1>Query2</FIELD1>
                   <FIELD2>field2</FIELD2>
                   <FIELD3>field3</FIELD3>
              </ROW>
         </ROWSET>
    </DATA>

  • Expensive SQL Statements of the day?

    Hi...
    How can i find out Expensive SQL Statements of the day please.?
    Our SAP Version is ECC 6.0 on Oracle 10.2.0.4.0
    Rgds

    Hi Srinivas,
    On ECC 6.0, go to ST04 t-code --> performance --> SQL Cache --> You see SQL Statements where you need to sort by SQL Statements by Total Execution Time(ms).
    I have tried on one of my R/3 4.7EE system, ST04n --> Resource COnsumption --> Top SQL Statements --> you will see 50 Top most expensive SQL Statements interms of wait time.
    also Read: [Re: Diagnosis of the expensive ABAP programs having database time > 90%;
                      [Please Read before Posting in the Performance and Tuning Forum;
    Regards,
    Kanthi Kiran

  • Passing plsql parm to a sql statement in the procedure  database link name

    Would like to pass a parm that is the database link name to a stored procedure.  I defined this as below. var1 is the name of the db link that I would like to pass
    create or replace procedure   proc1  (var1 in varchar2) as
    cursor c1 is
    select num,name,city from emp@var1;
    However, this is getting a plsql error in the above code   as bad bind variable, db link name expected.
    Is there a method to pass a variable within a stored proc into a SQL statement that has a cursor ..
    thanks

    Hi,
    Database links have to be hard-coded.  If you really need to specify the database link at run-time, then you need Dyanmic SQL.
    Why do you need to do this?   How many databases are involved?  Do you have new database links all the time?  The more you can say about your business requirements, the more helpful we can be.
    Are there only a couple of possible database links?  If so,  you might consider hard-coding each of them, and branching to the appropriate one in your code.
    is the real variable here the environment (Development, Test, Production) that you're in?  For example, do you need to use one database link in Development, a different one in Test, and a third in Production, but you don't want to change the code when you move from one environment to another?  If so, you can try conditional comilation.

  • Update SQL Statement in the JDBC sender

    Hello!
    I have a AS400/DB2 table which I am polling for my XI scenario using the JDBC sender adapter.
    I would like to know if it is possible to use system variables (data/time) in the UPDATE statement field? This because we would like to timestamp the exact date/time we read a table. (We can use stored procedures, I know, but would preferr not if at all possible.) Or is there another way?
    Thanks,
    Nam

    Hello!
    a little more detail:
    We have a fairly simple scenario. We are polling the AS400/DB2 table for information using the JDBC sender with a SELECT statement in the SQL query. We take the data, map it and push it into SRM.
    Bhavesh: What I meant is that for error handlig purposes we would like to update the polled record with date and time at the same time as we poll. Using the system date/time of the db system would be ideal, but XI time would be just fine to. So wondering if there is any way to pick up the system data/time (of either system) and pass it in the UPDATE statement as system variables or some such.
    Nimrod: one question.... how do we do the mapping in the poll? Meaning the polling is the trigger of the whole scenario, so there is no mapping preceding it. I am fairly new to XI, especially the mapping bit, any help or advice appreciated!
    Thanks!
    Nam

  • How Can I Retrieve SQL Statement From The User ?

    Hi
    I want to know, how can I make the user can enter the SQL statement from himself ?? in this code he can't enter it. Only he can display the SQL that i wrote it...
    this is my Code:
    import java.sql.*;
    public class db_testing {
         static final String DRIVER = "com.mysql.jdbc.Driver";            
         static final String DATABASE_URL = "jdbc:mysql://localhost/S204111933";
         public static void main(String[] args) {
              Connection cn=null;
              Statement st= null;
              ResultSet rset=null;
              try{
                   Class.forName(DRIVER);
                   cn=DriverManager.getConnection(DATABASE_URL, "root", "admin");
                   st=cn.createStatement();
                   rset=st.executeQuery("select * from employee");
                   ResultSetMetaData metadata=rset.getMetaData();
                   System.out.println("The begining: ");
                   for(int i=1;i<=metadata.getColumnCount();i++)
                   System.out.print(metadata.getColumnName(i)+"\t");
                   System.out.println();
                   System.out.println();
                   while(rset.next()){
                   for(int i=1;i<=metadata.getColumnCount();i++)
                   System.out.print(rset.getObject(i)+"\t\t");
                   System.out.println();}
              catch(Exception e){
                   e.printStackTrace();
              finally{
                   try{
                   cn.close();
                   st.close();
                   rset.close();
                   catch(Exception e1){
                        e1.printStackTrace();
    }

    The following changes in the code will make the user to give the input
    import java.sql.*;
    public class db_testing {
    static final String DRIVER = "com.mysql.jdbc.Driver";
    static final String DATABASE_URL = "jdbc:mysql://localhost/S204111933";
    public static void main(String[] args) {
    Connection cn=null;
    Statement st= null;
    ResultSet rset=null;
    try{
    Class.forName(DRIVER);
    cn=DriverManager.getConnection(DATABASE_URL, "root", "admin");
    // st=cn.createStatement();
    // rset=st.executeQuery("select * from employee");
    PreparedStatement pstmt=null;
    pstmt=cn.prepareStatement("select * from employee where id=?");
    pstmt.setInt(1,Integer.parseInt(args[0]));
    rset=pstmt.executeQuery();
    ResultSetMetaData metadata=rset.getMetaData();
    System.out.println("The begining: ");
    for(int i=1;i<=metadata.getColumnCount();i++)
    System.out.print(metadata.getColumnName(i)+"\t");
    System.out.println();
    System.out.println();
    while(rset.next()){
    for(int i=1;i<=metadata.getColumnCount();i++)
    System.out.print(rset.getObject(i)+"\t\t");
    System.out.println();}
    catch(Exception e){
    e.printStackTrace();
    finally{
    try{
    cn.close();
    st.close();
    rset.close();
    catch(Exception e1){
    e1.printStackTrace();
    }

  • How to retrieve SQL statement in the CR 2008

    I'm using Crystal Reports 2008 in MS Visual Studio 2008, how can i retrieve SQL statement from *.rpt file, i have tried this code, but it doesn't work:
    ReportDocument rdReport = new ReportDocument();
    rdReport.Load("Reports/EmployeeTest.rpt", OpenReportMethod.OpenReportByTempCopy);
    CrystalDecisions.ReportAppServer.Controllers.RowsetController rsController;
    CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rdClient = rdReport.ReportClientDocument; // on this line it throws an exception "The ReportClientDocument property can only be accessed when the report is opened using a Report Application Server."
    CrystalDecisions.ReportAppServer.DataDefModel.ISCRGroupPath rdGroupPath = new CrystalDecisions.ReportAppServer.DataDefModel.GroupPath();
    string temp;
    string sql;
    rsController = rdClient.RowsetController;
    sql = rsController.GetSQLStatement(rdGroupPath, out temp);
    maybe i'm doing something wrong ?
    thanks

    Hello Ludek,
    when I try to get the report from the session I got an error like this (I am using State Server Session mode i.e out proc in my application)
    ReportClientDocument     'reportDocument.ReportClientDocument' threw an exception of type 'System.InvalidOperationException'     CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument {System.InvalidOperationException}
    +base     {"The ReportClientDocument property can only be accessed when the report is opened using a Report Application Server."}     System.SystemException {System.InvalidOperationException}
    StackTrace     "   at CrystalDecisions.CrystalReports.Engine.ReportDocument.get_ReportClientDocument()"     string
    so is it the problem of not opened with RAS. Does installation of RAS solves the problem, If so Is it a free-ware or needs to be purchased.
    Ashok

  • How to monitor perticuler sql statement using the INDEX or not?

    I am running on a long running quary, and the output is comming very late. So i want to know the sql quary is using the index or not? How to know that?

    If you want to check the real execution plan of a running query without waiting for query completion, you can try following steps that you should adapt to your query and your environment:
    1. start the query
    select
    count(*)
    from all_objects, all_objects;2. Retrieve in another session the SQL_ID and the CHILD_NUMBER of the running query:
    select sql_id, child_number, sql_text
    from v$sql
    where sql_text like '%all_objects%';3. use DBMS_XPLAN.DISPLAY_CURSOR to get the real execution plan from shared pool using SQL_ID and CHILD_NUMBER from step 2:
    select * from table(dbms_xplan.display_cursor(<sql_id>,<child_number>));Actually you don't need to restart the query if it is already running because the hint GATHER_PLAN_STATISTICS is only needed if you want to have current execution statistics.
    Edited by: P. Forstmann on 2 mars 2011 10:23

  • How to examine the generated SQL statement in Receiver JDBC Adapter

    I have been searching this forum how to display te generated sql statement (by the jdbc receiver adapter).
    The only suggestion is to use RWB, but I was unable to find any details about how to do so.
    Any help is appreciated

    Hi,
    To add, u can see the SQL Statements in Audit log of RWB.
    Select Message Monitoring-> Adapter Engine. choose ur entry and click on Details option button, u can see the SQL Statements in Audit Log.
    Regards,
    Sudharshan
    Message was edited by:
            Sudharshan Aravamudan

  • How is the address selected in the Customer Account Statement (F.27)?

    Hi expert,
    The customer account statement (transaction F.27) uses the address which is in the customer master data.
    This is the customer master data on the company code level (Street, postal code, city).
    Is it possible to select the PO address (PO box , postal code, city) in the account statepment?
    This data is also available on the company code level.
    Thank you for your feedback.
    Kind regards,
    Linda

    Hi,
    Customer Account Statement uses the below program :
    SAP13: Customer statement (single statement)
    Copy the same and change accorndingly.
    Your requirement can be done with the ABAP changes
    VVR

  • Setting the sql statement

    http://www.egbolig.dk/drift_bo_syd.rpt (HERE IS THE REPORT)
    We are using SAP Crystal Report .NET Runtime files (http://scn.sap.com/docs/DOC-7824 newest version 13.0.9.1312) in our web asp.net application. Everything have been working fine, but we have can into problems when showing the certain kinda reports.
    In our code get the reports sql statement using getSQLStatement.
    Dim gp As New GroupPath() Dim sql As String = report.ReportClientDocument.RowsetController.GetSQLStatement(gp)
    This will get the sql, and we use this sql (getSqlStatement) and attach a sql WHERE clause from the code to only get a certain number of records.
    The report Drift_bo_syd.rpt has 5 tables, and the following sql statement. 
    Database/Show Sql Statement
    SELECT "rekvstam"."Sel", "rekvstam"."Afd", "rekvstam"."Levadresse", "rekvstam"."Rekvisition", "rekvstam"."Lejemaal", "rekvstam"."Lejer", "rekvstam"."Udfoertaf", "rekvstam"."Udfoertdato", "rekvstam"."Krit", "Selskab"."Adresse", "Selskab"."Postby", "Selskab"."Tlf", "Selskab"."Fax", "rekvstam"."Kontor", "rekvstam"."Hjemme", "rekvstam"."Rekvdato", "rekvstam"."Aftale", "rekvstam"."InitialRet", "rekvstam"."Arbejde", "kreditor"."Att", "rekvstam"."Konto", "Selskab"."Navn", "Selskab"."Email", "Interessentadresse"."Navn", "Interessentadresse"."Adresse", "Interessentadresse"."Postby", "Interessentadresse"."Email1", "Interessentadresse"."Telefon_Fax", "Interessentadresse"."Type", "Interessentadresse"."Tlf1", "rekvstam"."tlfLejer", "kreditor"."Kred", "Interessentadresse"."Interessentnr" FROM  (("Rekvstam" "rekvstam" INNER JOIN "Selskab" "Selskab" ON "rekvstam"."Sel"="Selskab"."Sel") LEFT OUTER JOIN "Kreditor" "kreditor" ON "rekvstam"."Kred"="kreditor"."Kred") INNER JOIN "Interessentadresse" "Interessentadresse" ON "kreditor"."Interessentnr"="Interessentadresse"."Interessentnr" WHERE  "Interessentadresse"."Type"='K' 
    But if we run the report from our asp.net code, we get the following error: 
    Cannot determine the queries necessary to get data for this report. Failed to retrieve data from the database. Error in File Drift_Bo_Syd {97FED382-1BAC-4DB1-970F-9E098ECE28F1}.rpt: Failed to retrieve data from the database.
    After a long time searching for a solution, we found out that if we place the column kred from the kreditor table on the report, the report will work. (field explorer / database fields / kreditor (table) / kred (column)
    Very important is that the field "kreditor.kred" is a primary key of the table kreditor, and also used in the linking.!
    (We can get the report to work if we call the sql statement with the "kreditor"."kred" in the SELECT statement.
    SELECT "kreditor"."kred", "rekvstam"."Sel", "rekvstam"."Afd", "rekvstam"."Levadresse", "rekvstam"."Rekvisition", "rekvstam"."Lejemaal", "rekvstam"."Lejer", "rekvstam"."Udfoertaf", "rekvstam"."Udfoertdato", "rekvstam"."Krit", "Selskab"."Adresse", "Selskab"."Postby", "Selskab"."Tlf", "Selskab"."Fax", "rekvstam"."Kontor", "rekvstam"."Hjemme", "rekvstam"."Rekvdato", "rekvstam"."Aftale", "rekvstam"."InitialRet", "rekvstam"."Arbejde", "kreditor"."Att", "rekvstam"."Konto", "Selskab"."Navn", "Selskab"."Email", "Interessentadresse"."Navn", "Interessentadresse"."Adresse", "Interessentadresse"."Postby", "Interessentadresse"."Email1", "Interessentadresse"."Telefon_Fax", "Interessentadresse"."Type", "Interessentadresse"."Tlf1", "rekvstam"."tlfLejer", "kreditor"."Kred", "Interessentadresse"."Interessentnr" FROM  (("Rekvstam" "rekvstam" INNER JOIN "Selskab" "Selskab" ON "rekvstam"."Sel"="Selskab"."Sel") LEFT OUTER JOIN "Kreditor" "kreditor" ON "rekvstam"."Kred"="kreditor"."Kred") INNER JOIN "Interessentadresse" "Interessentadresse" ON "kreditor"."Interessentnr"="Interessentadresse"."Interessentnr" WHERE  "Interessentadresse"."Type"='K'
    But it should not be necessary to include this field (which is the primary key and used in linking the report) in the sql statement,
    BECAUSE it is not used in the report. So maybe this is a bug?
    It has not been necessary in RDC Crystal Report or RAS Crystal Report in a classic asp envoriment.
    Here is the code we use to set the reports SQL Statement)
    Try
    Dim conn As New SqlConnection(connString)
    conn.Open()
    Dim sd As New SqlDataAdapter(New SqlCommand(nySQL, conn))
    Dim ds As New Data.DataSet()
    Dim navn As String = report.Database.Tables.Item(0).Name
    sd.Fill(ds, navn)
    report.SetDataSource(ds)
    conn.Close()
    Catch ex As Exception
    Throw
    End Try

    Hi Jan
    I understand your problem completely but we have asked  R&D to be able to edit the SQL and they explained due to how the report Engine works it's simply not possible anymore. It would take a complete rewrite in all of our DB drivers and query dll's to be able to allow it. They did that in CR 9 when they rewrote the DB drivers and removed the SQL part of the code into separate dll's and that is when the ability was removed, it's been that way ever since.
    One possibility is to get the SQL from the Report and then connect to your DB using a .NET and if the results from the SQL is less than 5K rows and not too many columns you could then set the Report data source to a Dataset.
    As long as all of the field names are the same CR will run the report using this work flow.
    For data larger than 5K rows, limit is due to memory resources, you could save the DS to an XML file and then set the reports data source to the XML file. We've seen 100meg XML's used so the amount of data should not be a problem, but of course there are limits to everything so test...
    This should not affect performance much.
    So the work flow would be:
    Load the report
    Get the SQL Statement
    Paste it into a Dataset Query
    Something like this should get you started:
    //string connString = "Provider=SQLOLEDB;Data Source=MySQLServer;Database=xtreme;User ID=sa;Password=pw";
    string connString = "Provider=SQLNCLI10;Server=MySQLServer;Database=xtreme;User ID=sa;Password=pw";
    Detail"".""Quantity"" FROM   ""xtreme"".""dbo"".""Orders Detail"" ""Orders Detail""";
    string sqlString = @"SELECT top 10*  FROM  ""xtreme"".""dbo"".""Financials"" ""Financials""";
    System.Data.OleDb.OleDbConnection oleConn = new System.Data.OleDb.OleDbConnection(connString);
    System.Data.OleDb.OleDbCommand cmd = oleConn.CreateCommand();
    cmd.CommandText = sqlString;
    System.Data.DataSet ds = new System.Data.DataSet();
    OleDbDataAdapter oleAdapter = new OleDbDataAdapter(sqlString, oleConn);
    //OleDbDataAdapter oleAdapter2 = new OleDbDataAdapter(sqlString2, oleConn);
    DataTable dt1 = new DataTable("Financials");
    //DataTable dt2 = new DataTable("Orders Detail");
    oleAdapter.Fill(dt1);
    //oleAdapter2.Fill(dt2);
    ds.Tables.Add(dt1);
    //ds.Tables.Add(dt2);
    ds.WriteXml("c:\\reports\\sc2.xml", XmlWriteMode.WriteSchema);
    // as long as the field names match exactly Cr has no problems setting report to a DS.
    try
        rpt.SetDataSource(ds.Tables[0]); // incremtent [0] for more than 1 table.
        rpt.SetDataSource(ds);
    catch (Exception ex)
        MessageBox.Show("ERROR: Schema Mismatch. Error reported by CR: " + ex.Message);
    //Now check for subreport and set to same DS
    foreach (CrystalDecisions.CrystalReports.Engine.Section section in rpt.ReportDefinition.Sections)
        foreach (CrystalDecisions.CrystalReports.Engine.ReportObject reportObject in section.ReportObjects)
            if (reportObject.Kind == ReportObjectKind.SubreportObject)
                CrystalDecisions.CrystalReports.Engine.SubreportObject subReport = (CrystalDecisions.CrystalReports.Engine.SubreportObject)reportObject;
                CrystalDecisions.CrystalReports.Engine.ReportDocument subDocument = subReport.OpenSubreport(subReport.SubreportName);
                subDocument.SetDataSource(ds);
    And for XML it would use this part, not above I am saving the data and structure in the XML file so it should match what is in the report:
    foreach (CrystalDecisions.CrystalReports.Engine.Table rptTable in rpt.Database.Tables)
        try
            rptTable.Location = btrDataFile.ToString(); // @"D:\Atest\" + rptTable.Location + ".xml";
        catch (Exception ex)
            MessageBox.Show("ERROR: " + ex.Message);
    Only issue you may run into is sometimes XML does not have a direct field type and your original data source but you'll get an error if that happens which could be trapped and handled.
    If you have a report that only uses 2 tables I do have code that will convert it to use a Command Object. That is the limit the engine is capable of, there is a lot of logic to be able to do this in CRD and the SDK so that is all we could get for now.
    I hope that helps
    Don

  • Determining the "type" of a SQL statement

    I'm using the Oracle thin driver with my JDBC program.
    I want to be able to accept a String containing a SQL statement from the user and execute it. If it's a select statement then present the rows returned in a JTable, otherwise retrieve the return value for the command (eg INSERT, DELETE, etc).
    Is there any "readymade" method in JDBC or Oracle driver to determine the type of a SQL statement in this sense. Or do I have to parse it myself? (Imagine having to write code to strip comments out etc!)

    There is no "readymade" method. But an easy way to check will be to check the first 6 charchters of the string.
    You could use
    newString = SQL.substring(0, 5); to obtain the first 6 characters.
    if the characters are "select"
    //do select things
    else
    // do insert/delete whatever things

Maybe you are looking for

  • Hp officejet pro 8600 n911a series

    The Printer will not print out, stay's in queue, everything is connected, no jam's , set up for wireless, test was ok, says printer not connected, also turned off and on printer, doesn't work, can you help

  • "An Error Occured: Try Again" Message Everywhere. App nearly unusable. [Version 1.0.0.3251]

    Hello, After upgrading to Spotify version 1.0.0.3251, I have had numerous issues with connecting, searching, and playing music as a Premium user. No matter what I do, whether it is under Browse, Discover, Radio, Search, Playlists, or my own user prof

  • Business Unit Security Access

    I have created a Child Business Unit that has a Parent Business Unit. The Child Business Unit has a team associated with it. The team has members that are all in the Business Unit. I have restricted access in the security role so that Read access on

  • Nokia 6120 Classic USB Modem is not working proper...

    Hello everybody! Something strange happened last week with my Nokia 6120 Classic (version: 03.83). I regularly use it as a USB modem and last week's Wednesday it stopped working. What the problem really is due to, is hard for me to say precisely. Usi

  • App shuts down when moving files

    After updating the files, when I try to move them back to their folders, every time I try to scroll down to select the folder to move them to, the app shuts down.