Insert a single space into a NOT NULL column defined as CHAR(1)

Hi,
I am trying to run a C program in which I am inserting a space character into a database table, where the column has been defined as CHAR(1) NOT NULL.
I am initialising a variable defined in C as: char, with a blank but after running the insert statement I get an error: ORA-01400: cannot insert NULL into �. .
create table nullTest ( col1 char(1) NOT NULL );
Sample code:
EXEC SQL BEGIN DECLARE SECTION;
char dbo_cValue;
EXEC SQL END DECLARE SECTION;
dbo_cValue = � �;
EXEC SQL
INSERT
INTO nullTest
col1
VALUES
:dbo_cValue
My options are: char_map=charz, code=ANSI_C, mode=ANSI.
I understand that if I was using char_map = VARCHA2, on input - if the input value contains nothing but blanks Oracle treats it like a null, but I am not using VARCHAR2 option, but CHARZ.
I tried STRING and other options and I cannot get this to work.
Is there a way where I can insert a space character into a table (using a C program), which has a constraint of �not null� while using C type variables?
I would appreciated any help on this.
Thank you.

Since you did not post a sample of the code that produces an error, its hard to speculate what might be wrong with it.
But, the following sample works, and successfully inserts a space into the table.
#include <sys/types.h>
#include <stdio.h>
EXEC SQL INCLUDE SQLCA ;
EXEC SQL BEGIN DECLARE SECTION ;
        VARCHAR col[10] ;
        char * uid ;
EXEC SQL END DECLARE SECTION ;
int main(void)
        uid = (char *)"/" ;
        EXEC SQL connect :uid ;
        printf("Connected to Oracle!\n") ;
        strcpy(col.arr, " ") ;
        col.len = strlen(col.arr) ;
        EXEC SQL insert into ins_null values (:col) ;
        EXEC SQL COMMIT WORK RELEASE ;
}And, here is the table definition, and a select after running the above program once.
SQL> create table ins_null(col varchar2(10) not null) ;
Table created.
SQL> select ':'||col||':' from ins_null ;
':'||COL||':
1 row selected.
SQL>

Similar Messages

  • Inserting blanks into a NOT NULL CHAR column

    How do you insert a value of blank/spaces into a NOT NULL CHAR column. Oracle 9i interprets the space as a NULL and the insert fails because the column does not allow NULLS. Thanks in advance.

    Hi,
    19:07:13 topgun>create table t1(c1 varchar2(10) not null);
    Table created.
    19:07:33 topgun>insert into t1 values (' ');
    1 row created.
    19:07:42 topgun>select * from t1;
    C1
    19:07:46 topgun>select count(*) from t1;
      COUNT(*)
             1
    19:07:53 topgun>select * from V$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for Linux: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production- Pavan Kumar N

  • Oracle BPEL - Does not cater for not null columns and use of "default".

    Oracle BPEL - Does not cater for not null columns and use of "default".
    BPEL fails with message:
    ORA-01400: cannot insert NULL into ("EDDB"."SEISMIC_LINES"."COORD_SYSTEM_ID")
    But SQL*PLUS command works:
    INSERT into EDDB.SEISMIC_LINES
    (etc)
    regards
    Allan Ford
    Analyst / Programmer - IT Application Services, IT Services, Shared Business Services
    Santos Ltd
    Level 4, 91 King William Street, Adelaide SA 5000
    Phone: 08 8224 7944 Fax: 08 8218 5320
    Email: [email protected]

    note: BPEL keeps it's own "offline" copy of table and database items. A column that is marked not null in the database can be marked as nullable in this area. (if you kmow that a trigger is going to cater for this ..)
    One workaround is to use a trigger to provide value rather than use the column default ..

  • ORA-01400 - not null column with default value and item with authorization

    I've searched - I would think someone has run into this. APEX 3.0.0.00.20 - I've created a simple form on a table. One of the column is a not null column with a default value. I have a select list on that item, but it has security on it - authorization scheme. So, it checks the user and if that user isn't of the right role, it will not even display that item. However, APEX appears to still send in the column in its sql! So, the default value is useless, it sends in null each time. Even if I set the default at the Item level, I get null. Argg. That's got to be a bug...
    In debug, I do not see the item listed at all. It's not used. That's fine - but why is it trying to insert the value? I would think it would leave it off??? I think because the item is associated with a database column. But, getting around this is ugly. Having to create a hidden item for each one, and then check to see if I need to take the list value... horrible. Any way to get around this???

    I should add - I guess I can always put my own custom process in to replace the DML. Just seems like a simple thing - if the value doesn't appear on the debug, isn't set with any default value... don't include it in the DML.

  • Script to add not null columns to all tables in database

    Hello,
    I need to add 5 not null columns to my existing database (all tables).
    The problem is that i do not want to loose the current data.
    I need a script so that i need not do this manually for each table.
    Can u suggest?
    Vishal

    Hello,
    I need to add 5 not null columns to my existing database (all tables).
    The problem is that i do not want to loose the current data.
    I need a script so that i need not do this manually for each table.
    Can u suggest?
    Vishal I always follow this step
    1) Alter table <<tablename>> add(<<columnname>> <<datatype>>)
    2) Update <<tablename>> set <<columnname>>=<<anyvalue>>
    3) Alter table <<tablename>> modify(<<columnname>> <<datatype>> not null)
    else
    1) rename <<tablename>> to <<tablenamebk>>
    2) drop table <<tablename>>
    3) Alter table <<tablenamebk>> add(<<columnname>> <<datatype>>)
    4) update <<tablenamebk>> set <<columnname>>=<<anyvalue>>
    5) create table <<tablename>> (with additional columns with not null)
    6) insert into <<tablename>> select * from <<tablenamebk>>

  • Do we have a function in oracle to select not null columns at the begining

    Hi,
    I have 8 columns. Some of them might be null.
    I want to display all 8 columns in my result. Not null columns will be first and null at the end.
    Here is a sample data :
    Employee table :
    Employee_id   Emp_fname  emp_lname  emp_mname  dept salary emp_height  emp_weight
       1               aaa        ddd                d1   100      6           180
       2               bbb                ccc             120                 169
       3               dfe                           d2            5.9         223The expected result is :
    result1 result2   result3 result4  result5  result6 result7 result8
    1        aaa        ddd     d1       100     6        180
    2        bbb        ccc     120      169
    3        dfe        d2      5.9      223Thanks.
    Edited by: BluShadow on 12-Jul-2012 16:12
    added {noformat}{noformat} tags for readability.  Please read {message:id=9360002} and do this yourself in future.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    The requirement doesn't make a lot of sense and tends to imply that you have an incorrect data model. If that's the case, you'd be much better off fixing the data model than in trying to write this sort of query (particularly since a poor data model is going to force you to write a bunch of creative SQL).
    If you define a type and a function
    CREATE TYPE num_tbl AS TABLE OF NUMBER;
    create or replace function count_null( l_nums in num_tbl )
      return number
    is
      l_cnt integer := 0;
    begin
      for i in 1..l_nums.count
      loop
        if( l_nums(i) is null )
        then
          l_cnt := l_cnt + 1;
        end if;
      end loop;
      return l_cnt;
    end;Then you can do something like this
    SQL> ed
    Wrote file afiedt.buf
      1  select product,
      2         coalesce( q1, q2, q3, q4 ) col1,
      3         (case when count_null( num_tbl( q1 ) ) = 0
      4               then coalesce( q2, q3, q4 )
      5               when count_null( num_tbl( q1, q2 ) ) = 1
      6               then coalesce( q3, q4 )
      7               when count_null( num_tbl( q1, q2, q3 ) ) = 1
      8               then q4
      9               else null
    10           end) col2,
    11         (case when count_null( num_tbl( q1, q2 ) ) = 0
    12               then coalesce( q3, q4 )
    13               when count_null( num_tbl(q1, q2, q3) ) = 1
    14               then q4
    15               else null
    16           end) col3,
    17         (case when count_null( num_tbl( q1, q2, q3 ) ) = 0
    18               then q4
    19               else null
    20           end) col4
    21*   from saleshist
    SQL> /
    PRODUCT                              COL1       COL2       COL3       COL4
    Oracle EE                             100        123        128
    Partitioning                          100        130        128Justin

  • OracleXMLSave - Insert into table with NOT NULL Columns

    Im having trouble using OracleXMLSave (XSU12) to insert into a
    table where columns are initialized on insert with system
    derived values (see table script below) I get the following
    error message.
    Message: 'java.sql.SQLException: ORA-01400: cannot insert
    NULL "TESTMEETING"."S_TERMID")
    Im inserting this XML:
    <ROWSET table="testmeeting">
    <ROW>
    <DESCRIPTION>TestMeeting</DESCRIPTION>
    <STARTDATE>2001-10-22 00:00:00.0</STARTDATE>
    <CATEGORYCODE>HR</CATEGORYCODE>
    <STATUS>O</STATUS>
    </ROW>
    </ROWSET>
    Table Script:
    CREATE TABLE TESTMEETING (
    S_TERMID VARCHAR2 (12) DEFAULT (USERENV('TERMINAL'))
    NOT NULL,
    S_RECORDCREATED DATE DEFAULT (SYSDATE) NOT NULL,
    S_RECORDCREATOR NUMBER (4) DEFAULT (UID) NOT NULL,
    DESCRIPTION VARCHAR2 (28),
    CATEGORYCODE VARCHAR2 (2),
    STARTDATE DATE,
    STATUS VARCHAR2 (1))
    If I remove these columns the insert works OK. Inserts also work
    fine from sqlplus etc.
    Apologies for the previous entry, itchy fingers.
    Thanks for your help

    Hi.
    try to insert data in column "TESTMEETING"."S_TERMID" by trigger.
    Thanks..

  • Odi-row wise insertion of single source into multiple interfaces in package

    hi,
    i have an issue.My source table is emp(empno(pk),name,job,mgr,sal,deptno,comm).And my target tables are
    emp1(name,empnoa(pk),deptno),emp2(empnob(pk),job,sal).
    i have two interfaces: interface1----emp to emp1
    interface2-----emp to emp2.
    I have 100 rows in my source table.
    Requirement is :in my package i put interface 1 after interface 2.
    For each row of the sorce emp.The data should go into targets emp1,emp2.If a particular row isnt getting into either emp1 or emp2.That particular should rollback[i.e it should enter into either emp1 or emp2].
    The insertion should be row wise and not the whole of source data.
    How do i go about this?

    Perhaps this will work:
    Keep interface 1 as is - run it first in the package.
    for interface 2, join emp to emp1, only update/insert into target (emp2) if: emp.empno = emp1.empnoa - this way, you will not add anything to emp2 that is not in emp1.
    then, create a simple procedure to
    delete *
    from emp1
    where not empnoa in (select empnob from emp2)
    They may be a better solution, but this is easy and should work just fine.

  • NULL in not null column

    Hi,
    I have a table
    SQL> desc tabula.M$$USERS;
    Name Null? Type
    USERLOGIN NOT NULL VARCHAR2(20)
    PASSWORD NOT NULL VARCHAR2(30)
    T$USER NOT NULL NUMBER(38)
    USERNAME NOT NULL VARCHAR2(30)
    USERID NOT NULL NUMBER(38)
    USERGROUP NOT NULL NUMBER(38)
    T$LINKID NOT NULL VARCHAR2(50)
    password column is not null.
    Application get ORA-01400 (can't insert to null into not null colum) and also when I run -
    Edited by: user10237262 on Nov 29, 2011 12:54 AM

    Hi welcome to forum
    see below example
    SQL> create table t(empno number(4) not null, ename varchar2(10))
      2  /
    Table created.
    SQL> insert into t values(100,'abc');
    1 row created.
    SQL> insert into t values(200,'def');
    1 row created.
    SQL> insert into t values(null,'def');
    insert into t values(null,'def')
    ERROR at line 1:
    ORA-01400: cannot insert NULL into ("SYSTEM"."T"."EMPNO")
    SQL> desc t
    Name                                      Null?    Type
    EMPNO                                     NOT NULL NUMBER(4)
    ENAME                                              VARCHAR2(10)
    SQL>"Null?" tells the perticular column is null or not...
    Usage
    The description for tables, views, types and synonyms contains the following information:
    each column's name
    whether or not null values are allowed (NULL or NOT NULL) for each column
    refer:
    http://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12019.htm
    Edited by: newbie on Nov 29, 2011 12:54 AM

  • Empty string in NOT NULL column

    I'm migrating data to Oracle 9i from a database engine that supports emtpy strings in column with NOT NULL specified in the DDL. I would have thought Oracle would support this, but any attempt to put empty string data into a column created with NOT NULL is returning a 'column does not support nulls'-type error.
    Is there an option to allow this, or does Oracle simply not support this and assumes blank is null?
    Thanks

    I would have thought Oracle would support this, but any attempt to put empty string data into a column created with NOT NULL is returning a 'column does not support nulls'-type error.In Oracle Null means null nothing not even an empty String.
    Yes DB's like Ingress supports this. But I think Oracle is right.
    Is there an option to allow this, or does Oracle simply not support this and assumes blank is null?I am not aware of any options as it is against the basic principles.
    you can find work arounds to do the migration. But storing a blank NO.
    Good Luck
    Vij

  • Null and not null columns

    Hi,
    I want to specify that if an ID is 0 or null to do something... I am not sure if I am writing the code properly since it does not display anything when the coulmn has data(not null)
    <%! int ID=1;%>
    <% if ((ID ==0) || (request.getParameter("ID") !=null)){ %>
    do something
    <%} else {%>
    do something else
    <%%>
    if the ID is has a number greater than 0 then I would like to display information. But my code does not get to the else statement?
    Thanks!

    Remember the functionality of logical OR operator. IF the first statement evaluated is TRUE, the next are not evaluated.

  • Script or query to generate a report of null or not null columns

    I need a script/query it should pick up all the tables from user_tab_columns and produce a report for all the tables which are the columns are null and not null.

    As long as the columns were defined as NOT NULL on table create, or ALTERed NOT NULL, you can do this:
    SQL> CREATE TABLE t (id NUMBER NOT NULL, descr VARCHAR2(10));
    Table created.
    SQL> SELECT column_name, table_name, nullable
      2  FROM user_tab_columns
      3  WHERE table_name = 'T';
    COLUMN_NAME                    TABLE_NAME                     N
    ID                             T                              N
    DESCR                          T                              Y
    SQL> ALTER TABLE t modify (descr NOT NULL);
    Table altered.
    SQL> SELECT column_name, table_name, nullable
      2  FROM user_tab_columns
      3  WHERE table_name = 'T';
    COLUMN_NAME                    TABLE_NAME                     N
    ID                             T                              N
    DESCR                          T                              NNote that if you do:
    ALTER TABLE t ADD CONSTRAINT id_nn CHECK (id IS NOT NULL);then the nullable column in xxx_tab_columns will remain as Y.
    HTH
    John

  • Help - Inserting an XML document into a Oracle 8i Column (CLOB Type)

    Hi JavaGurus,
    I am looking for a simple java code which will take my XML document as input and insert the same into a Oracle 8i database's column which is of type CLOB.
    Insert statement won't work and I can not use SQL Loader.
    Any one?
    JK

    Maybe you can adapt some of the code in Oracle's "LOB Datatype" example, which is a complete working program that stores and retrieves BLOBs and CLOBs.
    http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/advanced.html

  • Error in updating not null column

    hi,
    I am getting the following error when i run the below query,
    SQL> SQL> SQL> SET (a.rate_center_nm,a.rate_center_state_cd,a.load_status_cd) =
    ERROR at line 2:
    ORA-01407: cannot update
    ("MKDM"."MASTER_ADRS_RATE_CENTER_XREF"."LOAD_STATUS_CD") to NULL
    Query
    UPDATE /*+ PARALLEL(a,6) */ master_adrs_rate_center_xref a
    SET (a.rate_center_nm,a.rate_center_state_cd,a.load_status_cd) =
    SELECT /*+ PARALLEL(b,6) */
    b.rate_center_nm
    ,b.rate_center_state_cd
    ,'4'
    FROM
    xref_temp b
    WHERE
    a.mast_pri_address_id = b.mast_pri_address_id
    WHERE EXISTS
    SELECT 1
    FROM
    master_adrs_rate_center_xref b
    ,xref_temp c
    WHERE b.mast_pri_address_id = c.mast_pri_address_id
    Can anyone help me in identifying the error?
    Beneven

    I would change your WHERE EXISTS clause to look exactly like your subquery (except for the column list of course):
    UPDATE master_adrs_rate_center_xref a
    SET   (a.rate_center_nm
          ,a.rate_center_state_cd
          ,a.load_status_cd) =
                 (SELECT b.rate_center_nm
                        ,b.rate_center_state_cd
                        ,'4'
                  FROM   xref_temp b
                  WHERE  a.mast_pri_address_id = b.mast_pri_address_id
    WHERE EXISTS (SELECT 1
                  FROM   xref_temp b
                  WHERE  a.mast_pri_address_id = b.mast_pri_address_id
    ;

  • SQL 7 - Oracle 8i - NOT NULL dropped for IDENTITY column

    It appears that OMWB is dropping the NOT NULL condition for columns defined as IDENTITY in SQL server 7.
    SQL code to create table:
    CREATE TABLE [dbo].[PCPrsnCorp] (
    [PrsnCorpId] [int] IDENTITY (1, 1) NOT NULL ,
    [PrsnCorpTpEnum] [tinyint] NOT NULL ,
    [Name] [varchar] (128) NOT NULL ,
    [NameFirstIdx] [smallint] NULL ,
    [NameMidIdx] [smallint] NULL ,
    [NameLastIdx] [smallint] NULL ,
    [NameSuffixIdx] [smallint] NULL ,
    [NameLine2Idx] [smallint] NULL ,
    [CmpyId] [smallint] NULL ,
    [ClsnId] [int] NOT NULL
    ) ON [PRIMARY]
    GO
    OMWB migration script:
    REM
    REM Message : Created Table :sa.PCPRSNCORP
    REM User : system
    CREATE TABLE sa.PCPRSNCORP(PRSNCORPID NUMBER (10,0) ,PRSNCORPTPENUM NUMBER
    (3,0) NOT NULL,NAME VARCHAR2 (128) NOT NULL,NAMEFIRSTIDX NUMBER (5,0)
    ,NAMEMIDIDX NUMBER (5,0) ,NAMELASTIDX NUMBER (5,0) ,NAMESUFFIXIDX NUMBER
    (5,0) ,NAMELINE2IDX NUMBER (5,0) ,CMPYID NUMBER (5,0) ,CLSNID NUMBER
    (10,0) NOT NULL) TABLESPACE ORACLEFULL
    NOT NULL appears to be handled correctly if colummn is not defined as IDENTITY. Is there a patch, workaround, or OMWB option to get past this?

    Currently, the Migration Workbench converts IDENTITY columns into a BEFORE INSERT trigger and an Oracle sequence.
    This trigger will fire prior to any INSERT statement executing against the table. The trigger inserts the next value of the defined sequence into the converted IDENTITY column.
    The NOT NULL column attribute is therefore no longer needed.
    Strictly speaking, it would do no harm to keep the NOT NULL column attribute and so I will log a bug on your behalf.
    Thanks for the info.
    Brian.

Maybe you are looking for

  • Apple no longer allows RESTORE via 3.0.1?!

    i have an event tomorrow. EARLY. i dont want to download the 3.1 ipsw tonight cuz my net connection is SLOW but i need to restore so i can get up and go to WORK in the morning with a _working phone_. i only need to restore because after downloading _

  • [Forum FAQ] How to format and combine PowerShell outputs

    Format the output with "Format-Table" and "Format-list" Sometimes when we query Powershell cmdlet, we would get ellipses in the result, which is not desirable. In this scenario, we can use the cmdlet "Format-Table" and "Format-list" to view the entir

  • Not able to change password in SAP WEB application server for BI 7 EHP 1.

    Hi all, I'm currently upgrading from BW 3.5 to BI 7 EHP 1. When logging to SAP WEB application server to execute a WEB report, it's not possible to change password. Even when a initial password has been set, the user are not forced or able to change

  • How to preserve the "return" char in the datafile imported

    Is there any way to preserve the "return" char in the datafile when using SQL*Loader to import data?What I wanted is to keep some format of the original data,the sample datafile as following(with the "|" as the fields-limit) aaaaa|bbbbbb cccccc|jjjjj

  • Generating Word 2007 document from RH X5

    Is there a work-around for generating printed documetation in RH X5 with Word 2007? If not, is there a version that is compatible with Word 2007?