Error in inserting a record in to table

hi..
i created a trigger....when i am trying to insert new record in to table i am getting the fallowing error...plz kindly help me out from this...
SQL> create or replace trigger secure_emp
2 before insert on employees begin
3 if(to_char('sysdate','DY') in ('SAT','SUN')) or
4 (to_char('sysdate','HH24:MI') not between '8:00' and '18:00') then
5 raise_application_error(-20500,'error');
6 end if;
7 end;
8 /
Trigger created.
SQL> insert into employees(employee_id,last_name,first_name,email,hire_date,job_id,salary,department
_id)
2 values (300,'smith','jack','SJACK',sysdate,'IT_PROG',4500,60);
insert into employees(employee_id,last_name,first_name,email,hire_date,job_id,salary,department_id)
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at "SCOTT.SECURE_EMP", line 2
ORA-04088: error during execution of trigger 'SCOTT.SECURE_EMP'

Yeah. Whenever Oracle sees TO_CHAR('string_literal1', 'string_literal2), it implicitly converts it to TO_CHAR(TO_NUMBER('string_literal1'), 'string_literal2). That's why an error in trigger occurs.
SQL> explain plan for
  2  select null
  3    from dual
  4   where dummy = to_char('A', 'DY');
Explained
SQL> @utlxpls
Cannot SET MARKUP
PLAN_TABLE_OUTPUT
Plan hash value: 397561404
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT  |      |     1 |     2 |     2   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     2   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   1 - filter("DUMMY"=TO_CHAR(TO_NUMBER('A'),'DY'))
13 rows selected

Similar Messages

  • Insert multiple records into a table(Oracle 9i) from a single PHP statement

    How can I insert multiple records into a table(Oracle 9i) from a single PHP statement?
    From what all I've found, the statement below would work if I were using MySQL:
         insert into scen
         (indx,share,expire,pitch,curve,surface,call)
         values
         (81202, 28, 171, .27, 0, 0, 'C' ),
         (81204, 28, 501, .25, 0, 0, 'C' ),
         (81203, 17, 35, .222, 0, 0, 'C' ),
         (81202, 28, 171, .27, 2, 0, 'C' ),
         (81204, 28, 501, .20, 0, 1, 'C' ),
         (81203, 28, 135, .22, 1, 0, 'C' )
    The amount of records varies into the multiple-dozens. My aim is to utilize the power of Oracle while avoiding the i/o of dozens of single-record inserts.
    Thank you,
    Will

    You could look at the INSERT ALL statement found in the documentation here:
    http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_913a.htm#2133161
    My personal opinion is that you probably won't see any benefit because under the hood I think Oracle will still be doing single row inserts. I could be wrong though.
    The only way to confirm was if you did a test of multiple inserts vs an INSERT ALL, that is if the INSERT ALL met your requirements.
    HTH.

  • Abort inserting a record in a table using a trigger

    Hi there,
    Is there any way to abort inserting a record in a table using a trigger?
    For full details, I have the following table ("myTable"):
    BSC INTEGER NOT NULL,
    BTS VARCHAR2(20) NOT NULL,
    INFO1 INTEGER,
    INFO2 INTEGER
    myTable_PK = PRIMARY KEY (BSC,BTS)
    I have also a stored procedure that imports a data from text file and inserts them to the specified table (using UTL_FILE package). The stored procedure works great.
    But the thing that in the text file itselft it might be (due to third-parity report generation bug) that the primary key will be violated or the BSC/BTS field has null value. In such case I just want to ignore the insertion statement using a trigger.
    Thanks

    Ok Jens, could you tell me what exception could I use?
    Below a protion of my StoredProcedure.
    CREATE OR REPLACE PROCEDURE update_myTable() IS
    FHANDLE UTL_FILE.FILE_TYPE;
    BSC INTEGER;
    BTS VARCHAR2(20);
    INFO1 INTEGER;
    INFO2 INTEGER;
    BEGIN
    FHANDLE := UTL_FILE.FOPEN('LOG_FILE_DIR',FILENAME,'R',4000);
    LOOP
    UTL_FILE.GET_LINE(FHANDLE,STR);
    -- Process the line STR and generates BSC, BTS, INFO1, and INFO2 values
    EXECUTE IMMEDIATE 'INSERT INTO myTable VALUES(:1,:2,:3,:4)' USING BSC,BTS,INFO1,INFO2;
    END LOOP;
    EXCEPTION WHEN NO_DATA_FOUND THEN UTL_FILE.FCLOSE(FHANDLE);
    END UPDATE_R205BTS;
    Remember that I am already using an exception with NO_DATA_FOUND to indicate the end of file then closing it.
    Thanks for your reply

  • Triggers to insert the record in a table

    I have two table 1. Holiday 2. Attendance.
    When I insert the record    in holiday table for his
     advance holiday   with empid, the same time I want to insert it attendance table
     automatically for the same date using a trigger
    Insert into attendance (empid,date,holiday) values (20078,07/10/2014,1). If holiday column value 1 represent holiday marked,
     0 represent  holiday not marked. The same thing can happen vice versa
    If employee mark his current attendance as  holiday through attendance,
     it should   be  inserted into holiday table 
    automatically using triggers.
    Insert into  Holiday (empid,date,holiday) values (20078,06/08/2014,1). If holiday column value 1 represent holiday marked,
     0 represent  holiday not marked. The same thing can happen vice versa
    Please I am looking for your help , how I can make it using triggers 
    to insert both table  in two different ways of options.
    Regards
    Pol
    polachan

    Hi polachan,
    According to your description, if you want to synchronize the data between the holiday table and the attendance table while inserting records into holiday table, you need to create a trigger on the holiday table, please try the following syntax.
    use <databasename>
    go
    create trigger Tr_holiday
    on holiday
    for insert
    as
    declare @empid varchar(20),
    @date datetime,
    @holiday int
    select @empid = empid, @date=date, @holiday=holiday from inserted
    declare @qty int
    select @qty =count(*) from attendance where empid=@empid and date=@date and holiday=@holiday
    if @qty<1
    begin
    insert into attendance
    select i.empid,
    i.date,
    i.holiday
    from inserted i
    end
    Meanwhile, if you want to insert the record into the holiday table when holiday is updated to 1 in the attendance table, you need to create another trigger on the attendance table, please try the following syntax.
    use <databasename>
    go
    create trigger Tr_attendance
    on attendance
    for update
    as
    declare @holiday int
    if update (holiday)
    begin
    select @holiday=holiday from inserted
    if @holiday=1
    begin
    insert into dbo.holiday
    select empid,
    date,
    holiday
    from inserted
    end
    end
    For more details about creating triggers in SQL Server, please review this article:
    CREATE TRIGGER (Transact-SQL).
    Thanks,
    Lydia Zhang

  • How to insert a record in ROOSPRMSC table? (accidentally deleted)

    Calling an InfoPackage in BW causes short dump, while fixing the short dump issue, accidentally
    deleted the "ROOSPRMSC" table entries.
    Could you tell me how to insert a record in "ROOSPRMSC" table???

    Hi Senthil,
    Regards,
    Phani Raj Kallur
    Message was edited by: Phani Raj Kallur

  • Inserting Multiple Records into two table

    I want to insert records from a ADF swing form into two tables. In the first table the primary key is generated by a trigger and then I need to retrieve the primary id generated and then insert multiple records in another table using the primarykey obtained from the first table as foreign key.
    How to do this ?

    User,
    If you're using ADF Business components, have a read on the DBSequence data type. If you have two VO's linked by a view link, and the FK is a DBSequence type, all this happens for you out-of-the-box.
    Hope this helps,
    john

  • Inserting new records into database table at runtime

    Hi all ,
    How to insert new records into database table at runtime on click update?
    Thanks.

    Hi Sasikala,
    Just for your understanding am giving a sample code snippet which you can use to read the contents of your Table UI element & save the data on to your database. Suppose you have a button up on pressing which you want to read the data from your screens table & save on to the database then you can proceed as shown below:
    1) Obtain the reference of your context node.
    2) Fetch all the data present in your table into an internal table using methods of if_wd_context_node
    3) Use your normal ABAP logic to update the database table with the data from your internal table
    In my example I have a node by name SFLIGHT_NODE and under this I have the desired attributes from SFLIGHT. Am displaying these in an editable table & the user would press up on a push button after making the necessary changes to the tables data. I would then need to obtain the tables information & save on to the database.
    data: node_sflight           type ref to if_wd_context_node,
            elem_sflight           type ref to if_wd_context_element,
            lt_elements            type WDR_CONTEXT_ELEMENT_SET,
           stru_sflight           type if_main=>element_sflight_node,
           it_flights             type if_main=>elements_sflight_node.
    "   navigate from <CONTEXT> to <SFLIGHT_NODE> via lead selection
        node_sflight_node = wd_context->get_child_node( name = 'SFLIGHT_NODE'  ).
       lt_elements = node_sflight->get_elements( ).
    "   Get all the rows from the table for saving on to the database
        loop at lt_elements into elem_sflight.
          elem_sflight->get_static_attributes( importing static_attributes = stru_sflight ).
          append stru_sflight to it_flights.
        endloop.
    " Finally save the entries on to the database
        modify ZSFLIGHT99 from table it_flights.
        if sy-subrc eq 0.
    endif.
    However a word of caution here.... SAP doesn't ever recommend directly modifying the database through an SQL query. You would preferably make use of a BAPI for the same. Try go through Thomas Jung's comments in [here|modify the data base table which is comming dynamiclly;.
    Regards,
    Uday

  • Getting error while inserting a row in a table

    Hi,
    The following error occurs when one of my enduser is trying to enter record into a table
    <b>Error: Insertion of Infotype 1032 (return code 3) </b>
    There are no records in the table at all.. what could be the reason and why the error occurs?
    Thanks in advance
    Regards,
    Suresh

    Hello Suresh,
    in which table... did you get a dump?
    What is the ORA-error? Is a trace or an alert.log entry generated?
    Your information is insufficient to solve the problem
    Regards
    Stefan

  • Unable to insert a record in any table

    Hi,
    I was working on a procedure in which i had to insert 1,00,000 records each in 3 tables. But the procedure stopped after inserting 56000 records.
    After that I again ran the query but now it is not inserting a single record.
    I just created a dummy table
    create table vinod1(no number);
    and tried to insert a value in it using
    insert into vinod1 values(100);
    But to my surpries the query has been executing since last 10 and has not inserted a row.
    I tried it on SQLPLUS also and i am using oracle 10g
    Can you please help me and explain why i am not able to insert even though I am able to create table.
    Thanks
    -Vinod

    965358 wrote:
    The problem is In the new created table I am not able to insert records. The session keeps on executing forever.
    Also I am using Plsql developer and in that if I see in tools-> session -> active session
    for my session under event the message is 'statement suspended wait error to be cleared'
    Edited by: 965358 on Dec 24, 2012 6:30 AMyou have a mystery & we have no clues.
    How can we reproduce what you report?
    How do I ask a question on the forums?
    SQL and PL/SQL FAQ

  • Inserting Multiple Records in Transparent Table

    Hi Friends,
    I am New to ABAP and Previously i was in Web Dynpro Java....
    I am doing an scenario Travel Request.
    The Problem i am facing i this scenario is inserting the data in the table. I have to maintain a custom table in which Travel request No (Primary Key), Employee No (Primary Key) and Transport Details.....etc.are maitained...
    Employee Number  -
    Travel Request No--Place From-Place To       
    70043 -
    817--Chicago--
    Miami
    70043 -
    817--Miami--
    Chicago
    I have to maintain table like this
    Whenever i inseted the data into the Tranparent Table its showing dump and sy-subrc count is 4
    Plz provide suggestion to achieve this........Thanks in Advance
    Regards
    Chandran S

    In ur case u r trying to enter duplicate values that's why u r getting error.
    In ur custom table, Employee Number  and Travel Request No are 2 primary keys. That means for each record content of these fields should be unique but in ur case they are same. If u really need to maintain data in this way then u have to make another field as key field so that it can uniquely identify a record.
    Employee Number Travel Request No Place From Place To
    70043 817 Chicago Miami
    70043 817 Miami Chicago
    Regards,
    Joy.

  • Do Data Found Error on Inserting a Record

    I am working in Apex 4.0.
    I'm getting this error when I click the "Create" button to insert a record.
    ORA-01403: no data found
         Error      Unable to fetch row.
    Since I'm inserting rather than fetching, why would I get this error? What do I need to do to suppress it?

    Arie, thanks for the response. I suspected the automatic Row Processing might be the problem. But I did not (and still don't) know how to fix it.
    Here's what's happening. The page involved is part of an insurance tracking system. At the time of annual renewal of a policy, we create a new record for the next year. This is done by including in the new record all usuable data fields from the old expiring record. I use a button to navigate to the current page (page 22 to page 22) and set values (from the old page 22) of items in the new page 22. The user then makes a couple of manual entries and then clicks the "Create" button which appears on the new page 22 since the primary key is null. The new record is then correctly inserted into the table, and the system branches back to a calling page. It is at this time that the error occurs.
    ORA-01403: no data found
    Error Unable to fetch row.
    A database trigger gets the new primary key from a sequence generator and puts it into the record on insert. Here's the SQL on the trigger:
    CREATE OR REPLACE TRIGGER "UCC_AUTO_SEQ"
    BEFORE
    insert on "UCC"
    for each row
    begin
    select ucc_seq.nextval
    into :new.uccseq
    from dual;
    end;
    May be that I can fix this if you will explain to me what you mean by this: "My guess is that your page includes an ARF process and you didn’t set the return key item, or you didn’t use the RETURNING clause, so the ARF process can’t fetch the newly inserted record." Forgive my ignorance, but I do not know what a "RETURNING clause" is. I checked out the Source: Automatic Row Processing (DML) and found that the item labeled "Return Key Into Item" was blank. I put "P22_INSURESEQ" (the primary key item) into this field, but the error is still being thrown. The "Action Processed" message always appears in its own window just above the error message.

  • 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.

  • Error when inserting a Record Form

    Hi,
    I'm very green with web development and am just trying my hand at PHP. I've set up a database with Mysql and phpmyadmin  those are working fine.
    I had inserted a record form using the record insertion form wizard and it worked just fine. I deleted it because I wanted some different information and
    now every time I try to insert a new form this error message comes up.
    While executing onClick in ServerObject-InsRecPHP.htm, the following JavaScript error(s) occurred:
    At line 5694 of file 'C:\Program Files (x86)Adobe\Adobe Dreamweaver CS5\Configuration\Shared\Common\Scripts\dwscriptsExtData.js':this.node has no
    properties.
    I've gone to look at the file but I'm not sure how to tell if the properties are working or not. I've also googled this problem but haven't found someone with exactly my dilemma. Any help will be greatly appreciated!
    Thank you for your time

    Troubleshooting JavaScript errors in Dreamweaver
    http://kb2.adobe.com/cps/405/kb405604.html
    Try #4 and #12 first.

  • Script for inserting 1000 record in a table...

    Hello Gurus,
    I have a table structure like this....
    USERID     USERNAME     USERPWD     EMAILID     FIRSTNAME     LASTNAME     ISACTIVE
    1     superuser     Pyramid123      [email protected] a b      1
    21     neha     Pyramid123     [email protected] s     s     1
    I need to write a script where i can insert 1000 dummy related records into this table..
    your help would be appreciated..
    Thanks,
    HP

    Hi,
    Hope the below solves your problem.
    SQL> CREATE TABLE t (USERID NUMBER,
      2                  USERNAME VARCHAR2(20),
      3                  USERPWD VARCHAR2(10),
      4                  EMAILID VARCHAR2(20),
      5                  FIRSTNAME VARCHAR2(10),
      6                  LASTNAME VARCHAR2(10),
      7                  ISACTIVE NUMBER);
    Table created
    SQL> INSERT INTO t
      2    SELECT srl,
      3           name,
      4           pwd,
      5           LOWER(SUBSTR(name, 1, 10)) || '@abc.com',
      6           SUBSTR(name, 1, 10),
      7           SUBSTR(name, 11, 20),
      8           1
      9      FROM (
    10    SELECT level srl,
    11           dbms_random.string('U', 20) name,
    12           dbms_random.string('A', 10) pwd
    13      FROM DUAL
    14   CONNECT BY LEVEL <= 1000);
    1000 rows inserted
    SQL> commit;
    Commit complete
    SQL> select count(1) from t;
      COUNT(1)
          1000
    SQL> select * from t where rownum < 10;
        USERID USERNAME             USERPWD    EMAILID              FIRSTNAME  LASTNAME     ISACTIVE
           342 JLMPNCRYRZYLEGVVKLQT ypsFEvtYOg [email protected]   JLMPNCRYRZ YLEGVVKLQT          1
           343 UINEJWHGFHCBOUXWQWEL OSBmpXSSDp [email protected]   UINEJWHGFH CBOUXWQWEL          1
           344 TLGFDHHLMACMMENWRMZG RIrPTdotaX [email protected]   TLGFDHHLMA CMMENWRMZG          1
           345 QARLMGJVFJXTJRQUFRFU lkbvEGACDi [email protected]   QARLMGJVFJ XTJRQUFRFU          1
           346 TYMDMPTWASFOGIYZYBZP SadCSlHiZc [email protected]   TYMDMPTWAS FOGIYZYBZP          1
           347 XDTRMJICNQNKFMDRRMZB lSchkFigpz [email protected]   XDTRMJICNQ NKFMDRRMZB          1
           348 DQZUKSXOLMQLMFBMEGNI psBCKgLVPP [email protected]   DQZUKSXOLM QLMFBMEGNI          1
           349 JMTNKXDDAPDHYLHUVSWF WXYrBQNKJk [email protected]   JMTNKXDDAP DHYLHUVSWF          1
           350 ZHAFZAJPJCBHNLTCQWTB rhtoGTpBle [email protected]   ZHAFZAJPJC BHNLTCQWTB          1
    9 rows selected
    Regards
    Ameya

  • Insertion a record in a table having columns of different charsets using OLEDB

    My development environment -
    Database -> Microsoft SQL Server
    2008 R2
    OS -> Windows Server
    2008 R2
    Database Charset -> Chinese_PRC_CI_AS (Windows
    936)
    Operating System Charset -> Chinese
    Below table is having varchar fields with different charsets.
    create
    table dbo.tcolcs1 (
        c1 int
    not
    null
    primary
    key,
        c2 varchar(30)
    collate SQL_Latin1_General_Cp1_CI_AS ,
        c3 varchar(30)
    collate Chinese_PRC_CI_AS
    I want to insert below record using OLEDB APIs provided by Microsoft. Just for information, character '0x00C4' does not
    belong to Windows 936 codepage.
    insert
    into dbo.tcolcs1
    values (10,
    NCHAR(0x00C4), NCHAR(0x4EBC))
    Code snippet -
    DBPARAMBINDINFO bind_info
    memset(&bind_info,
    0, sizeof(DBPARAMBINDINFO));
    bind_info.pwszDataSourceType = L"DBTYPE_VARCHAR";
    bind_info.wType = DBTYPE_STR;
    I have bound the varchar field with DBTYPE_STR. I can see that my code is not inserting Latin1 character (0x00C4) correctly
    into the table. The code always inserts a blank character into Latin1 column (c2) and 0x4EBC into Chinese column (c3).
    Later, I changed the binding from DBTYPE_STR to DBTYPE_BYTES as below -
    bind_info.pwszDataSourceType = L"DBTYPE_BINARY";
    bind_info.ulParamSize =
    0;              
    bind_info.wType = DBTYPE_BYTES;
    With the above change, I observed that OLEDB is converting hex value to string. It is inserting 0x00C4 as 'C4' and 0x4EBC
    as '4EBC'. I also tried with adding 'AutoTranslate=no' in driver connection string, but it did not help. How can I insert above record with OLEDB in the above table ?
    Thanks in advance.

    Did you try making fields as unicode?
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

Maybe you are looking for