Select in if statement

Hi!
create or replace procedure ......
begin
if not exists (select email from emails where email=f) then
end if;
end;
how to check in the if statement either mail exists in table or not?

I would maybe just do it like this:
create table emails as
    (select 'f' email
        from dual);
commit;
declare
    num pls_integer;
begin
    select count(email)
    into num
    from emails
    where email = 'f'
    if num != 0 then
        dbms_output.put_line('Exists');
    end if;
end;
Exists

Similar Messages

  • Delete statement that uses a sub-select with the statement in the cursor

    Hi all,
    How to write write a delete statement that uses a sub-select with the statement in the cursor?
    CURSOR excluded_dates IS         
           SELECT TO_TIMESTAMP(report_parameter_value, in_date_format_mask)
          INTO my_current_date_time
          FROM report_parameters
         WHERE report_parameters.report_parameter_id    = in_report_parameter_id
           AND report_parameters.report_parameter_group = 'DATE_TIME'
           AND report_parameters.report_parameter_name  = 'EXCLUDED_DATE';
    OPEN excluded_dates;
      LOOP
        FETCH excluded_dates INTO my_excluded_date;
        EXIT WHEN excluded_dates%NOTFOUND;
        DELETE FROM edr_rpt_tmp_inclusion_table
        WHERE TO_CHAR(date_time, 'mm/dd/yyyy') = TO_CHAR(my_excluded_date, 'mm/dd/yyyy');
      END LOOP;
      CLOSE excluded_dates;Thanks

    Hi,
    In such case I think is better to create a view an perform the delete using it. Example (using HR schema):
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL> create or replace view v_employees as select * from employees where first_name like 'J%';
    View created
    SQL> select * from v_employees;
    EMPLOYEE_ID FIRST_NAME           LAST_NAME                 EMAIL                     PHONE_NUMBER         HIRE_DATE   JOB_ID         SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
            110 John                 Chen                      JCHEN                     515.124.4269         28/09/1997  FI_ACCOUNT    8200,00                       108           100
            112 Jose Manuel          Urman                     JMURMAN                   515.124.4469         07/03/1998  FI_ACCOUNT    7800,00                       108           100
            125 Julia                Nayer                     JNAYER                    650.124.1214         16/07/1997  ST_CLERK      3200,00                       120            50
            127 James                Landry                    JLANDRY                   650.124.1334         14/01/1999  ST_CLERK      2400,00                       120            50
            131 James                Marlow                    JAMRLOW                   650.124.7234         16/02/1997  ST_CLERK      2500,00                       121            50
            133 Jason                Mallin                    JMALLIN                   650.127.1934         14/06/1996  ST_CLERK      3300,00                       122            50
            139 John                 Seo                       JSEO                      650.121.2019         12/02/1998  ST_CLERK      2700,00                       123            50
            140 Joshua               Patel                     JPATEL                    650.121.1834         06/04/1998  ST_CLERK      2500,00                       123            50
            145 John                 Russell                   JRUSSEL                   011.44.1344.429268   01/10/1996  SA_MAN       14000,00           0,40        100            80
            156 Janette              King                      JKING                     011.44.1345.429268   30/01/1996  SA_REP       10000,00           0,35        146            80
            176 Jonathon             Taylor                    JTAYLOR                   011.44.1644.429265   24/03/1998  SA_REP        8600,00           0,20        149            80
            177 Jack                 Livingston                JLIVINGS                  011.44.1644.429264   23/04/1998  SA_REP        8400,00           0,20        149            80
            181 Jean                 Fleaur                    JFLEAUR                   650.507.9877         23/02/1998  SH_CLERK      3100,00                       120            50
            186 Julia                Dellinger                 JDELLING                  650.509.3876         24/06/1998  SH_CLERK      3400,00                       121            50
            189 Jennifer             Dilly                     JDILLY                    650.505.2876         13/08/1997  SH_CLERK      3600,00                       122            50
            200 Jennifer             Whalen                    JWHALEN                   515.123.4444         17/09/1987  AD_ASST       4400,00                       101            10
    16 rows selected
    SQL> delete from v_employees where hire_date >= to_date('01/06/1998', 'dd/mm/yyyy');
    2 rows deleted
    SQL> regards,

  • Can I use a select and update statement in a single jsp file?

    I want to update the BUY table everytime I would add a SELL transaction.....I want to minus the stocks that I sold to those that Ive bought before.....
    note: I used a seperate table in BUY and SELL transaction
    After I Have added a transaction, I want to update the buy table. This is my problem, can I used both SELECT and UPDATE statement at the same time in a single jsp file for example like this:
    select * from test, test1;
    update test
    set total_shares=total_shares-Stotal;
    where stock_code=Scode AND name_broker=Sbroker;
    Can i have both of these statements in the same jsp file in oder to update the buy table?
    Or can anyone suggest how can process that update?THANKS!
    --------------------

    Can i have both of these statements in the same jsp file in oder to update the buy table?Yes. But wouldn't it have been easier just to try it?

  • I cannot select a particular state in Fireworks CS6 !

    So I've duplicate a state , and after that I tried to change some filters on the newly state , but when I did that it affected the first state too . The problem is that I cannot select a particular state !
    Please ,help !

    I believe this is caused by you working in the background only. You must work in layers for states to be different. Examine my version (in one state I copied the map to a layer, and applied a gaussian blur). Notice that switching to the other state removes that layer, and only displays the background.
    http://www.estructor.altervista.org/links/new_version.png

  • Audit "SELECT FOR UPDATE" statement

    Hi all
    My database is 10.2.0.3 and I enabled audit_trail to DB value already.
    My purpose I want to audit "SELECT FOR UPDATE" statement on the table and I tried to enable audit "SELECT" on the table that have many records in dba_audit_trail because "SELECT" statement that include in this audit and then I tried to enable audit "LOCK TABLE" on the table that doesn't have any records n dba_audit_trail.
    So my question is How to enable audit for collecting only "SELECT FOR UPDATE" statement? or anyone have any idea for this.
    Regards,
    Hiko

    taohiko wrote:
    Hi all
    My database is 10.2.0.3 and I enabled audit_trail to DB value already.
    My purpose I want to audit "SELECT FOR UPDATE" statement on the table and I tried to enable audit "SELECT" on the table that have many records in dba_audit_trail because "SELECT" statement that include in this audit and then I tried to enable audit "LOCK TABLE" on the table that doesn't have any records n dba_audit_trail.
    So my question is How to enable audit for collecting only "SELECT FOR UPDATE" statement? or anyone have any idea for this.
    A consideration on top of the comments made by Justin:
    You have an unfortunate version of the database for auditing: when you enable audit on 10.2.0.3 (or.2 or .1) the redo pattern changes - normally you will see a redo change vector for each row updated, but in these versions you will see two records, a "lock row" followed up "update row piece"; which means your volume of redo may increase significantly.
    I wrote a note about it some time ago: http://jonathanlewis.wordpress.com/2011/05/27/audit-ouch/ and one of the comments includes the bug number ( 5166745 ), reporting fixed in 10.2.0.4 and 11.1.0.6
    Regards
    Jonathan Lewis
    This is bug

  • Insert and select in one statement

    using MS Sql server and VB i can execute two queries Insert and select in one statement e.g. (insert into (....) values (...) Select @@Identity).
    how can i do the same thing using Oracle and VB. ???
    It gives error. here's what i want to do.
    (insert into table1 (...) values (...) Select table1_sequence.currval from dual )
    Khurram

    Here's how you can achieve the same Oracle :-
    Test Db>desc tmp1;
    Name Null? Type
    EMP_NO VARCHAR2(10)
    EID NUMBER
    Test Db>insert into tmp1 (emp_no, eid)
    2 select '123', 1
    3 from dual;
    1 row created.
    Shailender Mehta

  • URGENT : select from table statement in ABAP OO

    Hi all,
    I am an absolute ABAP OO beginner and need some quick help from an expert. How can I make a selection from an existing table (eg MARA) in an BADI which is programmed according to ABAP OO principles.
    In the old ABAP school you could make a TABLES statement at the beginning and the do a SELECT¨* FROM but this does not work in ABAP OO.
    How should i define such simple selections from existing tables. Anyone ?
    Thanks a lot,
    Eric Hassenberg

    *define internal table
    data: i_mara like standard table of mara.
    *select to this table
    select * from mara into table i_mara.
    Also you have to define work area for this internal table in order to use it.
    data:w_mara like line of i_mara.

  • Correct usage of select and option statements

    Is it ok if I say this in my option statement?
    <select name="XYZ" onchange="return valChange(this)">
    <option <%=Selected%> value="100"><%=100%%></option>Or should the option tag just contani the variable names instead of values directly?
    like this
    <option <%=aTmpSelected%> value="<%=abc%>"><%=fslr%></option>where atmpselected contains selected,
    abc contains 100,
    and
    fslr contains 100%,
    as values?
    Please specify using an example.
    Thanks for your time.

    Tutorial on how to use select elements:
    http://w3schools.com/tags/tag_select.asp
    Tutorial on how to use option elements:
    http://w3schools.com/tags/tag_option.asp
    Sandbox to test out your code:
    http://w3schools.com/html/tryit.asp?filename=tryhtml_select2
    The value attribute is the string that gets passed to the form when it's submitted. The text between the <option></option> tags is what gets displayed for that choice. You can use a conditional to decide if "selected" gets added to the html.

  • Adding of new field in dynamic selection for financial statements

    Hi ALL,
    I want to add Trading partner in dynamic selection fields of financial statement report at document level not yet GL master level: S_ALR_87012284 - Balance Sheet / Profit and Loss Statement .
    Can any one tell how to proceed?
    I have referred notes: Note 188663 - Enhancing selection views and dynamic selection.
    But exactly I am unable to find which logical database has to be given?
    regs,
    ramesh b

    Hi,
    If you want to add extra field in your report you can do the setting in Layout selection. If it is not available kinldy check any SAP notes available or not. Otherwise do Zreport with your ABAPer.
    Regards,
    Mohan.

  • Rogue implicit SELECT FOR UPDATE statement in forms 9i  9.0.4.0.19

    all,
    out of 200 production forms, one form occasionally and incorrectly "selects for update" an entire 3 million row table, during an update transaction. this creates 100+ archive logs.
    we cannot repeat the event via testing. but the rogue select statement has been captured from SGA and is listed below. its plain to see that somehow the where clause is truncated to a W, and is then used as a table alias, resulting in the entire table being locked.
    has anyone seen anything like this?
    SELECT ROWID,DISTRIBUTION_PARTY,DISTRIBUTION_PARTY_NAME,CORRESPOND_SEQ_NUM,DISTRIBUTION_SEQ_NUM,VENDOR_NUM,DEPENDENT_SEQ_NUM,INTERNAL_ATTORNEY_USER_NAME,MAIL_LOC,ORIGINAL_FLAG
    FROM CLAIM_DISTRIBUTION_DATA W
    FOR UPDATE OF DISTRIBUTION_PARTY NOWAIT

    Find out where this select statement is issued from first of all. Is it in your code or is it issued implicitely by Forms? Since it has rowid I assume it is an implicit Forms call.
    Do you use on-update triggers any where in this form? on-lock?

  • SELECT-INTO prepared statement?

    Hi,
    I have a single-row select to execute. I don't know if the multi-row select functionality (ResultSets, etc.) should be used for a single-select.
    Here's from the Oracle JDBC Documentation on a prepared statement with input variables:
    PreparedStatement pstmt =
    conn.prepareStatement ("insert into EMP (EMPNO, ENAME) values (?, ?)");
    pstmt.setInt (1, 1500); // The first ? is for EMPNO
    pstmt.setString (2, "LESLIE"); // The second ? is for ENAME
    pstmt.execute ();
    What I would like to do is have a PreparedStatement for output variables in a SELECT-INTO:
    pstmt= conn.prepareStatement("select max(sal) into ? from emp;");
    but there appears to be no bind variable functionality.
    Callable statements apparently are only for stored procedures.
    Basically, should I just use the multirow select for this?
    Thanks,
    Glen

    pstmt= conn.prepareStatement("select max(sal) into ?
    from emp;");
    but there appears to be no bind variable
    functionality.You might be able to bind this as an output parameter, but it seems like extra work (just getting a ResultSet for "select max(sal) from emp" would be a lot more straight forward).
    >
    Callable statements apparently are only for stored
    procedures.Not really, I execute PL/SQL blocks using prepared statements all the time. Sometimes it's the only way to get the data into a format that JDBC can handle.
    Here's an example:
        /** This is the SQL used to call the API ... */
        public static final String spSQL =  
        "declare " +
            "t_warranty_tbl apps.cib_devo_wrapper.wartbltyp; " +
            "x_warranty_tbl apps.cib_devo_wartbltyp; " +
            "x_return_text VARCHAR2(2000); " +
        "begin " +
            "apps.cib_devo_wrapper.cib_get_warranty_info(" +
                "P_SERIAL_NUMBER => ?,"
                "X_WARRANTY_TBL => t_warranty_tbl," +
                "X_RETURN_TEXT => x_return_text," +
                "x_row_count => ?); " +
            // Convert to a table of objects ...
            "x_warranty_tbl := apps.cib_devo_wrapper.cib_warranty_casttowartbltyp(t_warranty_tbl); " +
            // Get the cursor with order by ...
            "OPEN ? FOR SELECT * FROM TABLE(CAST(x_warranty_tbl AS apps.CIB_DEVO_WarTblTyp)) tbl " +
                "WHERE tbl.entitlementReturnCode != apps.cib_devo_wrapper.g_ent_ret_code_08 " +
                "ORDER BY tbl.INSTALLEDAT_CUSTOMER_NAME, tbl.SITE_NAME, tbl.SITE_ID, " +
                          "tbl.PRODUCT_FAMILY, tbl.PRODUCT_NAME, tbl.SERIAL_NUMBER; " +
           "?:=x_return_text; " +
        "end;";In this example, I declare a few variables, call a stored procedure,
    do some more PL/SQL to reduce the results before I finally bring them back.
    The first placeholder (question mark) is the input serial number, the second one is an output parameter that gives the row count. The third
    question mark is the cursor that contains the data I need, and the fourth is a reference to a status message.
    As you can see, the PL/SQL isn't exclusively stored procedure calls.
    >
    Basically, should I just use the multirow select for
    this?I think you'd need code that looks something like:
    DECLARE
    myCount NUMBER;
    BEGIN
    select max(sal) into myCount
    from emp;
    ? := myCount
    END;Although wrapping the select in a BEGIN..END block may be enough.

  • "select into" query statements using the DI API

    I am trying to use the DI API (6.5) t create a temp table based on an existing table.  For example, here is a query string....
    select * into ORDR_TEMP from ORDR
    Code...
    oRecordSet := IRecordset(oCompany.GetBusinessObject(BoRecordset));
    oRecordset.DoQuery(sSql);
    Error I get...
    1). [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot use SELECT INTO in browse mode. 2). [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared
    For any other regular select statements the previous code works.  Does anyone know for sure if a "select into" statement is not possible using the DI API?

    Hi Bill,
    I´m not really sure if select into is avaiable. But here you´ve got a hint: You could use a user defined function to do it, and just call the function from your code.
    SELECT dbo.MyFunction()
    Having this function defined in your SQL Server:
    CREATE function MyFunction ()
    returns char(2)
    AS
    Begin
    select * into ORDR_TEMP from ORDR
    Return ('OK')
    End
    Hope this helps,
    Ibai Peñ

  • Handling menu selection in multi states of states machine

    Hi everyone,
    My application uses states machine architecture, I have to handle menu selection in two different states and the 2nd of them has to be handled by the event case structure.
    The problem is that when I use event structure in the 1st state it is also handled later by the event case in the 2nd state and it is impossible to handle menu selection in the 1st state by the "Get Menu Selection" block because according to it's descripton if event structure is configured to handle the same menu as item as this block, LabVIEW ignores this function.
    I would be greatful for any clue.
    Greetings,
    Mariusz
    Solved!
    Go to Solution.

    Thanks for respond.
    Here's a code explaining the main idea.
    Attachments:
    Untitled 1.vi ‏9 KB
    Enum_States.ctl ‏5 KB

  • One select using dynamic statements....

    Hello ,
    I am using for all entries. I want to combine all in one because currently I have to write two select statements based on condition for internal table not empty.
    IF IT_WIID[] IS NOT INITIAL.
    SELECT * FROM zcust into CORRESPONDING FIELDS OF TABLE i_t01_dup
             FOR ALL ENTRIES IN IT__WIID
             WHERE WI_ID = IT_WIID-WI_D
             AND RECNO IN TRECNO.
    ESLE.
    SELECT * FROM zcust into CORRESPONDING FIELDS OF TABLE i_t01_dup
             WHERE RECNO IN TRECNO.
    ENDIF.
    Regards,
    Jainam.
    Edited by: Jainam Shah on Mar 5, 2010 8:31 PM

    OK, I wrote a test program myself which proves my theory. I can't believe I am resorting to a p***ing contest instead of going home for the weekend.
    First count SE16 records on DD02L by specifying 'A' for AS4LOCAL field and note down the count.
    Then, try this program:
    REPORT y_sk_test .
    PARAMETERS: p_itabfl TYPE c AS CHECKBOX DEFAULT 'X',
                p_as4lcl TYPE dd02l-tabclass DEFAULT 'A'.
    DATA: t_dd02l TYPE STANDARD TABLE OF dd02l INITIAL SIZE 0 WITH HEADER LINE,
          t_itab  TYPE STANDARD TABLE OF dd02l INITIAL SIZE 0 WITH HEADER LINE.
    IF p_itabfl = 'X'.
      t_itab-tabname = 'T000'.
      APPEND t_itab.
    ENDIF.
    SELECT *
    INTO   TABLE t_dd02l
    FROM   dd02l
    FOR ALL ENTRIES IN t_itab
    WHERE  tabname = t_itab-tabname
      AND  as4local = p_as4lcl.
    DESCRIBE TABLE t_dd02l LINES sy-tfill.
    WRITE: / 'Number of rows selected:', sy-tfill.
    If you uncheck the checkbox, the count matches the SE16 count and I didn't have to use the IF ELSE block.

  • SELECT - INSERT/UPDATE statement mapping.

    This might be a silly question, but are there any Java libraries that can perform an arbitrary SELECT statement to INSERT/UPDATE statement mapping? Or indeed, is this in fact possible?
    Just to be a little clearer, if we had the statement;
    SELECT [Field1] FROM [Table1]
    It would map down to;
    INSERT INTO [Table1] VALUES [Field1]='foo'
    Please excuse my INSERT syntax if it is incorrect, I hardly ever use these statements.
    The reason that I ask is because I am writing a piece of software that can perform quite complex extractions from databases, and it would be nice to be able to automatically 'reverse' the extraction, and perform updates on the extracted data.
    Unfortunately, because of the architecture and requirements of the application, I can not just update a resultset and call the update() method.
    Thanks for your time.
    Ben

    You can define a Bean or simple class to define a table record type (table structure), defining all fields, the primary key and maybe more.
    then deriving a select or insert or update can be done with ease.

Maybe you are looking for

  • ASA 5505 VPN conenction issue

    Good morning everyone. I am in need of some help. I am a newbie when it comes to configuring the ASA. Here is my problem. I have the asa configure and it is allowing me to get out to the internet. I have several VLANs on my network and from inside I

  • New to podcasting, and if that's not bad enough....I'm on a PC....help!!

    So here's my issue, Not only am I on a pc and can't make the move to a Mac right now(it's not out of the question for later tho..) I am trying to make a video podcast for a sport that I do. I was in a shop the other day and a nice Mac rep was showing

  • Ignore some specific Open item in AR during credit check

    Hi, User had a customer whose AR open items are subjected to "settlement issues" and are still opened after 90 days. The customer had been assigned a risk category that will blocked the sales order when open item is more than 90 days. How can I confi

  • How to I get my Mac to show the iPhoto tool bar across the top?

    My iPhoto doesn't show a tool bar across the top--just the categories on the side.  Therefore, I can follow Gary's instructions on deleting photos.  I didn't realize until I watched a video that I didn't have the options he was talking about.

  • Fill colors to ALV cells

    Hi All, How can I display multiple colors to different cells in an ALV ?. Please help.. Thanks in advance, sudeep v d..