PL/SQL stored procedure and passing queries

Hi all.
This is a really "newbie"-type question....sorry !
I have written a PL/SQL procedure which takes a query (as varchar2) as an argument and returns the result in xml as a clob.
ie: SELECT returnXML('SELECT * FROM test_table') FROM DUAL;
This works fine, however how do I pass a query that also contains single quotes ?? I have tried escaping them in C-style with backslashes, but to no avail. As an example, I'd like to pass the following query to my procedure:
SELECT * FROM test_table WHERE name='TEST' AND id='200'
Any help would be greatly appreciated.
Regards,
Kristian.

Try doubling up the quotes, ie
SELECT returnXML('SELECT * FROM test_table WHERE name=''TEST'' AND id=''200''') FROM DUAL;

Similar Messages

  • Support a singly report on SQL Stored Procedure and Oracle Stored Procedure

    Hi,
    I have a requirement in which I need to create a report that will run both on oracle and sql server.
    Report is designed as follows.
    Main report contain 2 sub-reports.Sub-reports are  based on stored procedure that takes three input parameters(beginDate,endDate and hostname which is a comma-separated string).
    Main report also have three parameters (beginDate,endDate and hostnameList) that I am linking with both sub-reports.
    Since the crystal picks the same name of the parameter as we define in procedure it showing '@' symbol in all the parameters when I change the datasoure from oracle to sql server and that's why sub reports defined in main report loose all the linking and same happens when I switch from sql to oracle since in case of oracle it does not have '@' symbol in variable name.
    How can I have one report that work with both DBs without loosing the links.
    Any help will be appreciated.
    Thanks,
    Amrita

    There is no way of doing this in CR. At least not that I've ever heard of anyway.
    If you REALLY need to make this work and it REALLY has to be just 1 report... Here is what I'd do...
    In the SQL Server database, add a new table that contains the same columns that are being returned by the sp's. If you can't add new tables to the database, use a different database or server...
    Create a Linked Server linking the Oracle db to SQL Server. (If you take the 3rd server rout, do the same with the SQL Server)
    Write a new sp that will accept the {?WhichServer} parameter and populate the new table with the result set.
    Then just query that table for your report.
    I know this probably isn't the rout you were wanting to take but it should work...
    Jason

  • Two related questions: using htmldb_Get to call stored procedure and passing in an array of items

    I have the need to save dynamically generated ApEx items via AJAX.  I am using APEX_ITEM API to generate the items.  At run-time, I have no idea how many of items will be generated on the page, but I know that they will all have discreet and distinct "name" attributes, i.e. f01, f02, f03, etc.  As a basic example, if I have to generate a select list, I know that the "p_idx" parameter of the APEX_ITEM call is say "3", so all select lists that get generated will have a "name" attribute in the DOM of "f03", all text items will be "f01", etc.
    I want to save this data to the database via AJAX.  It is typical to call the standard htmldb_Get javascript function for use of an on-demand process, but I am interested in using the rarely-called-upon "procedure" and queryString" options of that javascript function so that I can build the queryString on the fly based on what is on the DOM when the tries to save the data they entered into these APEX_ITEM-generated items.  Does anyone have any good examples of how to use the "procedure" and "queryString" parameters of the htmldb_Get javascript function?
    I have found a smattering of some blogs, posts, etc. online related to this, but mostly just people regurgitating the documentation.  I found this post (https://forums.oracle.com/thread/2549237) which had a glimpse of hope to be able to pass an array (which is something I will need) as a parameter, but would like someone to sanity check this before I go down that road.
    Shane.
    ApEx 4.2.1

    Shane
    Since you mention you are on APEX 4.2  I would recommend using apex.server.process which is the documented replacement of the officially undocumented htmldb_Get.
    In the documentation it is set that the first parameter is the ajaxidentifier but it actually is the process name.
    The data object would be something like
    var lData ={f01 : get_value_array('f01')}
    Where get_value_array is
    function get_value_array(pColumnName) {
      var l_values =[];
      apex.jQuery('[name="'+pColumnName+'"]').each(
       function(){
        var l_value;
        l_value = apex.item(this.id).getValue();
        l_values.push(l_value);
      return l_values
    For a working example see this demo.
    Nicolette

  • Invoking PL/SQL Stored Procedure and returning a collection

    Hi...
    I want to return from PLSQL stored procedure a collection (like bulk collections) .
    TYPE tt_number IS TABLE OF NUMBER(20,2) INDEX BY BINARY_INTEGER;
    procedure prueba( p_collection out tt_number )
    is
    begin
    select code
    bulk collection into p_collection
    from myTable;
    end
    How I can do this? How can read this collections in java?
    thanks..

    Hope this link will work for you:
    http://www.onjava.com/pub/a/onjava/2003/08/13/stored_procedures.html
    Answer provided by http://www.consultoriajava.com

  • Creating a SQL Stored procedure to call a CF function

    I need to create a method to migrate data from a DMZ inside a firewall.  To do this I was thinking of making a call from the DMZ web server (using CF) to an internal SQL server database stored procedure.  The stored procedure would then call a CF template on the internal web server to pull data inside the firewall.  Not my first choice on implementation but as a consultant I don’t make the rules I create the code to enforce them... Anyway these are the steps I need to follow.
    1.)    Call the stored procedure and pass an int value with the call.
    2.)    The Stored procedure calls a URL and passes the INT with it. I.E.  http://Mylocalhost/Xferdata/MyXferTemplate.cfm?MyIntValue=”PASSED IN INT VALUE”
    3.)    The MyXferTemplate does the actual data migration for me.
    My question is how do I create a simple stored procedure to do this on SQL Server 2008???  After looking at the CF documentation I don’t think there will be much of a problem making the call to the stored procedure… its just writing the stored procedure…  Any and all help is greatly appreciated!!!
    Have an Ordinary Day...
    Kurtis   ~|:-)

    So far this is what I got... When I "execute' this code in SQ
    L Server management studio it compiles without any errors but when I run it I get the message "http: is not recognized as an internal or extermnal command."
    /**********************************  Code to create the SP **************************/
    USE 
    [KDLTransfer]
    GO
    /****** Object: StoredProcedure [dbo].[Migrate_DMZ_Data] Script Date: 03/07/2011 16:48:50 ******/
    SET 
    ANSI_NULLS ONGO
    SET 
    QUOTED_IDENTIFIER ONGO
    -- =============================================
    -- Author: KDL
    -- Create date: 3/7/2011
    -- Description: Migrate data
    -- =============================================
    ALTER 
    PROCEDURE [dbo].[Migrate_DMZ_Data]  
    -- Add the parameters for the stored procedure here
    @MyIntValue
    int = null
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    -- Insert statements for procedure here
    EXEC xp_cmdshell 'http://localhost/IREC/KDL/KDL.cfm?@MyIntValue, no_output';
    END
    /**************** Code to call the SP ******************/
    execute  Migrate_DMZ_Data @MyIntValue = N'5'

  • Can't create valid PL/SQL stored procedure

    I have two questions about PL/SQL and JDBC:
    Question 1: I'm trying to create and execute a PL/SQL stored procedure, and I can't seem to get the syntax right. I'm trying to create the simplest stored proc I can. Here's the stored procedure:
    create or replace procedure test( inParam char(20) ) is
    begin
    select inParam from dual;
    end;
    When I try to execute it, I'm getting the error:
    PLS-00905: object TEST is invalid
    The creation of the proc, and the execution are being done using the same login.
    Question2: Once I get the stored procedure created, I want to call it from a JDBC application. Is this the correct syntax:
              CallableStatement stmt = connection.prepareCall("begin test('abc'); end;");
    or can I use the standard JDBC escape sequence:
              CallableStatement stmt = connection.prepareCall("{ call test('abc'); }");
    Thanks for your help,
    Jeff

    Forgot to mention, I'm using TimesTen 11.2.1.4.

  • Conc. prog as pl/sql stored procedure question

    When I registered a conc. program as pl/sql stored procedure, and, with in procedure I am using as following:
    exception
    when others
    retcode := 2;
    Where I am expecting the conc. request screen should show me as red one, that is completed with error. But, even though my program aborted for unknown reason, the conc. request screen for this conc. request-id shows as "completed-normal" insted of "completed_error".
    Any idea? what are the exact retcode should be used? please explain.
    Thanks
    R2b.
    null

    What about
    exception
    when others
    THEN
    retcode:=2;
    Jack

  • How to create an External Content Type with SQL Stored Procedures Parameters and query it in a SharePoint App

    Hi,
    I'm new to SharePoint 2013 I want to be able to query a MSSQL database from a SharePoint App I have tried to create an External Content Type (ECT) which is produced from a MSSQL stored Procedure, this procedure has several parameters which are needed to
    filter the data correctly.  From here I want to produce an external list which I can then query from a c# SharePoint app.  If I leave the filters in the ECT null then the list is of course empty or if enter a default values the results are limited
    for the app to query so are no good.
    I want to dynamically pass values to the ECT when querying from the app, is this not possible.  Should I just be returning everything in an external list and then letting the query in the app filter the data, this seems inefficient?
    Is this the best way to do this or should I be doing this differently?
    Please can someone point me in the right direction.
    Thanks

    Hi Pandra801,
    When you create a the external content type, please try to add a filter based on your select statement.
    http://arsalkhatri.wordpress.com/2012/01/07/external-list-with-bcs-search-filters-finders/
    Or, try to create a stored procedure based on your select statement, then create ECT using the SQL stored procedure.
    A step by step guide in designing BCS entities by using a SQL stored procedure
    http://blogs.msdn.com/b/sharepointdev/archive/2011/02/10/173-a-step-by-step-guide-in-designing-bcs-entities-by-using-a-sql-stored-procedure.aspx
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • Pass date range parameter  to SQL stored procedure.

    Hi,
    I'd like to pass a date range parameter from Crystal Reports to a sql stored procedure. Does anyone know if this is possible?
    I've had no problem passing standard datetime (single value) paramaters to and from but am struggling with getting a range value parameter to work.
    Environment: Crystal Reports 10/XI and SQL 2000 MSDE version or SQL 2005 Express Edition.
    Any help would be appreciated.

    C5112736 wrote:>
    > And then these 2 formulas 'Formula # 1' and 'Formula # 2' can be used to pass on to the stored procedure.
    Can someone please demonstrate exactly how to use formula results as date parameters to a SQL stored procedure?  Keep in mind, there are two parameters to the stored procedure.
    I have gleaned this much: Use Add Command and insert the procedure with
    EXEC ServerName.dbo.usp_sprocName;1 '{?StringParameter}'
    but if I try to do
    {CALL ServerName.dbo.usp_SprocName({@Formula1},{@Formula2})}
    then it gives the error "No value given for one or more required parameters". 
    Both of the parameters are VARCHAR(50).
    I have finally found this link: [http://msdn.microsoft.com/en-us/library/ms710248(VS.85).aspx|http://msdn.microsoft.com/en-us/library/ms710248(VS.85).aspx]
    This Microsoft site defines the format of the ODBC escape sequences, but I still do not know how to convince Crystal to insert it's parameter results or formula results.
    Pulling what's left of my hair out . . .
    ~ Shaun

  • How to get a list of values used in the WHERE filter of stored procedures and functions in SQL Server

    How can I get a list of values (one or more) used in the WHERE filter of stored procedures and functions in SQL Server?
    How can get a list of values as shown (highlighted) in the sample stored procedure below?
    ALTER PROC [dbo].[sp_LoanInfo_Data_Extract] AS
    SELECT   [LOAN_ACCT].PROD_DT,
                  [LOAN_ACCT].ACCT_NBR, 
                  [LOAN_NOTE2].OFCR_CD, 
                  [LOAN_NOTE1].CURR_PRIN_BAL_AMT, 
                  [LOAN_NOTE2].BR_NBR,
    INTO #Table1
    FROM
                    dbo.[LOAN_NOTE1],
                    dbo.[LOAN_NOTE2],
                    dbo.[LOAN_ACCT]
    WHERE
                    [LOAN_ACCT].PROD_DT = [LOAN_NOTE1].PROD_DT
                    and
                    [LOAN_ACCT].ACCT_NBR = [LOAN_NOTE1].ACCT_NBR
                    and
                    [LOAN_NOTE1].PROD_DT = [LOAN_NOTE2].PROD_DT
                    and
                    [LOAN_NOTE1].MSTR_ACCT_NBR = [LOAN_NOTE2].MSTR_ACCT_NBR
                    and
                    [LOAN_ACCT].PROD_DT = '2015-03-10'
                    and
                    [LOAN_ACCT].ACCT_STAT_CD IN
    ('A','D')
                    and
                    [LOAN_NOTE2].LOAN_STAT_CD IN
    ('J','Z')
    Lenfinkel

    Hi LenFinkel,
    May I know what is purpose of this requirement, as olaf said,you may parse the T-SQL code (or the execution plan), which is not that easy.
    I have noticed that the condition values in your Stored Procedure(SP) are hard coded and among them there is a date values, I believe some day you may have to alter the SP when the date expires. So why not declare 3 parameters of the SP instead hard coding?
    For multiple values paramter you can use a
    table-valued parameter. Then there's no problem getting the values.
    If you could elaborate your purpose, we may help to find better workaround.
    Eric Zhang
    TechNet Community Support

  • How to bind arrays to PL/SQL stored procedure using OCI?

    Hi,
    We are having problems trying to bind arrays to PL/SQL stored procedure using OCI. Here is the situation:
    - We have a stored procedure called "GetVEPFindTasks" with the following interface:
    PROCEDURE GetVEPFindTasks (
    p_ErrorCode OUT NUMBER,
    p_ErrorMsg OUT VARCHAR2,
    p_RowCount OUT NUMBER,
    p_VEPFindTasks OUT t_VEPFindTaskRecordTable,
    p_MaxTask IN NUMBER);
    t_VEPFindTaskRecordTable is a record with the following entries:
    TYPE t_VEPFindTaskRecord IS RECORD (
    RTCID NUMBER,
    TransNum NUMBER,
    TransTimestamp VARCHAR2(20),
    Pathname1 image_data.pathname%TYPE,
    Pathname2 image_data.pathname%TYPE,
    Pathname3 image_data.pathname%TYPE,
    OperatorID operator.id%TYPE);
    - Now, we are trying to call the stored procedure from C++ using OCI (in UNIX). The call that we use are: OCIBindByName and OCIBindArrayOfStruct to bind the parameters to the corresponding buffers. We bind all parameters in the interface by name. Now, we do bind the record's individual item by name (RTCID, TransNum, etc.), and not as a record. I don't know if this is going to work. Then, we use the bind handles of the binded record items (only record items such as RTCID, TransNum, and NOT error_code which is not part of the record) to bind the arrays (using OCIBindArrayOfStruct).
    All of the parameters that are binded as arrays are OUTPUT parameters. The rest are either INPUT or INPUT/OUTPUT parameters. Now, when we try to execute, OCI returns with an error "Invalid number or types of arguments" (or something to that sort... the number was something like ORA-06550). Please help...
    Is there any sample on how to use the OCIBindArrayOfStruct with PL/SQL stored procedures? The sample provided from Oracle is only for a straight SQL statement.
    Thank's for all your help.
    ** Dannil Chan **

    As you said:
    You have to pass in an array for every field and deconstruct/construct the record in the procedure. There is no support for record type or an array of records. Can you give me a example? I'am very urgently need it.
    thanks
    email: [email protected]

  • Creating XML report using PL/SQL Stored Procedure

    Hi Friends,
    I am working on an xml report with the xml source as PL/SQL Stored Procedure.
    I am referring the exercise shown in the following link to understand the process:
       http://orclapp.blogspot.com/2012/02/developing-xml-publisher-report-using.html
    In the example shown in the above link I could not understand the following:
    1) In the following procedure, the out parameter 'retcode' is not used at all.
       What is the importance of this parameter.
        PROCEDURE REPORT (errbuf  OUT VARCHAR2, retcode  OUT VARCHAR2, p_product_id   IN     NUMBER)
    2)  After the xml data is prepared and put to 'l_result' Clob variable, the following
        Loop is executed. I am not able to appreciate why the following loop is required.
         LOOP
             EXIT WHEN l_length = l_retrieved;
             IF (l_length - l_retrieved) < 32000
             THEN
                SELECT SUBSTR (l_result, l_retrieved + 1) INTO l_xmlstr FROM DUAL;
                l_retrieved := l_length;
                fnd_file.put_line (fnd_file.output, l_xmlstr);
             ELSE
                SELECT SUBSTR (l_result, l_retrieved + 1, l_offset)
                  INTO l_xmlstr
                  FROM DUAL;
                l_retrieved := l_retrieved + l_offset;
                fnd_file.put_line (fnd_file.output, l_xmlstr);
             END IF;
         END LOOP;
    3) In the example it is not explained how the concurrent program gets the xml data?
       I assume it is written to a file using the following line of code:
        fnd_file.put_line (fnd_file.output, l_xmlstr);
       I would appreciate if anyone can throw some light into my above queries so that I can understand the process clearly.
    Thanks & Regards
    Hawker

    Hi 32000 in the code is a 'safe' size smaller than the max available 32767, the loops purpose is to move through the entire thing in chunks that will be manageable in the limits of the data type.
    Btw; if you are in Oracle e-business suite then you can also use Oracle reports very simply to create XML output.
    If you have reports developer all you need to do is put raw sql (without any 'artifice' to create XML) in the report SQL and then set the reports output to XML in the program definition in Oracle e-business.
    best regards,
    Robert.

  • How to send a Varying Array param to a PL/SQL Stored Procedure from Java

    * I am VERY new to jdbc, and even somewhat new to Java
    * I'm using Java 1.5, Oracle 10g.
    * I need to call the following PL/SQL Stored Procedure from Java:
    procedure setEventStatus
    i_deQueueStatus in deQueueStatus_type
    *deQueueStatus_type is the following (an array of deQueueStatus_OBJ):
    CREATE OR REPLACE TYPE deQueueStatus_OBJ as object
    eventID number (20),
    dequeuestatus varchar2(20)
    CREATE OR REPLACE TYPE deQueueStatus_TYPE IS VARYING ARRAY(500) of deQueueStatus_obj
    *I have created a Java object as follows:
    public class EventQueueDeQueueStatus
         long      eventID;
         String      dequeueStatus;
         EventQueueDeQueueStatus(long eventID, String dequeueStatus)
              this.eventID = eventID;
              this.dequeueStatus = dequeueStatus;
    I have an ArrayList of these.
    I need to pass this list to the Stored Procedure. How do I create a java.sql.Array so I can call CallableStatement.setArray to set the parameter? Or do I use something else? I have tried setObject with both the ArrayList and also with a primitive array, but got "Invalid Column Type" both times.
    Any help would be greatly appreciated. I just got this task today, and I have to make it work by Tuesday :-( !
    Thanks,
    Kathy

    Kathy,
    Search the archives of this forum and the JDBC forum for the terms STRUCT and ARRAY and you can find some sample code on the JDBC How-To Documents page and the JDBC Samples which can both be accessed from this page:
    http://www.oracle.com/technology/tech/java/sqlj_jdbc/index.html
    Good Luck,
    Avi.

  • Executing a shell script from pl/sql stored procedure

    Hi,
    I have Oracle 8i on HP-UX.
    I am passing a shell script name as a parameter to a user defined function from a pl/sql stored procedure. This user defined function has insterface to a user defined Java class file in Aurora java virtual machine which is written using runtime class which can execute any OS command or any shell script. I am getting any OS command run successfully, but could not run my own shell script. It's is not getting environment variables of my own, so not getting executed. So please suggest how can get these env variables in my shell script and also suggest other sucurity concerns to be taken into consideration.
    If you have any questions please let me know.
    This is really a very urgent issue.....
    Please help me.
    Thanks
    Srinivasa Rao Kolla

    Your best bet is to use the dbms_pipe builtin package to send the command to the host

  • APEX - accepting OUT variable values from PL/SQL Stored Procedure

    I have created a page (Form) which is accepting values text fields.
    In the Page Processing section under Processing, I am passing the values to a PL/SQL Stored Procedure, which acts like an API. The procedure contains code to validate the entered data and finally insert the data into the base tables. The procedure also contains OUT variables in the parameter that would return status of processing and any error messages.
    Now, my question is, how can I make the page accept these OUT variables from the procedure. What I wish to do is, to capture these messages/processing status from the procedure in the page. For example, if there is a error in the data and the procedure is sending this message in the OUT variable, I need this to be displayed on the page as an error message.
    Is this possible in APEX?
    Regards,
    Santhosh Jose

    Hi VC,
    I just tried putting the string directly instead of the variable. Its still not giving me the expected results.
    HOWEVER, I think the reason was because of the EXCEPTION block in my code. I have an EXCEPTION block to handle exceptions. I commented the WHEN OTHERS section and now the error message is coming on the page.
    So what I have done now is as follows: At the point at which the error is expected, I am raising a handled exception. And within the exception handling, I am giving RAISE_APPLICATION_ERROR.
    WHEN ex_main_error*
    THEN*
    p_status := 2;*
    p_msg := 'ERROR Stage: '||lc_err_stage||' ERROR Message: '||lc_err_msg;*
    RAISE_APPLICATION_ERROR (-20001, p_msg);*
    This is working now! Which is very good news. Thanks once again for your help!
    Regards,
    Santhosh Jose

Maybe you are looking for

  • Problem with the Date Field in Production

    In Development while using a variable with data element DATS , the variable gets initialised to 00000000. But the same does not get initialised in Production..... Kindly  suggest? Regards Dilip

  • Automation Script execution

    Hello All, How i will do Automation script execution in Production We have a bunch of scripts (Packages , DDL & DML ) everyday. What is the better aproach to do automatic script execution without any issues ?

  • ALV OUTPUT FIELD LEANTH

    HI EXPERTS, IN ALV OUTPUT FIELD LENTH IS MAX 128? IN MY REQUIRMENT THE FIELD HAS 500 CHARTERS Moderator Message: So where is the question? And why type in CAPITAL letters? Do some research before you post a question here. Also, please read the Rules

  • Page down functionality in table control BDC-CJ02 tcode

    Hi Friends, I am doing a BDC with Table control for Tcode CJ02. When I reach certain number of records, say 13, the page down functionality doesnt work.I tried different ways like using the BDC_OKCODE as "=P" and "=P+".Also, I tried doing a recording

  • Enterprise Services list in Discovery System.

    Hi, I just want to know the Enterprise services list in Discovery system. Actually why i needed that, is just wanted to know is there any enterprise service available for Billing, Service Order Management that are present as functionality in  SAP CCS