Conditional Insert

Hi,
Is it possible to do a conditional insert? e.g.
IF :P2_NAME != (SELECT name from hk.appname where name = :P2_NAME) then
INSERT....
END IF;So if the value of :P2_NAME doesn't exist within the table then it will be inserted...its to be an addition to a currently existing APEX process (checks that field values aren't null then enters a record into a different table than hk.appname).
Thanks for any help.
Mike

Dird wrote:
PLS-00405: subquery not allowed in this context As I said:
IF :P6_NEW_PROJ IS NOT NULL THEN
proj := lower(:P6_NEW_PROJ);
ELSE
proj := :P6_PROJECT;
END IF;
insert into hkadm.applic@XXX (appl_name) select proj from dual
where 0 = (select count(*) from hkadm.applic@XXX where appl_name = proj and rownum = 1);SY.

Similar Messages

  • MERGE w/ conditional Insert clause

    Hi--
    Sum Up:Is it possible to run Merge syntax with update and a conditional Insert clauses ?
    Question Details
    Have a base table Emp and staging table New_Emp with a common identifier Emp_id.
    The ideal would be to merge the 2 tables and update Emp using New_Emp values and
    insert only some new emp, not all records.
    Any ideas ? Thks
    Lamine

    Absolutely. See the docs. Use the WHEN and WHERE clauses.
    Tom Best

  • Implementing Conditional Insert

    I use tips in the article "Implementing Conditional Insert, Update, and Delete Allows for View Objects" from "Steve Muench's Radio Weblog".
    At the start all it's ok, but I found this problem:
    1. I have two views (V1 and V2) over the same entity (E1)
    2. V1 permit insert, delete, update, and select.
    3. V2 overwrite method create and don't allow insert.
    4. If you use V1 and try to insert a record all go ok.
    5. If you use V2 and try to insert a record get an exception "It's not allow insert into V2", It's Ok.
    6. If you use V1 again and try to insert a record you get an exception, that say "It's not allow insert into V2".
    I'm investigate the case, and found that when you insert a record in E1 throw V1, the framework (BC4) try to create the record in the views that are instantiated over the entity E1, for this call method "create" on views.
    Do you know some workaround ?
    thank in advice...

    Hi, again, I have question about this...
    I post it in the forum...
    If I use "isAssociationConsistent()" I have to know all views that depend of same entity, and its privileges. I have problem with that because if I add a view a have to remember to put this in the code.
    I need to confirm: is return of method "this.getEntity(0).isInCache()" true when record was inserting in other entity ?
    May I modify your sample like this:
    public class CustomViewRowImpl extends ViewRowImpl {
    protected void create(AttributeList nvp) {
    if ( this.getEntity(0).isInCache() || getVO().isInsertAllowed()) {
    super.create(nvp);
    else {
    throw new JboException("Insert not allowed in this view");
    thank a lot

  • Conditional Insert within Merge???

    can we use conditional insert within the merge statement????
    thanks a lot..
    nantha

    NanthaKumarAR wrote:
    is there is any possible way to do so????
    thanks a alot ....
    nanthaHmmm let's look at the conversation so far...
    You: "is this possible?????"
    Me: "No."
    You: "is there is any possible way to do so????"
    I'm now wondering which part of "No" you failed to understand.
    You cannot perform multiple/conditional inserts within a MERGE statement. The purpose of a MERGE statement is to take data and MERGE it into a single table.
    The only messy way I can think of would be to merge into an intermediate table with triggers on it, that takes the merged data and splits it out into the seperate tables. Messy and not likely the best solution to the initial problem, which would probably be better solved by avoiding the use of MERGE in the first place (though we don't know what problem you are actually trying to solve).

  • Conditionally inserting tiles

    Hello All,
    I am using tiles with JSF. In my jsf page, i have the below logic but still the tiles get inserted...
    <% if(false){ %>
    <tiles:insert definition="NonMember" flush="false"/>
    <% } %>
    I am not sure whats happening.. does anyone know whats happening here...
    Basically,i want to check a condition and if the condition is false, i dont want to insert the tiles..

    Make sure nonMember definition is accessible via the jsp page:
    <f:verbatim>
    <%
    String nonMember = ...
    if(false)
    %>
    <tiles:insert name="<%=nonMember%>" flush="false" />
    <%
    %>
    </f:verbatim>
    Hope this may help.
    BaTien
    DBGROUPS

  • Conditional insert in plsql

    Hi friends,
    I am a beginner in Oracle PLSQL. I need to insert a row into a table based on a condition. The condition is to check if the value is already there in another table.
    i.e, If the username is already present in the users table then the username should not be added to username table. I have written a stored procedure to insert into the username table but need i do not know how to check for the condition.
    Could you please let me know how to get this. I tried a lot but getting compilation errors.
    Regards,
    Padeep

    Use Control Statements
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17126/controlstatements.htm
    Such as: IF-THEN-ELSE or CASE
    That documentation is for 11.2. Your Oracle version may be different, but since IF statements have been around for a long time, this will do.
    Alternatively, consider a unique index on the field.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17120/indexes003.htm#ADMIN11724
    Or even consider using a MERGE statement:
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/statements_9016.htm#SQLRF01606

  • Conditional Insertion in table based on Field

    Hi all,
      I am having 3 text input fields in my page, Empno, Ename, Sal
      After inserting data in the fields, commission column has to be populate automatically, based on conditions.
      Conditions are : If the salary is less than 5000 the commission 500 has to be insert, salary is greater than 5000 commission 1000 has to be inserted.
    how can I achieve this, and where I have to implement the logic, please help me out.
    Thanks in Advance
    Jagadish

    Hi,
    You can apply PPR on salary field. Then catch the event and based on condition, set the value of commission field.
    Also, you can check this link for PPR:
    http://sushantsharmaa.blogspot.in/2012/12/11-ppr-partial-page-rendering-in-oaf.html
    --Sushant

  • Conditional Insert into staging table by using sqlloader

    Hi,
    In Oracle apps I'm submitting a concurrent program programmatically which will call sqlloader and insert into a staging a table.
    This table consists of 30 columns.Program has one input parameter.If parameter value = REQUIRED Then it should insert into first three columns of staging table.If it's APPROVED then it should insert into first 10 columns of the same table.
    Data file is pipe delimited file which may or may not have all possible values :For Required,I many not have all three column values

    >
    I think you understood the thinks wrongly. OP marked UTL_FILE as the correct answer, which is again a server side solution.
    >
    Perhaps you failed to notice that the answer now marked correct was posted AFTER mine. I'm not clairvoyant and OP did not state whether a server side or client side solution was appropriate.
    I stand by my comments. Using an external table is an alternative to sql loader but, as I said, simply using an external table instead of sql loader doesn't address OPs problem.
    >
    And IMO, external table will be faster than UTL_FILE
    >
    I'd be more concerned with why OP wants to write a procedure to parse flat files, deal with data conversion errors and perform table inserts when Oracle already provides that functionality using either external tables or sql loader.
    I would suggest loading the file into a new staging table that can hold all of the columns that might be contained in the flat file. Then the appropriate data can be moved to OPs staging table according to the required business rules.
    Sounds like we each think OP should reconsider the architecture.

  • Conditional insertion into a table

    Hello:
    I've a base table into which records are inserted from results returned by a query. The query always runs on the current date every hour. There are some preconditions before insertion:
    1) The backdated records will remain as it is;
    2) If query finds a new Number it will be inserted in the table;
    3) If query finds a same number but Count is more, it will also inserted in the table.
    TABLE1-
    Number|PDATE|CATEGORY|MARKED|COUNT
    1|29-APR-2012|C1|Y|2
    3|30-APR-2012|C1|Y|1
    4|30-APR-2012|C1|Y|1
    5|30-APR-2012|C1|Y|3
    Query Result-
    Number|TDATE|COUNT
    1|30-APR-2012|1
    2|30-APR-2012|5
    3|30-APR-2012|1
    4|30-APR-2012|9
    5|30-APR-2012|3
    Output: (Updated Table-1)
    Number|PDATE|CATEGORY|MARKED|COUNT
    1|29-APR-2012|C1|Y|2
    1|30-APR-2012|C1|N|1
    2|30-APR-2012|C1|N|5
    3|30-APR-2012|C1|Y|1
    4|30-APR-2012|C1|Y|1
    4|30-APR-2012|C1|N|9
    5|30-APR-2012|C1|Y|3
    Explain Output: The query is running on 30-Apr-2012
    1|29-APR-2012|C1|Y|2: This is a backdated record. So, remained unchanged.
    1|30-APR-2012|C1|N|1: 1 of today was not in the table. So, it is inserted with Status 'N'
    2|30-APR-2012|C1|N|5: 2 of today was not in the table. So, it is inserted with Status 'N'
    3|30-APR-2012|C1|Y|1: 3 is already in the table. So, unchanged.
    4|30-APR-2012|C1|N|9: 4 will be inserted cause count (9) is more than previous (1). So, it is inserted with Status 'N'
    5|30-APR-2012|C1|Y|3: 5 is already in the table. So, unchanged.
    Can anyone help me with query?
    Thanks/Razin

    Hope below helps you
    CREATE TABLE T
    (  NUM      NUMBER,
       PDATE    DATE,
       CATEGORY VARCHAR2(2),
       MARKED   VARCHAR2(1),
       COUNT    NUMBER
    INSERT INTO T VALUES (1,'29-APR-2012','C1','Y',2);
    INSERT INTO T VALUES (3,'30-APR-2012','C1','Y',1);
    INSERT INTO T VALUES (4,'30-APR-2012','C1','Y',1);
    INSERT INTO T VALUES (5,'30-APR-2012','C1','Y',3);
    INSERT INTO T(NUM, PDATE, CATEGORY, MARKED, COUNT )
    WITH QUERY_RESULT AS
    ( SELECT 1 NUM , TO_DATE('30-APR-2012','DD-MON-YYYY') PDATE,1 CNT FROM DUAL UNION ALL
      SELECT 2     , TO_DATE('30-APR-2012','DD-MON-YYYY'),5 FROM DUAL UNION ALL
      SELECT 3     , TO_DATE('30-APR-2012','DD-MON-YYYY'),1 FROM DUAL UNION ALL
      SELECT 4     , TO_DATE('30-APR-2012','DD-MON-YYYY'),9 FROM DUAL UNION ALL
      SELECT 5     , TO_DATE('30-APR-2012','DD-MON-YYYY'),3 FROM DUAL
    SELECT R.NUM, R.PDATE, 'C1','N', R.CNT
    FROM QUERY_RESULT R
    WHERE NOT EXISTS ( SELECT NULL
                       FROM T
                       WHERE R.NUM = T.NUM AND ( R.PDATE < T.PDATE OR (R.PDATE = T.PDATE AND R.CNT <= T.COUNT ))
    SELECT * FROM T
           NUM PDATE     CATEGORY   MARKED          COUNT
             1 29-APR-12 C1         Y                   2
             1 30-APR-12 C1         N                   1
             2 30-APR-12 C1         N                   5
             3 30-APR-12 C1         Y                   1
             4 30-APR-12 C1         Y                   1
             4 30-APR-12 C1         N                   9
             5 30-APR-12 C1         Y                   3
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Implementing Conditional Insert, Update, and Delete Allows for View Objects

    Steve,
    Thanks for the info in this article it was very helpful. I have one question as I created a test case that used dept & emp tables as master and detail.
    Placing code in the emp detail ViewRowImpl that also tests to see if the master is updateable and it all works fine but I noticed that when you run it in the tester the dept master fields are grayed out but not the emp details and if you bring up the emp detail with out the view link then they are grayed out.
    Just wondering is this just a fact of the detail being shown in a table in the master detail and not a form or is there more to it then that??

    yes as follows:
    isMasterUpdateable checks the Dept table to see if it is updateable before allowing emp to be updated.
    public boolean isAttributeUpdateable(int index)
    if ( isMasterUpdateable() == true )
    return ( super.isAttributeUpdateable(index) );
    return(false);
    When I run this in the tester the results are correct except for the visual where the form is grayed out but the detail in the table is not. Should the table gray out also or is this effect something that must be coded in all Jtables that i may implement? If it needs to be coded to get the effect where does Jtable check for isAttributeUpdateable ?
    thanks,

  • How to insert some records in one table and some records in another table

    Interview question
    how insert records in two tables by using trigger
    CREATE or REPLACE TRIGGER Emp_Ins_Upd_Del_Trig
    BEFORE delete or insert or update on EMP
    FOR EACH ROW
    BEGIN
    if UPDATING then
    UPDATE emp2
    SET
    empno = :new.empno,
    ename = :new.ename
    --, job = :new.job
    --, mgr = :new.mgr
    --, hiredate = :new.hiredate
    , sal = :new.sal
    --, comm = :new.comm
    --, deptno = :new.deptno;
    sdate = :new.sdate,
    edate = :new.edate
    end if;
    if INSERTING then
    INSERT INTO emp2
    VALUES
    ( :new.empno
    , :new.ename
    --, :new.job
    --, :new.mgr
    --, :new.hiredate
    , :new.sal
    --, :new.comm
    --, :new.deptno
    new.sdate,
    new.edate);
    end if;
    if DELETING then
    DELETE FROM emp2
    WHERE empno = emp2.empno;
    end if;
    END;
    it is working fine but he wants to insert some specific litimit on one table and some specified limit of records in one ..
    In this senerio can i insert records by use count of records...
    please help me..

    Can you be more specific on the "Limit"
    Conditional insert can be used in this case.

  • Use of insert in case

    Hi,
    Is it possible to use insert statement in CASE.
    For example as follows:
    let create a table as
    create table DECOMPENSATED_BALANCE_TMP (ENDING_ENTERED_BALANCE_DR number, ENDING_ENTERED_BALANCE_CR number);
    select
    CASE
    WHEN (PERIOD_NET_DR+BEGIN_BALANCE_DR-PERIOD_NET_CR-BEGIN_BALANCE_CR) total > 0
    THEN
    INSERT INTO XXGL_DECOMPENSATED_BALANCE_TMP (ENDING_ENTERED_BALANCE_DR) values (total)
    WHEN (PERIOD_NET_DR+BEGIN_BALANCE_DR-PERIOD_NET_CR-BEGIN_BALANCE_CR) <= 0
    THEN
    INSERT INTO XXGL_DECOMPENSATED_BALANCE_TMP (ENDING_ENTERED_BALANCE_CR) values (total)
    else
    NULL
    end
    from gl_balances
    where code_combination_id=109940 and currency_code='GBP';
    Any answers will be highly appreciated ....
    Thanks,
    zaheer

    I don't think that a conditional insert is really needed in this case. THe only part where the insert differse is the else part of your case statment where no insert should be done. THis can be made into a where clause.
    An easy way would be to use a simple INSERT + SELECT statement. Where the value for the dr and cr columns are created by a case or a decode statement.
    untested example
    insert into XXGL_DECOMPENSATED_BALANCE_TMP
      (ENDING_ENTERED_BALANCE_DR, ENDING_ENTERED_BALANCE_CR)
    select case WHEN (PERIOD_NET_DR+BEGIN_BALANCE_DR-PERIOD_NET_CR-BEGIN_BALANCE_CR) > 0  then total
              else null
              end as DR
             ,case WHEN (PERIOD_NET_DR+BEGIN_BALANCE_DR-PERIOD_NET_CR-BEGIN_BALANCE_CR) <= 0  then total
              else null
              end as CR
    from gl_balances
    where code_combination_id=109940
    and currency_code='GBP'
    and (PERIOD_NET_DR+BEGIN_BALANCE_DR-PERIOD_NET_CR-BEGIN_BALANCE_CR) is not null -- else part
    ;The good thing is you could run this insert statement for several code_combination_ids directly in SQL without any pL-loop.
    Just noticed that leonard aready posted almost the same solution.
    Edited by: Sven W. on Aug 24, 2011 3:22 PM

  • Maintain Excise defaults for pricing condition in TAXINN procedure

    Hi all,
    I post this message as I'm customizing CIN part for creation and calculation of excise invoice. I have read lot of post but i'm a bit confused about right procedure to adopt. I try to explain:
    I'm doing a stardard sales flow (sales order -> delivery -> commercial invoice -> excise invoice) and the only method I have found to flow excise values in excise invoice is to insert pricing conditions in India -> Basic settings -> Determination of excise duty -> Maintain excise defaults for TAXINN procedure.
    In this table I have insert pricing conditions I use in my SD pricing schemas (in this case I use a copy of JINFAC). I have insert pricing conditions corresponding to BED % and BED total, and also CESS % and total and S&HCESS % and total.
    If I remove pricing condition from this table, corresponing value in excise invoice, when I create it, become 0.
    My dubt is if is correct to populate with table to flow excise values in excise invoice. I ask it as I have read differents approach and differents customizing settings applied in similar situations. In particular, I have found documentation in which, for TAXINN procedure, is recommended to leave blank "excise defaults" (with exception of CVD condition). What is the right method to use?
    There is one right procedure or, as it seems reading posts, someone have to do his "proper CIN customizing" based on results that have to obtain?
    Thanks in advance for any contribute that can help to clarify this situation.
    Regards
    Gianpaolo

    Hi all,
    I think to have found solution to my dubt.
    If I use "condition based Excise determination" I have to insert records with pricing schema (if is a copy of standard J* schema, like ZINFAC that is a copy of JINFAC) and excise pricing conditions in the transaction below:
    India -> Basic settings -> Determination of excise duty -> Condition-based Excise determination -> Classify condition type
    To determine value in excise invoice seems that program check before table in transaction described before. If in this table don't find records for pricing schema-excise pricing condition the program check also table in transaction below:
    India -> Basic settings -> Determination of excise duty -> Maintain excise defaults
    If during this second check find excise pricing conditions insert, can determine equally the values of excise in excise invoice.
    This is the result of my checks. I hope this could be useful for other people with similar problem.

  • How to insert variable value using select statement - Oracle function

    Hi,
    I have a function which inserts record on basis of some condition
    INSERT INTO Case
    Case_ID,
    Case_Status,
    Closure_Code,
    Closure_Date
    SELECT newCaseID,
    caseStatus,
    Closure_Code,
    Closure_Date,
    FROM Case
    WHERE Case_ID = caseID
    Now i want new casestatus value in place of select statement caseStatus value. I have a variable m_caseStatus and i want to use the value of this variable in above select statement.
    how can i use this.
    thanks

    Hi,
    I have a function which inserts record on basis of some condition
    INSERT INTO Case
    Case_ID,
    Case_Status,
    Closure_Code,
    Closure_Date
    SELECT newCaseID,
    caseStatus,
    Closure_Code,
    Closure_Date,
    FROM Case
    WHERE Case_ID = caseID
    Now i want new casestatus value in place of select statement caseStatus value. I have a variable m_caseStatus and i want to use the value of this variable in above select statement.
    how can i use this. Do not select Case_Status from inner select, so null will be inserted then after inserting it update the case status with m_caseStatus.
    Regards.

  • Reduce the execution time of a insert

    Hello,
    I have a table called LINK_TABLE that contains a field called LINK_ID that identify with an ID the links of a network and other two fields called START_NODE_ID and END_NODE_ID that contains the ID of the start node and the ID of the end node for each link. This table has 7 Millions of record.
    Then I have a table called NODE_TABLE that contains a field called NODE_ID that identify the all nodes of the network (i.e. all the START_NODE_ID and END_NODE_ID without duplicates ). This table has 6 Millions of record
    Now, I created a new table of links called LINK_TABLE2 that derive from the LINK_TABLE with these conditions:
    INSERT INTO LINK_TABLE$ USING SELECT * FROM ITALIA_LINK$ WHERE (FRC>=0 AND FRC<=6) AND FEATTYP<>4130;The table LINK_TABLE has now 3 Millions of record.
    NODE_TABLE2 must have only the NODE_ID that are the START_NODE_ID and END_NODE_ID of the table LINK_TABLE2 ( without duplicates ). So, I'm doing this insert:
    INSERT INTO NODE_TABLE2 USING SELECT * FROM NODE_TABLE n WHERE (n.node_id IN (SELECT start_node_id FROM LINK_TABLE2) OR n.node_id IN (SELECT end_node_id FROM LINK_TABLE2));but this second insert is working from about 15 hours.
    I have 4GB RAM (oracle is using it for 30%), Quad core of CPU (oracle is using it for 100%).
    Is it possible?
    Is there a fast method for do this?
    Thank you very much in advance.

    example:
    LINK_TABLE
    LINK_ID: 50, 51, 52
    START_NODE_ID: 10, 11, 12
    END_NODE_ID: 20, 21, 22
    where:
    10 and 20 are the start point and the end point of the link (or street) 50;
    11 and 21 are the start point and the end point of the link (or street) 51;
    12 and 22 are the start point and the end point of the link (or street) 52;
    NODE_TABLE
    NODE_ID: 10, 11, 12, 20, 21, 22
    LINK_TABLE2
    LINK_ID: 50, 52
    START_NODE_ID: 10, 12
    END_NODE_ID: 20, 22
    now, NODE_TABLE2 must have only:
    NODE_TABLE2
    NODE_ID: 10, 12, 20, 22.
    Is it clear?
    thank you very much.

Maybe you are looking for

  • How to set an alerting substitution for another user as admin?

    Dear experts, having the case on of our employees went on vaction without entering a substitution for his alerts. How can I as an administrator setup a substitution for the alerts of this user? Thanks in advance, BR Matthias

  • Regarding MCBA character selection.

    Hi, When I am performing transaction MCBA and selecting all the characteristics like Plant, Storage location, MAterial, Month, Valuation class, MRP controller, etc. When executing the report the output is delivered. But while downloading it via XXL t

  • Processing 30 MB+ file in BPEL

    I have a requirement where I need to read a simple CSV file having size 30 MB+ in BPEL. Currently I am not able to read anything above 6 MB size. Even after using incremental read the process is taking more than 30 mins to read the file and pump it's

  • IBooks file problems

    I am having problems with a collection of exported ibooks that have all originated from one template. When exporting the ibooks into the ibooks application only one file from that collection is visible. When I try to import one of the files in again

  • Use Publisher as primary IPMA Server

    Dear Expert, I would like to khnow if the fact of using my publisher (on a cluster of three nodes) as a primary IPMA server is a deviation of the best practice of Cisco or it can implémented without any issue. Thank you in advance. Nizar Houichi