Ignoring the empty parameter in a stored procedure

I am writing a SP that ignores an empty parameter in a where clause like this clause.
Create procedure @myvar AS int blah
Select * from companies
where 1 = 1
If @myvar is <>"
and id = @myvar

This seems to be a simple task, but it does not work. Thanks in advance

Use the ISNULL trick, but at the beginning of your stored procedure, add the line:
IF LTRIM (@myvar) = "SET @myvar = NULL

Tags: ColdFusion

Similar Questions

  • How to pass an array as a parameter to a stored procedure

    Hi all
    I want to pass the name of a table as a parameter in a stored procedure, which will be used for cursors, etc..
    But when I pass the parameter and I compile the S.P. he gives me error (error: table exist not...)

    Any help?

    Thanks in advance, Marco

    Cannot open a cursor explicit when it comes to the dynamic table names or parameters. This is because the explicit and implicit cursors seek real table names since they are static.
    Here your name of the table is dynamic, so u need to use dynamic that is ref cursor to and not static cursor.

    I made the correction in the code below. Run it and check the result!

    CREATE OR REPLACE PROCEDURE "P_1" ( TAB1 VARCHAR2)
    AS
    field1 CHAR(5);
    field2 CHAR(5);
    
    c1 sys_refcursor;
    
    begin
    
    l_str := 'select a,b,c from '||tab1||' INNER JOIN tab2 ON a = .......';
    open c1 from l_str;
    
    /*OPEN C1;
    CURSOR C1
    IS
    SELECT a, b , c
    FROM TAB1
    INNER JOIN
    tab2
    ON a = .......
    OPEN C1;*/
    
    LOOP
    FETCH C1
    INTO ..... 
    
    EXIT WHEN C1%NOTFOUND;
    .....
    END;
    END LOOP;
    
    CLOSE C1;
    
    EXCEPTION
    WHEN OTHERS
    .....
    END;
    
  • query as a parameter in a stored procedure

    Hi all

    I'm working on Oracle 10 g.
    Can I send a query as a parameter in a stored procedure?

    Thanks in advance

    You can, of course. Should you? At most, rarely.

    You can use SQL statements (EXECUTE IMMEDIATE or DBMS_SQL) Dynamics to run an arbitrary string as a SQL statement. There are serious security problems if someone how to pass a statement dangerous SQL in numbers (update the USERS table, remove all data from an important painting, etc.). If you pass in a SELECT statement and you do not know the structure of the result set, you must use DBMS_SQL rather than the simple EXECUTE IMMEDIATE and a more complicated API to describe the result set.

    Justin

  • Composer calendar ignores the startTime parameter

    Hello everyone!

    I am creating a calendar event by using the composer calendar via the Invocation Framework System. The problem is that the calendar composer dialog box ignores the startTime parameter. Here is the code:

    bb::system::InvokeRequest cardRequest;
    QVariantMap requestData;
    
    requestData["startTime"] = dateTimePicker_->value().toString("yyyy-MM-dd hh:mm:ss");
    
    cardRequest.setTarget("sys.pim.calendar.viewer.eventcreate");
    cardRequest.setAction("bb.action.CREATE");
    cardRequest.setMimeType("text/calendar");
    
    bool ok = true;
    QByteArray encodedRequestData = bb::PpsObject::encode(requestData, &ok);
    if (!ok)
    {
        Q_ASSERT(false);
        return;
    }
    
    bb::system::InvokeTargetReply *reply = invokeManager_->invoke(cardRequest);
    QObject::connect(reply, SIGNAL(finished()),
             this, SLOT(invokeCalendar_finished()));
    

    I tried to use 'startTime' and 'start', or work.

    Any help is very appreciated!

    Just do QDateTime.toString () with no args just worked for me.

    Have an idea what the term is supposed to be in? It says int but does not say if it is in seconds, minutes, hours, milliseconds

  • to find the location of PL/SQL, stored PROCEDURE in the database

    Hello

    This is the detail I have the executable of the Application Developer program simultaneous

    Executable NAPESCO_STAFF_LEDGER_DTLS

    Short name NPSTALEDDTLS

    Application of human resources

    Execution of PL/SQL, stored procedure method

    Name of file execution NAPESCO_STAFF_LEDGER_DTLS


    I would like to know how to view and change this procedure, where it is stored

    kindly help

    Hello

    This seems to be a custom package. To display the source of the simultaneous program ' PL/SQL Stored Procedure', please refer to (Note: 455582.1 - where can I get the whole "stored procedure" Pl/Sql Source file on the current program?).

    Thank you
    Hussein

  • relative to the parameter in a stored procedure returns

    I'm doing a sp sp / sql with select and update, the idea is to return the value assigned in the select, but when I test the procedure about adding the parameter to the method PPerformance does not, in fact I am new to oracle, I searched some tutorials but I have not managed to solve the problem


    my source its:
    create or replace
    PROCEDURE PA_CONSECUTIVO (TipoConsecutivo in  VARCHAR2, AUXI OUT int )
    
    AS
    aux2 int;
    BEGIN
    
     SELECT consecutivo + 1 into aux2 FROM  tbl_consecutivo
        WHERE UPPER(ltrim(rtrim(Tipo_Consecutivo))) = UPPER(ltrim(rtrim(TipoConsecutivo)));
        
        UPDATE tbl_Consecutivo SET consecutivo = aux2 
    WHERE upper(ltrim(rtrim(Tipo_Consecutivo))) = upper(ltrim(rtrim(TipoConsecutivo))) ;
    
     AUXI:=aux2;
        
    
    
    END PA_CONSECUTIVO;
    the table og the request her:
    TIPO_CONSECUTIVO     VARCHAR2(20 BYTE)
    CONSECUTIVO     NUMBER(38,0)
    FECHAULTIMO     DATE
    I appreciate the help.

    Published by: 1008490 on 29-may-2013 07:49

    Your stored procedure has 2 settings while you provide 1. Use something like:

    SET SERVEROUTPUT ON
    DECLARE
        V_AUXI NUMBER;
    BEGIN
        PA_CONSECUTIVO('ENTRADA',V_AUXI);
        DBMS_OUTPUT.PUT_LINE('AUXI = ' || V_AUXI);
    END;
    /
    

    SY.

  • Is it possible to move an Oracle null input parameter to a stored procedure

    I have a stored procedure taking 3 inputs and 1 output of donne. I use the Oracle parameter to add all the input parameters 3 as follows:

    OracleParameter = cmd inobj. Parameters.Add ("wid", OracleDbType.Int32, 50);
    inobj. Direction = ParameterDirection.Input;
    inobj. Value = _employeeID;

    and the addition of the setting of output as follows:

    OracleParameter outobj is _cmd. Parameters.Add ("w_first", OracleDbType.Varchar2, 50);
    outobj. Direction = ParameterDirection.Output;

    On the side of the user interface, the user has the option of providing 1 entry or all inputs or any 2 based on his interest. Stored proc looks like this:
    SP (inp1 in parameter, inp2 in inp3 in parameter, parameter, out parameter output1)

    If I just get 1 or 2 entries of the user, it is very good query output data using the same stored procedure or do I create stored procedures for each scenario (combination of different entries)?

    I get an error in pl/sql which indicates the invalid number of arguments?

    Maybe I can be more clear with c# code. :)

    void SaveSomethingInOracle(int param1, string param2 = null, decimal? param3 = null)
    {
    // Set up your oracle connection and query here
    OracleParameter inobj = _cmd.Parameters.Add("w_id", OracleDbType.Int32,50);
    inobj.Direction = ParameterDirection.Input;
    inobj.Value = param1;
    
    OracleParameter inobj2 = _cmd.Parameters.Add("name", OracleDbType.Varchar2,50);
    inobj2.Direction = ParameterDirection.Input;
    inobj2.Value = param2;
    
    OracleParameter inobj3 = _cmd.Parameters.Add("quantity", OracleDbType.Decimal,50);
    inobj3.Direction = ParameterDirection.Input;
    if (param3.HasValue)
    {
    inobj3.Value = param3.Value;
    }
    else
    {
    inobj3.Value = null;
    }
    }
    

    This c# method takes 3 parameters. The first is necessary, the other two are optional. If you do not set them, they take the value default null and passing it to the database. If you want to set the first and third only, you can still pass null as the other. If you have this piece of code to call the stored procedure any combination of parameters that you use, and the proc will get values or NULL values properly.

    Hope he says. You need only one together code to do what you want to do. :)

    Published by: Tridus on December 19, 2012 12:10

  • Pass parameters to the box of the HTML form to a stored procedure

    I'm always looking for a solution to my problem of forms. For the record, I don't use Express applications to create my application - I use PL/SQL right. I need to know how to pass parameters from the box to my Web form. I welcome people select one or more checkboxes in a form that calls a remove function to delete the selected records. What I read in Oracle of the "Guide to the developer of database applications - Fundamentals" is not useful to me. If someone could tell me some examples, maybe I could see what I'm doing wrong. Here is what I wrote in "the developer of database applications - fundamentals Guide ':

    All the boxes with the same NAME attribute are a group of checkbox. If none of the boxes in a group is selected, the stored procedure receives a null value for the corresponding parameter.

    If a check box in a group is selected, the stored procedure receives a single parameter of VARCHAR2.

    If more than one check box in a group is enabled, the stored procedure receives a parameter with the type of PL/SQL TABLE OF VARCHAR2. You must declare a type like this, or use a pre-defined as OWA_UTIL. IDENT_ARR. To retrieve the values, use a loop:
    CREATE OR REPLACE PROCEDURE handle_checkboxes ( checkboxes owa_util.ident_arr )
    AS
    BEGIN
    ...
    FOR i IN 1..checkboxes.count
    LOOP
    htp.print('&lt;p&gt;Checkbox value: ' || checkboxes(i));
    END LOOP;
    ...
    END;
    /
    SHOW ERRORS;

    I'm not sure that understand what your question is.

    If your web form has the following defined all with the same name:

    one
    two
    three
    

    You create and save a procedure to manage the sending of a form that contains a parameter with the name of attrib type owa_util.ident_arr for example:

    create or replace procedure handle_form(attrib owa_util.ident_arr) as
      iter number;
    begin
      for iter in attrib.first .. attrib.last loop
        -- do something with attrib(iter)
      end loop;
    end;
    /
    

    Now, the only problem with this Manager (or any other), is that if the user selects any of the boxes, or no value for the parameters expected, the Manager called with parameters missing or with on all of the passed parameters, as well as the call will error.

    To move, you need to provide default values for all parameters passed to your handler such as the settings of ident_arr, but with ident_arr settings, it's hard to do with autonomous procedures. If you place your procedure in a package you can define variables of package-level of the appropriate types that can be used as default values:

    create or replace package my_web as
      empty_arr owa_util.ident_arr;
    
      procedure handle_form(attrib owa_util.ident_arr := empty_arr);
    end my_web;
    /
    create or replace package body my_web as
      procedure handle_form(attrib owa_util.ident_arr := empty_arr) as
        iter number;
      begin
        for iter in attrib.first .. attrib.last loop
          -- do something with attrib(iter)
        end loop;
      end;
    end my_web;
    /
    

    now, when you hit in the situation where the user does not select the checkboxes, the call to handle_form will be no reviewable error on due to missing parameters, and the empty_arr will not have all the elements to iterate over so the loop in the body of the procedure will be fine and you will be able to retrieve each value of the checkbox selected attrib table when you iterate on it.

  • Problem with the Entity Framework by using stored procedures

    I am developing a project with Oracle DB and Entity Framework.
    Due to performance issues, for some querys I uses procedures stored instead of LINQ queryies,
    When I try to add my model EF procedure, the procedure is added but the Model Designer
    It does not acknowledge the columns returned by the procedure.
    so I can't create something complex to the user the results of the procedure
    in a domain service

    Here's the relevant readme which has some tips: http://www.oracle.com/technetwork/topics/dotnet/tech-info/default-338300.html#mozTocId610465

    If you do a forum search there is further discussion of the issues, and the readme file provided with version beta has also some information.

    But I agree with the general theme: using stored procedures in the EF is a PITA. :( I really hope they do something to make it easier in the future because this is probably the single most important weakness in the implementation of Oracle EF and establishment of a complex type is your time and picky it's ridiculous. (I found it less problematic if your procedure returns a complete picture that your model has already an entity for, because you can get away with only add the entry to one of the configurations for the cursor rather than one for each column.)

    Even an external tool where direct you to the procedure and it creates the configuration entries to be able to copy and paste would be a huge improvement.

  • How to query the DDL lock functions or stored procedures and packages?

    Hello!

    The subject says it all: how to display existing DDL locks on the functions or stored procedures and packages?

    While running a procedure, it cannot be deleted or replaced, so there must be a DDL lock on it. The information does not seem to be in V$ LOCK or V$ LOCKED_OBJECTS.

    Thank you!
    Marcus

    Published by: David on November 21, 2009 15:43

    Hello

    You have the DBA_DDL_LOCKS view.

    Best regards
    Jean Valentine

  • How to transfer a. DOC /. XLS /. JPG of the client computer to a stored procedure?

    We have a requirement like this: we have a system of management (DMS). There are documents of different types on the client HARD disk. He could be. DOC. XLS. PDF and JPG files. We need to read our form (10g R2) and then without saving changes to a database, we need to transfer them to a queue Microsoft Message Queuing (MSMQ).

    We use WebUtil CLIENT_IMAGE. READ_IMAGE_FILE to read. JPG of the client computer to an element of the image in the form. But how can we read. DOC. XLS and. PDF files? There is no element of Oracle Forms to store BLOBs?


    How can we do this pls?

    You can use the Webutil_File_Transfer.Client_To_DB function to transfer the file to a table in the database. From there, you can process the file with your pl/sql procedure.

    without saving changes to a database

    Just delete the recording later.

  • Error, while the creation and execution of stored procedure

    Hello

    I'm creating a procedure stored and discovered during the compilation and execution of procedure.

    CREATE OR REPLACE PROCEDURE procTEST
    AS
    BEGIN
    WITH
    AS Report1
    (
    SELECT * FROM Employee
    )

    SELECT * FROM REPORT1

    END;
    /

    ERROR when compiling

    -------------------------------

    PROCTEST update procedure

    Errors: Newspaper the compiler check

    ERROR when executing

    ---------------------------------

    PROCTEST update procedure

    Errors: Newspaper the compiler check
    Error from line: 15 command.
    EXEC procTEST
    Error report-
    ORA-06550: line 1, column 7:
    PLS-00905: object SYSTEM. PROCTEST is not valid
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    06550 00000 - "line %s, column % s:\n%s".
    * Cause: Usually a PL/SQL compilation error.
    * Action:

    Hello

    user13360241 wrote:

    I want to insert values into the table tmpemployees.

    Insert into tmpemployees

    Select * from Report1

    CREATE OR REPLACE PROCEDURE procTEST
    AS
    BEGIN
    WITH
    AS Report1
    (
    SELECT * FROM Employee
    )

    Insert into tmpemployees

    SELECT * FROM REPORT1

    END;
    /

    I see.  Then, there is no need to use the PL/SQL.  All you need is:

    INSERT INTO tempemployees

    SELECT *.

    OF REPORT1.

    (assuming that the columns match Report1 tempemployees... It is best to explicitly list the individual columns, like this:

    INSERT INTO tempemployees (employyee_id, first_name,...)

    SELECT (col_1, col_2,...)

    OF REPORT1.

    )

    If you need to use the PL/SQL for a reason, you could use the exact same INSERT statement in PL/SQL:

    CREATE OR REPLACE PROCEDURE proctest

    AS

    BEGIN

    INSERT INTO tempemployees (employyee_id, first_name,...)

    SELECT (col_1, col_2,...)

    OF REPORT1.

    END proctest;

    /

    DISPLAY ERRORS

  • Get the error ORA-01422 in stored procedure

    ORA-01422: exact fetch returns more than number of lines
    This page explains the error:
    http://www.techonthenet.com/Oracle/errors/ora01422.php

    This is my procedure:
    In the clause select is causing the error. I understand the nature of the error, but the strange thing is that when I run the sql code, remove the "in."
    part of my test settings, I just receive a single line. Always when I execute my procedure with the same settings I get the error. What could be wrong?

    create or replace
    PROCEDURE COUNTER_GETACTIVE
    (
    METERPOINTID IN MeterPointCounters.MeterPointId%Type,
    METERPOINTCOUNTERNR IN METERPOINTCOUNTERS. Type of METERPOINTCOUNTERNR %,
    p_cursor on REFCURSOR_PKG.counter_cursor
    )
    IS
    l_counterNr CounterBridgeTable.CounterNr%type;
    l_meterId CounterBridgeTable.MeterId%type;
    BEGIN
    Select counternr, meterid in l_counterNr, l_meterId from CounterBridgeTable where meterpointid = METERPOINTID and meterpointcounternr = METERPOINTCOUNTERNR and datetom is null;

    Open p_cursor for select * from counters where counternr = l_counterNr and meterId = l_meterId;

    END COUNTER_GETACTIVE;

    You actually run this query

    select counternr, meterid from CounterBridgeTable where meterpointid = METERPOINTID and meterpointcounternr = METERPOINTCOUNTERNR and datetom is null;
    

    param name is identical to the column, he's ignoring your param and pretty much do a self-join

    Try this:

    create or replace
    PROCEDURE COUNTER_GETACTIVE
    (
    p_METERPOINTID IN MeterPointCounters.MeterPointId%Type,
    p_METERPOINTCOUNTERNR IN METERPOINTCOUNTERS.METERPOINTCOUNTERNR%type,
    p_cursor out REFCURSOR_PKG.counter_cursor
    )
    IS
    l_counterNr CounterBridgeTable.CounterNr%type;
    l_meterId CounterBridgeTable.MeterId%type;
    BEGIN
    select counternr, meterid into l_counterNr, l_meterId from CounterBridgeTable where meterpointid = p_METERPOINTID and meterpointcounternr = p_METERPOINTCOUNTERNR and datetom is null;
    
    open p_cursor for select * from counters where counternr = l_counterNr and meterId = l_meterId;
    
    END COUNTER_GETACTIVE;
    

    Published by: tanging on June 8, 2010 10:37

  • The Null value as the default value for an input to a stored procedure parameter

    Hello

    How can we set the default values with the NULL value for the parameter in a stored procedure.
    create or replace procedure emp_proc ( p_test_input in varchar2
                                                        p_emp_id in number,
                                                        p_emp_name in varchar2,
                                                       p_manager_id in number )
    as
      begin
       if ( upper ( p_test_input ) = 'I' )
       then
          insert into emp
          values      ( p_emp_id  ,p_emp_name ,p_Manager_id,sysdate );
       elsif ( upper ( p_test_input ) = 'D' )
       then
          delete from emp
          where       emp_id  = p_emp_id;
       else
          dbms_output.put_line
             ( 'Please input ''A'' for ADD or ''D'' Delete  EMPLOYEE'
             );
       end if;
    end;
    As described above if I want to delete only the functioning

    I want to call this procedure without pass additional parameters.
     EXECUTE  emp_proc('D',1010);
    Published by: Rede on May 28, 2010 12:21

    Published by: Rede on May 28, 2010 12:22
    create or replace procedure emp_proc ( p_test_input in varchar2,
                                                        p_emp_id in number,
                                                        p_emp_name in varchar2 default null,
                                                       p_manager_id in number default null )
    
  • Key of the stored procedure

    Hello

    I have a function in the db that returns a numeric value after passing an Id (digital). How do I create a join in physical layer as funtion will return a digital and given that it is a function, it can return only a single column.

    is it possible that I can keep the id (parameter) in the phycisal layer which I'm passing to the function, so that I can join neccasy in the physical layer with fact/Sun to the stored procedure.

    is the possible creation of mutiple stored procedure in physics if my function to only return a single column.

    Concerning
    Issue

    If I understand your question, you have a function that returns a numerical value based on an ID, we'll call it Customer ID as a sample. What you need to do is to create a view like this:

    CREATE THE VIEW IN CIRCULATION
    SELECT CUSTOMER_ID, get_outstanding (CUSTOMER_ID) FROM CLIENT

    You can then query this view like this:

    SELECT * EXCEPTIONAL WHERE CUSTOMER_ID = 999

    You could also use this point of view in your physical layer and attach it by customer ID. If you already have a table of facts, you could put a top view to add the extra column with your function. It of all good and should work fine with a warning. PL/SQL execution on SQL functions is not effective. Oracle has switch context between SQL and PL/SQL for each line and change in context is an expensive operation. In a proper system of DWH you préremplira your fact table with the results of get_outstanding for all customers so that there is no delay in the calculation it when OBIEE queries data.

Maybe you are looking for