Insert statement executes before If statements

Hello All,
I am trying to validate few fields before inserting them into table.
for example:
IF params('txtID') IS NULL THEN
"SOME MSG";
ELSIF params('txtName') IS NULL THEN
"SOME MSG";
END IF;
INSERT INTO TABLE T1
VALUES(params('txtID'),params('txtName');
What I want to do is : I want to validate two fields before inserting.
Can anyone help me?
Thank you,
H.

It directly executes insert statement. If I delete insert, it executes that IF statement.
It is strange.Let's be clear about this, it is not strange. Your original IF statements did execute before the INSERT but they did not raise an exception. Consequently the INSERT statement was processed. Your "SOME MSG" mechanism is obviously only triggered after the procedure completed. Walter's solution worked for you because it raise exceptions, which prevented the INSERT statement from executing.
Anyway, it is obvious that you haven't got NOT NULL enforced on your table, which is A Bad Thing. You shoudn't be enforcing such constraints through a procedure.
Cheers, APC
blog: http://radiofreetooting.blogspot.com
Edited by: APC on Feb 3, 2009 5:48 PM
Only because the OP edited their final post, and removed the lines I quoted.

Similar Messages

  • Return statement executed before soapresult is set

    In my method i'm doing a soap call.
    The return statement is executed before de soapresultset is read.
    is there a way to "delay" the return statement

    Your question doesn't make any sense. Execution leaves the method when it ends or when the return statement is reached. If you want something to happen before the return, then do it before you call return.
    My guess at this point is that you're using exceptions poorly.

  • Parent Concurrent Program executes  rest of the logic  before PAUSED STATE.

    Procedure parent_cp (errbuf out nocopy varchar2, retcode out nocopy varchar2) IS
    ret number;
    i number;
    BEGIN
    fnd_msg_pub.initialize;
    BEGIN ---Block A
    req_data := fnd_conc_global.request_data;
    if (req_data is not null) then
    i := to_number(req_data);
    if (i < 5 ) then
    errbuf := 'Done!';
    retcode := 0 ;
    return;
    end if;
    else
    i := 1;
    end if;
    for i in 1 .. 4 loop
    ret := fnd_request.submit_request('CZ', 'Child','Delete Localized Text - Child Number : ' ||TO_CHAR(vChildNo), NULL,TRUE, vChildMdlRange);
    fnd_conc_global.set_req_globals(conc_status => 'PAUSED', request_data => to_char(vChildNo)) ;
    IF (ret = 0 ) THEN
    errbuf := fnd_Message.get;
    retcode := 2;
    ELSE
    errbuf := 'Sub-Request submitted!';
    retcode := 0 ;
    END IF;
    END LOOP;
    END;
    BEGIN ---block B
    dbms_output.put_line(' Block after submitting Child CP ');
    END;
    END parent_cp;
    when i execute the above Parent CP ,it submitted 4 Child CPs and Parent CP went into Pause state. Before Parent CP went into Pause state it executed the Block B.
    My Requirement is it should execute the block B after completion of all child CPs.
    Please suggest how to achieve the above requirement.
    Thanks,
    Murali.

    Procedure parent_cp (errbuf out nocopy varchar2, retcode out nocopy varchar2) IS
    ret number;
    i number;
    BEGIN
    fnd_msg_pub.initialize;
    BEGIN ---Block A
    req_data := fnd_conc_global.request_data;
    if (req_data is not null) then
    i := to_number(req_data);
    if (i < 5 ) then
    errbuf := 'Done!';
    retcode := 0 ;
    return;
    end if;
    else
    i := 1;
    end if;
    for j in 1 .. 4 loop
    vRequestId(j) := fnd_request.submit_request('CZ', 'Child','Delete Localized Text - Child Number : ' ||TO_CHAR(vChildNo), NULL,TRUE, vChildMdlRange);
    fnd_conc_global.set_req_globals(conc_status => 'PAUSED', request_data => to_char(vChildNo)) ;
    IF (vRequestId(j) = 0 ) THEN
    errbuf := fnd_Message.get;
    retcode := 2;
    ELSE
    errbuf := 'Sub-Request submitted!';
    retcode := 0 ;
    END IF;
    END LOOP;
    END;
    BEGIN ---block B
    For j in vRequestId.FIRST..vRequestId.LAST LOOP
    fnd_file.put_line(fnd_file.log,' reuest' || vRequestId(j));
    vrequeststatus := fnd_concurrent.get_request_status(vRequestId(j),
         NULL,
    NULL,
         phase,
         status,
         dev_phase ,
         dev_status ,
         message );
    WHILE (dev_phase != 'COMPLETE') LOOP
    fnd_file.put_line(fnd_file.log,' while loop' || vRequestId(j));
    vrequeststatus := fnd_concurrent.wait_for_request(vRequestId(j),
    60,
         10,
         phase ,
         status ,
         dev_phase ,
         dev_status ,
         message );
    END LOOP;
    END LOOP;
    dbms_output.put_line(' Block after submitting Child CP ');
    END;
    END parent_cp;
    The above procedure was the Parent CP. Here the problem is in fnd_request.submit_request('CZ', 'Child','Delete Localized Text - Child Number : ' ||TO_CHAR(vChildNo), NULL,TRUE, vChildMdlRange); i have given sub_request as True and used fnd_conc_global.set_req_globals(conc_status => 'PAUSED', request_data => to_char(vChildNo)) ; to make parent CP to pause it.
    It submits 4 child CPs as expected but the phase as INACTIVE and status NO MANAGER and PARENT CP was always in running state.
    If i make sub_request parameter of fnd_request.sub_request to FALSE . It submits 4 child CPs as expected with the phase as PENDING and status NORMAL and PARENT CP was always in running state. But child cps are never changing the Phase as RUNNING. It is always in PENDING STATE.
    Please suggest how to use fnd_conc_global.set_req_globals and fnd_concurrent.wait_for_request together.

  • Execute multiple dml statements concurrently.

    Hi all,
    I have a requirement to execute multiple dml statements at the same time. I tried to achieve this using dbms_job, but failed.
    I scheduled 3 dbms_job at the same time. Each job has a bulk insert statement, inserting into a single target table. The 3 jobs kicked off, but there were close a minute apart.
    Is there any other way to achieve this?

    You can launch 3 separate SQL Plus sessions, but how do you execute the dml statements at the same exact time?From my desktop machine, here's how I'd do it:
    Create a dos batch file (runall.cmd for example) that looks like this:
    start some_command.cmd
    start some_command.cmd
    start some_command.cmd
    Then just double click on it. This will lauch some_command.cmd in 3 separate sessions. Each will be launched but will not wait to complete before launching the next.
    Inside the batch file, some_command.cmd, you can have whatever you want. But it will probably be sqlplus.exe with some command line options (one of them a .sql script).
    This is how I've used Tom Kite's "DIY Parallelization". But I normally would have a parameter (like a range or something) to keep the DMLs mutually exclusive.

  • Executing the SQL statement is not allowed - Error

    I am getting "Executing the SQL statement is not allowed" for an INSERT cfquery that I'm running.  I checked the usual suspects:
    - DSN allows INSERT
    - I've seen reports online where certain field names or values are considered key words, so for protection CF blocks the query in this way (it would be nice if there was a different error message when it gets blocked this way vs. the DSN doesn't allow INSERT error message).  The field names and values were all benign strings, so it didn't seem like that.
    I took the same string for the query and ran it on another page and it ran fine (same DSN, too).

    SOLVED: I decided to enter this in here, just to get it into web searches for others since I couldn't find anything.
    - I was calling a function for one of the values in the query:  get_db_status_code("initialize")  Apparently CF parses the query to see if it's allowed BEFORE it runs the CFML in it, so something in that function name, or the parameter "initialize" was a key word that CF doesn't allow.  I moved the function call outside of the query and loaded a temp variable for use in the query and it then worked.

  • How to execute a SELECT statement  in java??

    Hello !!
    In my java program , i need to delete a record of number X, so
    i accept the number X from the keyboard
    Then before deleting it
    i want the program to show me the name, age of the record which has the number X
    How to do this

    hello kylas
    actually i didnt get why this program example?? wats
    its executing ??? Look at reply #3 in your other thread:
    http://forum.java.sun.com/thread.jspa?threadID=713289&messageID=4126346
    Notice the similarity? You've now asked "How to delete a record in Java" and "how to execute a select statement in java". You may have noticed that, aside from the SQL and the call to execute and executeUpdate (for delete) it's the same code. This is because you don't so much do these things in Java, you do them in SQL. The Java code simply asks the Driver to execute whatever SQL you write. So, I really hope your next post isn't "how do I execute an UPDATE statement in Java".
    Good Luck
    Lee

  • Executing multiple DDL statements with OracleCommand

    hi..
    im having trouble executing multiple ddl statements with the the oracle command object. i have tried to enclose them within Begin.. End; block but with no use.
    this problem seems to occur only with DDL statements,.. as my DML like update, delete and Inserts seem to work fine when enclosed within the PL /SQL block.
    single DDL statements also seem to work fine. so im guessing this has nothing to do with priviledges. any ideas?
    my code as follows
    OracleCommand command = new OracleCommand();
    command.CommandType = CommandType.Text;
    command.CommandText = string.Format(@"{0}",script);
    conn.Open();
    command.Connection = conn;
    command.ExecuteNonQuery();
    the script is read from a file, and looks like this. (note : i have removed any line breaks or any other characters)
    BEGIN ALTER TABLE SYSTEMUSER DISABLE CONSTRAINT FK_USER_CLIENT; ALTER TRIGGER SET_SUBSCRIPTION_SUB_I DISABLE; END;
    this is the error i get.
    Oracle.DataAccess.Client.OracleException: ORA-06550: line 1, column 7:
    PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:
    begin case declare exit for goto if loop mod null pragma
    raise return select update while with <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall merge pipe.

    If I'm not mistaken, we're not allowed to issue DDL inside anonymoue block (or stored procedure) since DDL has implicit commit in it. But you still can execute DDL using EXECUTE IMMEDIATE or using DBMS_SQL package. Try changing your CommandText like this,
    BEGIN
       EXECUTE IMMEDIATE 'ALTER TABLE SYSTEMUSER DISABLE CONSTRAINT FK_USER_CLIENT';
       EXECUTE IMMEDIATE 'ALTER TRIGGER SET_SUBSCRIPTION_SUB_I DISABLE';
    END;Hope this helps,
    [Nur Hidayat|http://nur-hidayat.net/]

  • Executing a DDL statement from java code

    Hi all,
    this is code from jdev11.1.1.3 version. I am trying to execute a DDL statement in oracle db from java code, but "ORA-00900: invalid SQL statement" error is coming.
    I am trying to create a table in same schema in same db by using 'Copy' command.
    Same DDL command is executing from sql command prompt & table is being created. Plz help me , as how to do from java?
            public String cmb_action() {
            // Add event code here...
            try {
                //getting source db connection
                InitialContext initialContext = new InitialContext();
                DataSource ds = (DataSource) initialContext.lookup("java:comp/env/jdbc/SourceConnDS");
                Connection sourceconn = ds.getConnection();
                sourceconn.setAutoCommit(false);
                String sql = "Copy from myschema/mypass@DB insert t_dept using select * from dept;"                       
                Statement stat = sourceconn.createStatement();
                stat.executeUpdate(sql);
                sourceconn.commit();
                System.out.println("done");
              catch (Exception ne) {
                // TODO: Add catch code
                ne.printStackTrace();
            return null;
        }

    I have a requirement to transfer data from one db to another db from Java Application Layer.Maybe, maye not. We get all sorts of weird "requirements" - which are nothing but thoughts or proposed solutions.
    But,
    Did the "requirement" mention whether the table existed already or not in the target database? - If not, did it tell you to create it - drop/create it?
    Did the "requirement" deliver some explanation to why this copying was neeeded? - Are we talking replication? - Or a one time cloning?
    Etc, etc,
    Personally I would always argue against a "reuirement" like that. - It just isn't the way to do it. Period.
    Regards
    Peter
    P.S: If you are satisfied with what COPY does, then you could let Java make an OS call and do it from there?

  • Can getGeneratedKeys() be used when executing batches of statements?

    Hi all,
    this question was posted in this thread:
    Can getGeneratedKeys() be used when executing batches of statements?
    but unfortunately I didn't find the answered appropriate.
    That thread is now locked, so I would like to start it again here.
    This is a summary of the other thread:
    Can you retrieve keys generated by a batch of insert statements? The following code produces an ArrayIndexOutOfBoundsException from the Oracle T4CNumberAccessor.unmarshalOneRow() method (see stack trace at the bottom of this message).
    The code is:
    String sql = "INSERT INTO FOO (ID, NAME) VALUES (FOO_SEQ.NEXTVAL, ?)";
    String generatedColumns[] = {"ID"};
    PreparedStatement pstmt = connection.prepareStatement(sql, generatedColumns);
    pstmt.setString(1, "A");
    pstmt.addBatch();
    pstmt.setString(1, "B");
    pstmt.addBatch();
    pstmt.setString(1, "C");
    pstmt.addBatch();
    //EXCEPTION OCCURS HERE
    pstmt.executeBatch();
    The exception is:
    java.lang.ArrayIndexOutOfBoundsException: 22
    at oracle.jdbc.driver.T4CNumberAccessor.unmarshalOneRow(T4CNumberAccessor.java:190)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:610)
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
    at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:955)
    at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10580)
    The only answer given was:
    "You should directly specify how big your batching is. For that reason you may use ExecutionContext where you can set setBatchingLimit(int) and setBatching(bool). This operation will tell execution context the size of supposed batching and also should be batching performed at all or not. You can add batching jobs but you can not execute the jobs without proper initialization of batching job size - it will fail with out of bounds."
    ExecutionContext is not something I found in jdbc drivers, so I'm a bit confused about this answer.
    Did anyone solve the problem?
    Thanks,
    Michele

    >
    We have the same problem. No solution so far.
    >
    I never found a definitive solution but testing seems to show that this is not possible.
    There is no code that can be written to get the generated keys if batching is used.
    This is because the 'getGeneratedKeys' method must be called on the prepared statement and would return the generated keys as a ResultSet object. But when batching there is only one prepared statement but multple sets of parameters, one for each batch entry.
    Thus there could only be one call to 'getGeneratedKeys' since there is only one prepared statement. This strongly implies that it is not possible to use 'getGeneratedKeys' when batching.
    See Retrieval of Auto-Generated Keys in the JDBC Dev guide
    http://docs.oracle.com/cd/B19306_01/java.102/b14355/jdbcvers.htm#CHDEGDHJ

  • How to know which user has executed which ddl statement

    Hi All,
    Last week i faced some problem, like some one has truncated the table , so luckily i have the schema backup so i restored it till the last backup taken.
    but i want to know who has executed this ddl statement.
    i know there are some utilities are avaible with oracle, so please describe me the easiest and quickest way to get this.
    Regards
    Asif

    In order of descending simplicity
    - Use the principle of least privilege to restrict the privileges users have in the database to ensure that they cannot do things like truncating a table
    - Enable auditing of potentially problematic statements. This has to be done before the damage is done, though
    - Create a DDL trigger that logs when users issue DDL. This also must be done before the damage is done.
    - Use LogMiner to go through the archived log files that were generated at the time the table was truncated. This assumes that the database is in ARCHIVELOG mode and that you have the archived logs from last week. Using LogMiner to track down the culprit is also likely to be relatively time-intensive
    Justin

  • Error: Before the statement "FORM", conclude with "ENDFUNCTION

    Hi All,
    I'm using this exit :EXIT_SAPLVEDA_001.
    In this exit include zxvedu03 is used.
    I have written a perform in this include  zxvedu03  :
    perform abc.
    I have written the code
    form abc.
                                             endform.
    in include ZXVEDF01.
    I have called this
    includeZXVEDF01
    in the last line of include zxvedu03.
    Now i'm getting error :
    Incorrect nesting: Before the statement "FORM", the structure 
    introduced by "FUNCTION" must be concluded with "ENDFUNCTION".
    I have even tried to create include from perform statement and then inserted code and vise versa too but results are same.
    Please suggest how can i revolve this error.
    Thanks.

    Hi,
    This is my code of include ZXVEDU03:
    if ( contrl-sndsad in rl_var2 ) or ( contrl-sndsad in rl_var1 ).
    *** Uncommented below perform
      perform contract_determine using contrl-sndsad segment
                                                     dxvbak
                                                     dxvbap
                                                     dxvbadr
                                                     dd_flag_k.
    endif.
    ***statements**
    include zxvedf01.
    Code in includeZXVEDF01 :
    form contract_determine using    p_cntrl_sndsad p_segment type edidd
                                                    p_dxvbak   structure wa_dxvbak
                                                    p_dxvbap   structure wa_dxvbap
                                                    p_dxvbadr  structure wa_dxvbadr
                                                    p_d_flag_k structure wa_d_flag_k.
    *** statements**
    endform.
    Note: Include ZXVEDU03 is in EXIT_SAPLVEDA_001 and ZXVEDF01 is in ZXVEDU03.
    EXIT_SAPLVEDA_001-> ZXVEDU03->ZXVEDF01

  • How to execute multiple sql statements

    hi all
    i am wondering if i can execute multiple sql statements in one shot with >> execute immediate command
    for example:
    i define the variable as X := sql statement
    Y := sql statement
    z := sql statement
    can i do execute immediate (X,Y, Z);
    if yes how ?? and if not any possible alternate
    thanks

    Starting with Ganesh's code
    DECLARE
       l_statement                 VARCHAR2 (2000);
       v_passwd                    VARCHAR2 (200);
       v_username                  VARCHAR2 (200) := 'test';
       v_pwd_key                   VARCHAR2 (200) := 'lwty23';
       v_dblink_name               VARCHAR2 (2000);
       v_dblink_drop               VARCHAR2 (2000);
       v_dblink_create             VARCHAR2 (2000);
       v_dblink_check_connection   VARCHAR2 (2000);
       l_number                    NUMBER;
    BEGIN
       --<<c_instance>>
       FOR c_instance IN (SELECT *
                            FROM v_oracle_instances
                           WHERE environment = 'Developement')
       LOOP
          SELECT encpwd_owner.display_db_encpwd (v_username,
                                                 c_instance.host_name,
                                                 c_instance.instance_name,
                                                 v_pwd_key)
            INTO v_passwd
            FROM DUAL;
          v_dblink_name := c_instance.host_name || '_' || c_instance.instance_name;
          v_dblink_create :=
                ' CREATE DATABASE LINK '
             || v_dblink_name
             || ' CONNECT TO '
             || v_username
             || ' '
             || 'IDENTIFIED BY '
             || v_passwd
             || ' USING'
             || ' ''(DESCRIPTION=
    (ADDRESS=(PROTOCOL=TCP)(HOST= '
             || c_instance.host_name
             || ')(PORT='
             || c_instance.LISTENER_PORT
             || '))(CONNECT_DATA=(SID='
             || c_instance.instance_name
             || ')))''';
          v_dblink_check_connection := 'select 1 from global_name@' || v_dblink_name || '.QCM';    --- Notice this change. I am simply selecting 1. That should be enough to test the database link.
          v_dblink_drop := 'drop database link ' || v_dblink_name || '.QCMTLAF';
          -- l_statement := 'BEGIN ' || v_dblink_create ';' || v_dblink_check_connection ';' || v_dblink_drop '; END ;'
          BEGIN
              EXECUTE IMMEDIATE (v_dblink_create);
              DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Created');
         EXCEPTION
            WHEN others THEN
               dbms_output.put_line( 'Failed to create the database link ' || v_dblink_name  );
               dbms_output.put_line( dbms_utility.format_error_backtrace() );
               INSERT INTO error_table( column_list )
                 VALUES( <<list of values>> );
         END;
          EXECUTE IMMEDIATE (v_dblink_check_connection) INTO l_number;    --- Notice this.
          DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Tested');
          BEGIN
             EXECUTE IMMEDIATE (v_dblink_drop); 
             DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Dropped');
          EXCEPTION
             WHEN others THEN
               dbms_output.put_line( 'Failed to drop the database link ' || v_dblink_name  );
               dbms_output.put_line( dbms_utility.format_error_backtrace() );
               INSERT INTO error_table( column_list )
                 VALUES( <<list of values>> );
         END;
       END LOOP;
    END;But I agree with the point that others have brought up that it really doesn't make sense to create and drop a database link like this.
    Justin

  • How to execute multiple SQL statements thru frontend?

    With SQL Server database, you can execute multiple SQL statements.
    Ex.
    SQLCommand cmd = new SQLCommand();
    cmd.CommandText = "SELECT * FROM EMP; SELECT * FROM DEPT";
    cmd.ExecuteXXX();
    Note that for SQL Server, ";" (semocolon) is used as a separator.
    What separator is required for Oracle ? Or rather, can I execute multiple SQL statements against Oracle database (10g) ?
    (Why I want to do it is a totally diff. subject !)
    Thanks,
    Ami.

    Hello,
    You could use an anonymous PL/SQL block to batch multiple statements.
    If you want to use SELECT statements, you would open a REF CURSOR for each SELECT and return the REF CURSOR to your application. INSERT, UPDATE, and DELETE statements can just be passed as is.
    A simple REF CURSOR example might look like:
    begin
      open :v_refcursor1 for select * from emp;
      open :v_refcursor2 for select * from dept;
    end;Where v_refcursor1 and v_refcursor2 are parameters defined as a REF CURSOR type.
    Hope that helps a bit...
    - Mark

  • 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

  • SQL STATEMENT EXECUTES

    Hi All
    HOw oracle SQL statements executes ? Can anyone explain me for SELECT, INSERT,UPDATE and COMMIT statements works ?
    Regards
    Krishna

    Krishna,
    Search for SQL Statement Execution and see the Flow Chart.
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14220/sqlplsql.htm
    -Anantha

Maybe you are looking for

  • No of Purchase Orders... BW Report

    Hello I have a report in BW which shows number of purchase orders for a particular Purchase Organisation,Purchasing doc. type and Purch. doc. category. Is there any report / transaction in R3 side where I can see the number of purchase orders for the

  • Solaris 10 (5.11) Questions

    I have read many posts that do not seem to relate to my system so I am trying to get answers here. I have several questions regarding root's environment settings, use of LD_LIBRARY_PATH, logging of general errors, and menu configurations. To me there

  • ITunes Accounts - 1 account for multiple iPads?  Best Practices?

    I'm setting up a small deployment of 5 iPads for use in my company.  Could anyone share some tips / best practices as far as iTunes accounts are concerned? We would like to use one iTunes account to activate all of the iPads and set up / link to each

  • Hi Friends, Please help me to understand Why we are using CHARM instead of

    Hi friends, I am working as SAP security consultant. I am fresher and worked in implemetaion project. My question is when i was in implementation project i used CHARM in sol man to create transport request. Now i am working in support and here we are

  • The program used to create this object is acrobat. that program is either not installed or its nor responding?

    The program used to create this object is acrobat. that program is either not installed or its nor responding. to edit this object, install Acrobat or ensure that any dialog boxes in Acrobat are closed. I have just installed acrobat Pro XI . when ins