Passing blank parameter to stored procedures/function

Hi all,
When I pass blank value ('') to a VARCHAR2 parameter in a stored procedures/function it reads the parameter as NULL, I try to use DEFAULT keyword in the parameter declaration, but it does not work. How can I make the sp/func read the paramater as '' ?
Thanks in advance
Setya

This is a fundamental quirk of Oracle - it treats '' (empty string) as if it were null:
SQL> SELECT case when '' is null then 'EMPTY STRING IS NULL' else 'EMPTY STRING IS NOT NULL' end
  2  FROM   dual;
CASEWHEN''ISNULLTHEN'EMP
EMPTY STRING IS NULL
SQL> So what is it you want to do that you can do with an empty string but not with a null?
Regards, APC

Similar Messages

  • Passing dynamic parameter to stored procedure from CR formula?

    Dear all,
    I need to insert in some textboxes the right string based on the desired Language Code.
    I crated a stored procedure in my db.
    CREATE PROCEDURE MY_GET_TRANSLATION
         @TextID nvarchar(8),
         @LangCode int
    This parameters are used as keys to get the Trans field.
    I created a workshop formula: GetTranslation
    Please, can someone suggest the correct statement to call my MY_GET_TRANSLATION  stored procedure passing parameters?
    I would like to call the GetTranslation formula from all my textboxes, passing the specific TextID value
    and visualized the right translated string.
    For example:
    in my TEXT1 textbox, I would like to call the GetTranslation formula passing the parameters
    TextID = "T000001"
    and
    LangCode = 13    (Italian language)
    How can pass dynamic parameters to a formula?
    How can pass dynamic parameters to a stored procedure from a CR formula?
    Regards
        Emanuele

    Dear Jason,
    I'm trying to modify a SAP B1 CR marketing report.
    This CR marketing document is called by SAP B1 automatically passing the Document Number and Document Type.
    The report uses the right SAP B1 tables to read the information of the header and rows of the document.
    The language of the document is contained in a field of the header table
    {MyMarketingDocTable.LanguageID}
    I created a user table named "MyTranslationTable" where I added some strings in different langiages.
    For example:
    TexiID            TextString              LangID
    T00001          Delivery                          8      
    T00001          Consegna                     13       (Italian translation)
    T00002          Invoice                           8
    T00002          Fattura                         13       (Italian translation)
    In the header of the report I'd like, for example, to visualise the string "Consegna" if my document is a delivery in italian language.
    I'd like to implement this method to translate all the textboxes (header, comments, etc.) based on the languageID of my document.
    For each textboxes, in the CR designer statically I know what TextID I want to visualized but dinamically I need to pass to my stored procedure the right language. I'd like my report automatically gets the language at run-time. I don't want that when I press the Print-preview button in SAP B1, the report asks to prompt the languageID.
    It already read the DocNum and DocType and it already filter the SAP B1 tables basing on the DocNum and DocType of the document. In this way it reads the right row in the SAP B1 table and in this way I can read all the fields of this row (also the languageID of the actual document).
    Regards
        Emanuele
    Edited by: Emanuele Croci on Dec 3, 2010 9:03 AM

  • Parameter index move while executing PL/SQL stored procedure/function

    Hello, community.
    Have a question for you. It looked like very easy to write some small JDBC-wrapper to handle stored procedure/functions call for Oracle.
    Here is the code snippet of it:
    import java.io.Serializable;
    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.SQLException;
    import java.util.HashMap;
    import java.util.Iterator;
    import javax.sql.DataSource;
    import oracle.jdbc.driver.OracleTypes;
    import org.apache.log4j.Logger;
    public class SmallHelper {
         public static final int CALL_TYPE__PROCEDURE = 1;
         public static final int CALL_TYPE__FUNCTION = 2;
         public static final int PARAMETER__IN = 1;
         public static final int PARAMETER__OUT = 2;
         private static final Logger log = Logger.getLogger(SmallHelper.class);
         private Connection con = null;
         private CallableStatement statement = null;
         private String name;
         private int type;
         private int resultType;
         private HashMap arguments = new HashMap();
          * Creates connection using data source as parameter.
          * @param ds - data source
          * @throws EhlApplicationException
         public SmallHelper(DataSource ds) throws Exception {
           try {
                   con = ds.getConnection();
              catch (SQLException e) {
                   ExceptionHelper.process(e);
         public void registerProcedure(String name) {
              this.name = name;
              this.type = CALL_TYPE__PROCEDURE;
         public void registerFunction(String name, int resultType) {
              this.name = name;
              this.resultType = resultType;
              this.type = CALL_TYPE__FUNCTION;
          * NB! When You're dealing with stored function index should start with number 2!
         public void registerArgument(int index, Object value, int type, int inOutType) {
              arguments.put(new Long(index), new CallableStatementArgument(value, type, inOutType));
         private String getSQL() {
              StringBuffer str = new StringBuffer("{ call  ");
              if ( type == CALL_TYPE__FUNCTION )
                   str.append(" ? := ");
              str.append(name).append("( ");
              for ( Iterator i = arguments.values().iterator(); i.hasNext(); ) {
                   i.next();
                   str.append("?");
                   if ( i.hasNext() )
                        str.append(", ");
              str.append(") }");
              return str.toString();
         public void execute() throws SQLException{
              String query = getSQL();
              statement = con.prepareCall(query);
              if ( type == CALL_TYPE__FUNCTION )
                   statement.registerOutParameter(1, resultType);
              for ( Iterator i = arguments.keySet().iterator(); i.hasNext(); ) {
                   Long index = (Long) i.next();
                   CallableStatementArgument argument = (CallableStatementArgument) arguments.get(index);
                   int type = argument.getType();
                   if ( argument.getInOutType() == PARAMETER__OUT )
                        statement.registerOutParameter(index.intValue(), type);
                   else if ( type != OracleTypes.CURSOR )
                        statement.setObject(index.intValue(), argument.getValue(), type);
              log.info("Executing SQL: "+query);
              statement.execute();
         public CallableStatement getStatement() {
              return statement;
         public void close() throws EhlApplicationException {
              try {
                   if (statement != null)
                        statement.close();
                   if (con != null)
                        con.close();
              catch (SQLException e) {
                   EhlSqlExceptionHelper.process(e);
         private class CallableStatementArgument implements Serializable{
              private Object value;
              private int type;
              private int inOutType;
              public CallableStatementArgument(Object value, int type, int inOutType) {
                   this.value = value;
                   this.type = type;
                   this.inOutType = inOutType;
              public int getType() {
                   return type;
              public Object getValue() {
                   return value;
              public int getInOutType() {
                   return inOutType;
    }It was really done in 10-15 mins, so don't be very angry at code quality :)
    Here is the problem.:
                   helper.registerProcedure("pkg_diagnosis.search_diagnosis");
                   helper.registerArgument(1, null, OracleTypes.CURSOR, EhlJdbcCallableStatementHelper.PARAMETER__OUT);
                   helper.registerArgument(2, pattern, OracleTypes.VARCHAR, EhlJdbcCallableStatementHelper.PARAMETER__IN);
                   helper.registerArgument(3, lang, OracleTypes.VARCHAR, EhlJdbcCallableStatementHelper.PARAMETER__IN);
                   helper.registerArgument(4, EhlSqlUtil.convertSetToString(langs, ","), OracleTypes.VARCHAR, EhlJdbcCallableStatementHelper.PARAMETER__IN);
                   helper.registerArgument(5, EhlSqlUtil.convertSetToString(diagnosisClass, ","), OracleTypes.VARCHAR, EhlJdbcCallableStatementHelper.PARAMETER__IN);
                   helper.registerArgument(6, parentId, OracleTypes.NUMBER, EhlJdbcCallableStatementHelper.PARAMETER__IN);
                   helper.execute();
                   ResultSet rs = ((OracleCallableStatement) helper.getStatement()).getCursor(1);
                   procedure definition:
    procedure search_diagnosis (l_res OUT dyna_cur,
                               in_search_string IN VARCHAR2,
                               in_search_lang IN VARCHAR2,
                               in_lang_list IN VARCHAR2,
                               in_diag_class_list IN VARCHAR2,
                               in_parent_id IN NUMBER) Procedure call has inner check that fail because of som strange reason:
    in_search_string has 2 as index, that is correct. but procedure recieves is as number 3 in parameter list (what is in_search_lang). Other parameters are moved to. It seems like a cursor takes 2 places in definition. It's clear that if I put in_search_string as 1 parameter and cursor as 0 I'll get invalid parametr bindong(s) exception. So... any ideas why 2nd parameter is actually 3rd?
    Thanks beforehand.

    hmm...moreover:
    if we change procedure to function and call it in a simple way:
    CallableStatement stmnt = helper.getConnection().prepareCall("begin ? := pkg_diagnosis.search_diagnosis(?,?,?,?,?); end;");
                   stmnt.registerOutParameter(1, OracleTypes.CURSOR);
                   stmnt.setString(2, pattern);
                   stmnt.setString(3, lang);
                   stmnt.setString(4, langs);
                   stmnt.setString(5, diagnosisClass);
                   stmnt.setObject(6, parentId, OracleTypes.NUMBER);
                   stmnt.execute();
                   ResultSet rs = (ResultSet) stmnt.getObject(1);the exception is:
    [BEA][Oracle JDBC Driver][Oracle]ORA-06550: line 1, column 14:
    PLS-00382: expression is of wrong type
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignoredif we return some string or number - it works. but when we want cursor back - it fails.
    cursor is defined like ordinary dynamic cursor:
    TYPE dyna_cur IS REF CURSOR;

  • Pass a date parameter to Stored Procedure

    Hello friends,
    Can you help to pass a date parameter to Stored procedure from JSP. This is my code:
    In Oracle 9i I have this:
    PROCEDURE SP_EDORES(
    pfechaini IN hist_pol_reclama.hrc_fecha_contabilidad%Type, <-- This is a date field
    pfechafin IN hist_pol_reclama.hrc_fecha_contabilidad%Type, <-- This is a date field
    p_recordset OUT PKG_REP_CIERRE.cursor_type) AS
    In JSP have this:
    CallableStatement stmt = (CallableStatement)conn.prepareCall( "begin PKG_REP_CIERRE.SP_EDORES(?,?,?); end;" );
    stmt.registerOutParameter(3,oracle.jdbc.driver.OracleTypes.CURSOR);
    stmt.setDate(1,Date.valueOf("01-06-2005"));
    stmt.setDate(2,Date.valueOf("30-06-2005"));
    ResultSet rset = (ResultSet)stmt.getObject(3);
    while (rset.next()) {
    %>
    <TR>
    <TD ALIGN=CENTER> <%= rset.getString(1) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getString(2) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getString(3) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getInt(4) %> </TD>
    </TR>
    <%
    The Stored Procedure returns de Result set, however I think does not recognized the date format because I need it with this format dd-mm-yyyy.
    Thanks in advance

    to use Date you will need the oracle package.
    u can try this other solution: use String, not Date
    CallableStatement stmt = (CallableStatement)conn.prepareCall( "begin PKG_REP_CIERRE.SP_EDORES(?,?,?); end;" );
    stmt.registerOutParameter(3,oracle.jdbc.driver.OracleTypes.CURSOR);
    stmt.setString(1,"01-06-2005");
    stmt.setString(2,"30-06-2005");
    ResultSet rset = (ResultSet)stmt.getObject(3);
    while (rset.next()) {
    %>
    if this don't work you can change your PL/SQL to get Strings and do the conversion with TO_DATE in the sql statement.

  • Passing parameter into stored procedure

    Hi guys,
    I have a big problem here passing as a parameter in stored
    procedure.
    If i pass as a parameter in where clause it is working fine.
    Whenever i pass the parameter in order by it was not working..
    How to implement this issue????
    Here i am giving the example for package:
    PACKAGE XTRA.TEST_STATUS
    AS
    TYPE GenericCurTyp IS REF CURSOR;
    PROCEDURE SP_MAIN
    ( insortgroup IN VARCHAR2,GENERAL_CUR IN OUT GenericCurTyp);
    END TEST_STATUS;
    PACKAGE BODY XTRA.TEST_STATUS
    AS
    PROCEDURE SP_MAIN
    ( insortgroup IN VARCHAR2, GENERAL_CUR IN OUT GenericCurTyp
    ) AS
    BEGIN
    OPEN GENERAL_CUR FOR
    select last_name,first_name from applicant Order By insortgroup;
    END SP_MAIN;
    END TEST_STATUS;
    Passing as a parameter i am getting the below details.
    LAST_NAME FIRST_NAME
    ASFSDAF DASDFASF
    Ad DASD
    Adams John
    DANA WITEST
    If i hot code the parameter insortgroup to last_name
    i am getting the below values:
    LAST_NAME FIRST_NAME
    'ANNUNZIO GIANCOLA GABRIEL
    0'BRIEN ARMA
    0120453EZ ESTANISLAO
    082479 ELIZABETH
    Thanks,
    Rao

    CREATE OR REPLACE PACKAGE xtra.test_status
    AS
      TYPE GenericCurTyp IS REF CURSOR;
      PROCEDURE sp_main
        (insortgroup IN     VARCHAR2,
         general_cur IN OUT GenericCurTyp);
    END test_status;
    CREATE OR REPLACE PACKAGE BODY xtra.test_status
    AS
      PROCEDURE sp_main
        (insortgroup IN     VARCHAR2,
         general_cur IN OUT GenericCurTyp)
      AS
        select_statement VARCHAR2 (4000) := NULL;
      BEGIN
        select_statement :=
        'SELECT   last_name,
                  first_name
         FROM     applicant
         ORDER BY ' || insortgroup;
        DBMS_OUTPUT.PUT_LINE (select_statement);
        OPEN general_cur FOR select_statement;
      END sp_main;
    END test_status;

  • Is it possible to pass TABLE as the output parameter in stored procedure

    Hey Experts,
      Is it possible to pass TABLE as the output parameter in stored procedure.
    eg
    create procedure spGetData
    @tableName as TABLE(intValue INT NOT NUL)
    as 

    You can use OPENQUERY or OPENROWSET, as mentioned above, to make stored procedure results table like. There are
    some limitations with these methods:
    http://technet.microsoft.com/en-us/library/ms188427.aspx
    In OPENQUERY this-sql-server-instance can be used instead of a linked server name. It requires setting data accces server option:
    exec sp_serveroption @server = 'PRODSVR\SQL2012'
    ,@optname = 'DATA ACCESS'
    ,@optvalue = 'TRUE'
    LINK: http://www.sqlusa.com/bestpractices/select-into/
    Kalman Toth Database & OLAP Architect
    SELECT Video Tutorials 4 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Rowtype parameter in stored procedure

    Hi,
    Trying to call a stored procedure/function in C++ using OCI libs, with ROWTYPE parameter. Any ideas on how to do this?
    Thanks!

    You can't.
    ROWTYPE is an internal-to-PLSQL-only datatype (like BOOLEAN) except there is no external data type mapping. Use REF CURSOR or scalar arrays or object arrays instead.

  • Pass array to oracle stored procedure

    I have such a problem: I have to pass array to stored procedure, so I declare type:
    create type tNumberArray as table of number
    and create procedure:
    create or replace procedure proc_1 (in_param in tNumberArray) as
    .... BODY OF PROCEDURE ...
    when I call this procedure from C# like this:
    int []pParam = new int[3] {1,2,3};
    OracleCommand cmd = new OracleCommand("proc_1", dbConn);
    cmd.CommandType = CommandType.StoredProcedure;
    OracleParameter param14 = new OracleParameter("param", OracleDbType.Decimal);
    param14.Value = pParam;
    param14.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
    param14.Size = 3;
    param14.Direction = ParameterDirection.Input;
    cmd.Parameters.Add(param14);
    cmd.ExecuteNonQuery();
    an error occures. It say that there invalid number or type of parameters.
    But when I declare both type and procedure in a package everything goes fine.
    What is the matter? Did anybody have the same problem?

    Not I got next problem:
    when I cannot pass parameter to stored procedure and get array fro it. In other words returning array from procedure and passing some input parameters to it does not word!
    Does anybody know why it happens?

  • REF CURSOR as IN parameter to stored procedure

    Currently, ODP.NET supports REF CURSOR parameter as OUT parameter only.
    Based on the project requirements it is necessary to pass
    multiple records to the stored procedure.
    In this case REF CURSOR as IN parameter is useful.
    What are the plans to implement REF CURSOR as IN parameter to stored procedure?
    What is the work around in case it is necessary to pass several different
    record types as arrays to stored procedure?

    ODP.NET does not limit REF Cursor parameters to IN parameters. This is a known PL/SQL limitation.
    An excerpt from Application Developer's Guide:
    "If you pass a host cursor variable to PL/SQL, you cannot fetch from it on the server side unless you also open it there on the same server call".

  • How can i pass the  parameter for strored procedure from java

    dear all,
    I am very new for stored procedure
    1. I want to write the strored procedure for insert.
    2. How can i pass the parameter for that procedure from java.
    if any material available in internet create procedure and call procedure from java , and passing parameter to procedure from java

    Hi Ram,
    To call the callable statement use the below sample.
    stmt = conn.prepareCall("{call <procedure name>(?,?)}");
    stmt.setString(1,value);//Input parameter
    stmt.registerOutParameter(2,Types.BIGINT);//Output parameter
    stmt.execute();
    seq = (int)stmt.getLong(2);//Getting the result from the procedure.

  • Establishing database connection in stored procedures/functions

    Hi, any body knows how to do it....
    Consider there is 2 database, Oracle_1 and Oracle_2.
    I want to fetch some table data in Oracle_2 from Oracle_1 database Stored procedure/functions through query staments and cursors. How to establish the Oracle_1 DB connection in Oracle_2 DB stored procedure/function. Is it possible?

    Hi,
    Consider there is 2 database, Oracle_1 and Oracle_2.
    I want to fetch some table data in Oracle_2 from Oracle_1 database Stored procedure/functions through query staments and cursors. How to establish the Oracle_1 DB connection in Oracle_2 DB stored procedure/function. Is it possible?
    It's not the same how you implement the programs in java or .Net to create DB connection. It's different over here. You have use the DataBase Links in order to make to connection with another DB and use that Link in the stored procedure or function where ever its necessary as per your requirement.
    - Pavan Kumar N

  • How to execute a stored procedure/function in TOAD?

    Hi, All ,
    Can someone please tell me how to execute a stored procedure/function in TOAD?
    I have tired
    EXECUTE PROCEDURENAME(888), but it doesn’t work.
    TOAD give me the error: invalid SQL statement.
    Thanks a lot

    Write PL/SQl block.
    i.e Begin
    Procedure name..
    end;
    Then it will be excuted.
    Ashutosh

  • Passing data from Oracle stored procedures to Java

    We're going to write a new web interface for a big system based on Oracle database. All business rules are already coded in PL/SQL stored procedures and we'd like to reuse as much code as possible. We'll write some new stored procedures that will combine the existing business rules and return the final result dataset.
    We want to do this on the database level to avoid java-db round trips. The interface layer will be written in Java (we'd like to use GWT), so we need a way of passing data from Oracle stored procedures to Java service side. The data can be e.g. a set of properties of a specific item or a list of items fulfilling certain criteria. Would anyone recommend a preferable way of doing this?
    We're considering one of the 2 following scenarios:
    passing objects and lists of objects (DB object types defined on the schema level)
    passing a sys_refcursor
    We verified that both approaches are "doable", the question is more about design decision, best practice, possible maintenance problems, flexibility, etc.
    I'd appreciate any hints.

    user1754151 wrote:
    We're going to write a new web interface for a big system based on Oracle database. All business rules are already coded in PL/SQL stored procedures and we'd like to reuse as much code as possible. We'll write some new stored procedures that will combine the existing business rules and return the final result dataset.
    We want to do this on the database level to avoid java-db round trips. The interface layer will be written in Java (we'd like to use GWT), so we need a way of passing data from Oracle stored procedures to Java service side. The data can be e.g. a set of properties of a specific item or a list of items fulfilling certain criteria. Would anyone recommend a preferable way of doing this?
    We're considering one of the 2 following scenarios:
    passing objects and lists of objects (DB object types defined on the schema level)
    passing a sys_refcursor
    We verified that both approaches are "doable", the question is more about design decision, best practice, possible maintenance problems, flexibility, etc.
    I'd appreciate any hints.If logic is already written in DB, and the only concern is of passing the result to java service side, and also from point of maintenance problem and flexibility i would suggest to use the sys_refcursor.
    The reason if Down the line any thing changes then you only need to change the arguments of sys_refcursor in DB and as well as java side, and it is much easier and less efforts compare to using and changes required for Types and Objects on DB and java side.
    The design and best practise keeps changing based on our requirement and exisiting design. But by looking at your current senario and design, i personally suggest to go with sys_refcursor.

  • Return a parameter through stored procedures

    Hello Experts
    I want to return parameter through stored procedures so as to ensure that the application has been executed properly.
    My source message format is
    <StatementName5>
    <storedProcedureName action=u201D EXECUTEu201D>
      <table>Summarize_prc</table>
    <empid  [isInput=u201Dtrueu201D] [isOutput=true] type=SQLDatatype>val1</empid>
    </storedProcedureName > 
    </StatementName5>
    Do i need to put some extra parameters for return values from the stored procedures?
    What would be the response message format to return the parameters from stored procedure.
    Thanks
    Sabyasachi

    Hi,
    If you wants to read the return values from stored procedure, the scanario should be designed as Sync.
    The format looks like thsi
    <Message Type Name>
          <STATEMENTNAME_response>
                      <Field1> </Field1>
       </STATEMENTNAME_response>
    </Message Type Name>

  • Kill a stored procedure/function

    Hi Experts,
    I have requirement to kill or terminate the stored procedure/function through UI.
    Is there anyway to kill or terminate the stored procedure/function in oracle.
    Note:-it shouldn't impact the other running Stored procedures/functions.
    Thanks in Adavnce!!!

    Some basics first.
    You do not kill a procedure or function. You kill the process executing it.
    The ALTER SYSTEM KILL SESSION command does not kill a process (session). It requests that process to terminate by communicating with the process via the SGA. If that process is in a synchronous kernel call (and waiting for that call to complete), the process is unable to even check the SGA, never mind respond to a kill-yourself instruction. Which means it cannot terminate itself.
    User (application) code does NOT need the ALTER SYSTEM priv. That will be a very serious security violation. So if you do want to allow user code to make use of that priv to kill user sessions/processes, then you need to wrap that into a secure interface that user code can use. Such as a SYS owned KillUserSession() procedure, executing with definer rights, and ensuring the caller can only kill sessions that it owns (e.g. if caller is schema SCOTT, then only SCOTT sessions can be killed).
    Last comment. Killing user sessions is kind of stupid. As that means you loose. You cannot design properly. You cannot code properly. And to establish some kind of sanity in processing, The Very Large Hammer needs to be employed. Killing sessions does NOT fix the problem. It treats the symptom. The problem is still there.
    And to add a treat-the-symptom-by-killing-the-session button on a .Net (or any other) application? That is, IMO, four-letter-words epic lame.
    What is the real problem?

Maybe you are looking for