Unique or primary key on timestamp with timezone

Hi,
I have been experimenting with a date column in a primary key, or actually I tried using a timestamp with time zone in a primary key.
While researching whether there was a way to avoid ORA-02329, I found the following:
K15> create table dumdum
  2    (datum date not null
  3    ,naamp varchar2( 30 ) not null);
Table created.
K15>
K15> alter table dumdum
  2    add constraint d_pk
  3        primary key
  4          (datum, naamp)
  5    using index;
Table altered.
K15>
K15> select ind.index_type
  2  from   user_indexes ind
  3  where  ind.index_name = 'D_PK';
INDEX_TYPE
NORMAL
1 row selected.
K15>
K15> insert into dumdum
  2    (datum
  3    ,naamp )
  4  select sysdate - (level/1440)
  5  ,      'nomen nescio'
  6  from   dual
  7  connect by level < 1000
  8  ;
999 rows created.
K15>
K15> analyze index d_pk validate structure;
Index analyzed.
K15> analyze table dumdum compute statistics;
Table analyzed.
K15>
K15> select naamp
  2  from   dumdum
  3  where  datum > to_date('16-06-2011 15.46.16', 'dd-mm-yyyy hh24.mi.ss' )
  4 
K15> For the last select statement I get the following "explain plan":
SELECT STATEMENT  CHOOSE
          Cost: 2  Bytes: 247  Cardinality: 13       
     1 INDEX RANGE SCAN UNIQUE D_PK
                Cost: 3  Bytes: 247  Cardinality: 13  This behavior lived up to my expectations.
Then, I tried this:
K15> create table dumdum
  2    (datum date not null
  3    ,naamp varchar2( 30 ) not null);
Table created.
K15>
K15> alter table dumdum
  2    add constraint d_pk
  3        primary key
  4          (datum, naamp)
  5    using index;
Table altered.
K15>
K15> alter table dumdum
  2        modify datum timestamp(6) with time zone;
Table altered.
K15>
K15> select ind.index_type
  2  from   user_indexes ind
  3  where  ind.index_name = 'D_PK';
INDEX_TYPE
NORMAL
1 row selected.
K15>
K15> insert into dumdum
  2    (datum
  3    ,naamp )
  4  select sysdate - (level/1440)
  5  ,      'nomen nescio'
  6  from   dual
  7  connect by level < 1000
  8  ;
999 rows created.
K15>
K15> analyze index d_pk validate structure;
Index analyzed.
K15> analyze table dumdum compute statistics;
Table analyzed.
K15>
K15> select naamp
  2  from   dumdum
  3  where  datum > to_date('16-06-2011 15.46.16', 'dd-mm-yyyy hh24.mi.ss' )
  4
K15> So, at first glance, the alter table statement to change the datatype from DATE to TIMESTAMP seems like a way of fooling Oracle. But the explain plan reveals a different story:
SELECT STATEMENT  CHOOSE
          Cost: 4  Bytes: 1,25  Cardinality: 50       
     1 TABLE ACCESS FULL DUMDUM
                Cost: 4  Bytes: 1,25  Cardinality: 50  I was only fooling myself. :-0
But I wasn't done with my research:
K15> create table dumdum
  2    (datum timestamp(6) with time zone not null
  3    ,naamp varchar2( 30 ) not null);
Table created.
K15>
K15> create unique index d_ind
  2      on dumdum
  3           (datum, naamp);
Index created.
K15>
K15>
K15> select ind.index_type
  2  from   user_indexes ind
  3  where  ind.index_name = 'D_IND';
INDEX_TYPE
FUNCTION-BASED NORMAL
1 row selected.
K15>
K15> insert into dumdum
  2    (datum
  3    ,naamp )
  4  select systimestamp - (level/1440)
  5  ,      'nomen nescio'
  6  from   dual
  7  connect by level < 1000
  8  ;
999 rows created.
K15>
K15> analyze index d_ind validate structure;
Index analyzed.
K15> analyze table dumdum compute statistics;
Table analyzed.
K15>
K15> select naamp
  2  from   dumdum
  3  where  datum > to_date('16-06-2011 15.56.16', 'dd-mm-yyyy hh24.mi.ss' )
  4
K15>Now, my explain plan looks fine:
SELECT STATEMENT  CHOOSE
          Cost: 2  Bytes: 1,25  Cardinality: 50       
     1 INDEX RANGE SCAN UNIQUE D_IND
          Cost: 3  Bytes: 1,25  Cardinality: 50  Why is Oracle so adamant about not allowing a timestamp with time zone in a unique key? And, given their position on the matter, where does their tolerance for a unique index come from?
By the way, if I had a say in it, I would not allow anything that even remotely looks like a date to be part of a primary key, but that's another discussion.
Thanks,
Remco
P.S. All this is on Oracle9i Enterprise Edition Release 9.2.0.8.0. Is it different on 10g or 11g?

See if this helps. You can create primary key for TIMESTAMP WITH LOCAL TIME ZONE datatype.
SQL>CREATE TABLE Mytimezone(Localtimezone TIMESTAMP WITH LOCAL TIME ZONE primary key, Location varchar2(20) );
Table created.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14225/ch4datetime.htm#i1006169
TIMESTAMP WITH LOCAL TIME ZONE Datatype
TIMESTAMP WITH LOCAL TIME ZONE is another variant of TIMESTAMP. It differs from TIMESTAMP WITH TIME ZONE as follows: data stored in the database is normalized to the database time zone, and the time zone offset is not stored as part of the column data. When users retrieve the data, Oracle returns it in the users' local session time zone. The time zone offset is the difference (in hours and minutes) between local time and UTC (Coordinated Universal Time, formerly Greenwich Mean Time).
Thanks
http://swervedba.wordpress.com/

Similar Messages

  • No matching unique or primary key for this column-list --error

    CREATE TABLE CUSTOMER(CUS_NUM NUMBER(10) PRIMARY KEY,CUS_NAME VARCHAR2(50),ADDRESS VARCHAR2(50));
    CREATE TABLE ITEM(ITEM_NUM NUMBER(10),ITEM_DESC VARCHAR2(50),TYPE VARCHAR2(50),ITEM_STATUS VARCHAR2(50),
    CONSTRAINT PK_ITEM PRIMARY KEY(ITEM_NUM,TYPE));
    CREATE TABLE ITEM_TYPE(TYPE VARCHAR2(50) PRIMARY KEY,TYPE_NAME VARCHAR2(50),SKU VARCHAR2(50),RATING VARCHAR2(50));
    CREATE TABLE ORDERS(ORDER_NUMBER NUMBER(10),CUS_NUM NUMBER(10),ITEM_NUM NUMBER(10),ORDER_POINT VARCHAR2(50),DISPATCH_POINT VARCHAR2(50),
    PRIORITY VARCHAR2(50),ORDER_STATUS VARCHAR2(50),
    CONSTRAINT PK_ORDERS PRIMARY KEY(ORDER_NUMBER,ITEM_NUM),
    CONSTRAINT FK1_ORDERS FOREIGN KEY (CUS_NUM) REFERENCES CUSTOMER(CUS_NUM),
    CONSTRAINT FK2_ORDERS FOREIGN KEY (ITEM_NUM) REFERENCES ITEM(ITEM_NUM));
    Hi,friends i created tables as above when i creating 'ORDERS' table the error will fir as "ORA-02270: no matching unique or primary key for this column-list".
    can any body solve this issue.
    Cheers,
    Sudhir reddy.

    For your own sanity, you should learn to format your code, or use a tool to do it for you. For the sanity of the forum members, you should preserve that code using the \ tagsCREATE TABLE CUSTOMER
    CUS_NUM NUMBER(10) PRIMARY KEY,
    CUS_NAME VARCHAR2(50),
    ADDRESS VARCHAR2(50)
    CREATE TABLE ITEM
    ITEM_NUM NUMBER(10),
    ITEM_DESC VARCHAR2(50),
    TYPE VARCHAR2(50),
    TYPE is a reserved word.  Call it ITEM_TYPEITEM_STATUS VARCHAR2(50),
    CONSTRAINT PK_ITEM PRIMARY KEY(ITEM_NUM,TYPE)
    CREATE TABLE ITEM_TYPE
    TYPE VARCHAR2(50) PRIMARY KEY,
    again, with the reserved word.TYPE_NAME VARCHAR2(50),
    SKU VARCHAR2(50),
    RATING VARCHAR2(50)
    CREATE TABLE ORDERS
    ORDER_NUMBER NUMBER(10),
    be consistent.  NUM or NUMBER.  Pick one and stick with it.CUS_NUM NUMBER(10),
    ITEM_NUM NUMBER(10),
    ORDER_POINT VARCHAR2(50),
    DISPATCH_POINT VARCHAR2(50),
    PRIORITY VARCHAR2(50),
    ORDER_STATUS VARCHAR2(50),
    CONSTRAINT PK_ORDERS PRIMARY KEY(ORDER_NUMBER,ITEM_NUM),
    CONSTRAINT FK1_ORDERS FOREIGN KEY (CUS_NUM) REFERENCES CUSTOMER(CUS_NUM),
    CONSTRAINT FK2_ORDERS FOREIGN KEY (ITEM_NUM) REFERENCES ITEM(ITEM_NUM)

  • Oracle ODBC driver and TIMESTAMP with timezone

    Does anyone know if it is possible to return data from a "TIMESTAMP WITH TIMEZONE" column using the Oracle ODBC driver and an ADO Recordset?
    I am using the Oracle driver version 10.2.0.2 and TIMESTAMP fields work fine.
    I can call Recordset->Open() with a query like "SELECT * FROM TABLE" when the table contains a column of type timestamp with timezone but when I execute a statement to see if there are results as in
    if (!(srcRecsetPtr->BOF && srcRecsetPtr->EndOfFile))
    my application throws an unhandled exception and exits. The exception is not a COM exception and I'm not sure how to get back additional information if that's possible.
    The only information I've been able to find in searching TechNet and MetaLink is that a workaround is to wrap the columns in a TO_CHAR or TO_DATE conversion first but that's not a good solution for my problem since I am executing user specified SQL which may join multiple tables.
    I've found one other note that says the documentation should be corrected and that these fields are NOT supported period (Bug #4011640).
    I've experimented with the Bind Timestamp as Date option in the ODBC connection and with various ALTER SESSION settings to attempt to change the NLS_TIMESTAMP_TZ_FORMAT but I have been unable to get past the problem.
    Any ideas are greatly appreciated.
    Thanks,
    Troy

    Hi Justin
    Thanks for your help.
    I tried what you mentioned and I could connect myself via SQL*Plus without passing a password and a login, Extern authentification seems to work and my user seems to be right configurated.
    But he problem goes on via ODBC. When I test connection in the ODBC Data Source Administrator of Windows XP, test fails and seems to forbid connection without userID and password. When I try to connect via ODBC in my program the same problem appears : "Unable to connect SQLSTATE=28000 [Oracle][ODBC][ORA]Ora-01017: Invalid username/password;logon denied" I could not connect in this way.. What's wrong ?

  • Converting timestamp with timezone to milisecs

    Hi guys,
    How to converting timestamp with timezone to milisecs?
    I'm using oracle 10g.

    SeánMacGC wrote:
    Hello, do you mean:
    SQL> select to_char(systimestamp, 'SSSSS') from dual;
    TO_CH
    58435
    'SSSSS' Format Model returns 'Seconds past midnight' not milliseconds. I wonder if OP meant Fractional Seconds?
    SQL> SELECT TO_TIMESTAMP_TZ('1999-12-01 11:00:00.00532 -8:00',
      2         'YYYY-MM-DD HH:MI:SS.FF TZH:TZM') col_1 FROM DUAL
      3  /
    COL_1
    01-DEC-99 11.00.00.005320000 AM -08:00
    SQL> SELECT TO_CHAR(col_1, 'FF') fractional_sec FROM
      2  (SELECT TO_TIMESTAMP_TZ('1999-12-01 11:00:00.00532 -8:00',
      3         'YYYY-MM-DD HH:MI:SS.FF TZH:TZM') col_1 FROM DUAL)
      4  /
    FRACTIONA
    005320000
    SQL>Regards,
    Jo
    Edited by: Joice John : Added Code Tags

  • Regarding timestamp with timezone

    Hi,
    I have the following timestamp with timezone issue.
    From java program I am passing the datetime with timezone value to database (INTERVALTIME (column name)).
    PrepareStatemenet statement;
    java.util.Date dt = ISODateUtil.parse("2006-06-21T18:00:00+00:00");
    SimpleTimeZone zone = new SimpleTimeZone(0,"IST");
    Calendar cal = converting the dt to calendar;
    cal.setTimeZone(zone);
    statement.setTimestamp(col, new Timestamp(cal.getTimeInMillis()),cal);     
    In database INTERVALTIME (column name) coulmn type is TiMESTAMP WITH TIMEZONE.Database is in PDT (GMT-8) timezone.
    Now the problem is :
    Even if i send the datetime of IST timezone, it is displaying in PDT (GMT-8) timezone.
    How can i resolve this issue?

    Reo wrote:
    The query you provided doesn't run. If I want to convert to a different timezone, I need the from_tz.Is column update_time a TIMESTAMP WITH TIME ZONE? If so, then no casting is needed:
    SQL> create table test(id number,update_time timestamp with time zone)
      2  /
    Table created.
    SQL> insert into test values(1,systimestamp)
      2  /
    1 row created.
    SQL> insert into test values(2,systimestamp  at time zone 'UTC')
      2  /
    1 row created.
    SQL> select  id,
      2          update_time,
      3          update_time at time zone 'US/Pacific'
      4    from test
      5  /
            ID
    UPDATE_TIME
    UPDATE_TIMEATTIMEZONE'US/PACIFIC'
             1
    18-NOV-09 04.23.03.241000 PM -05:00
    18-NOV-09 01.23.03.241000 PM US/PACIFIC
             2
    18-NOV-09 09.23.29.346000 PM UTC
    18-NOV-09 01.23.29.346000 PM US/PACIFIC
            ID
    UPDATE_TIME
    UPDATE_TIMEATTIMEZONE'US/PACIFIC'
    SQL> SY.

  • Oracle timestamp with timezone

    Does CR support column of type "timestamp with timezone" column. I am getting error message "Failed to retrive data from database. Details:Not implemented". Thanks

    Since this is the Crystal Reports Java forum, you need to specify the explicit Java java.sql Type that the Oracle JDBC driver exposes the database type as.
    I'm not familiar with that data type, so don't know if it's mapped to the Timestamp type or not.
    Note that CR4E 2.0 supports up to JDBC 4.0 types.
    Sincerely,
    Ted Ueda

  • Why have I lost the info of  timezone (Timestamps with Timezone )

    I have been trying to get timestamps with timezones working in my Java application, but I don't seem to get the data I expect back from the JDBC driver
    my field type is Timestamps with Timezone ,in the database,I saw the info of (12-DEC-06 01.12.12.123000 PM -06:00),but I don't know How to get it from Java
    I've use the Timestamp aa =rs.getTimestamp("FIELDVALUE");but the timezone is lost, what can I do?
    thanks

    Timestamps are always GMT based (or could be thought of as timezone neutral) so what you should get back is a timestamp representing a GMT equivalent of the time you see that has a 6 hour offset from GMT. In other words, if the time were 1 PM Central Standard you would get a GMT time of 7 PM.
    You should then be able to display that time in any time zone you wish using SimpleDateFormat and specifying the time zone you want to display it in. So if you then display it with Central Standard, the 7 PM GMT would then display as 1 PM again. In other words, 7 PM GMT and 1 PM Central Standard are the same timestamp
    If you just display the timestamp using a toString(), you will get the time in the default time zone of the JVM..
    Whether the driver actually does this correctly with the Oracle database I can't say. I've made several posts in a variety of places complaining that the driver does not work correctly with timestamps but my experience is limited to regular timestamp fields, not the new Oracle type of timestamp with timezone.
    Based on my experience, what you are more likely getting back in the 1 PM- 7 PM example is 7 PM in the default timezone of the JVM.
    You should look at the getTimestamp with Calendar options to see if they work better for you.
    The main thing to keep in mind is that timestamps are really timezone neutral.

  • Compare 2 'timestamp with timezone' columns

    Hi All,
    I'm trying to compare 2 'timestamp with timezone' columns,
    comparision works fine as long as there is difference of at least seconds between them.
    But when the difference between them is in milliseconds, comparison is failing.
    I'm using oracle 10g.
    Pls advice.

    Works just fine:
    SQL> DECLARE
      2      t1 TIMESTAMP WITH TIME ZONE := TIMESTAMP '2008-01-10 10:25:17.123456 US/EASTERN';
      3      t2 TIMESTAMP WITH TIME ZONE := TIMESTAMP '2008-01-10 10:25:17.323456 US/EASTERN';
      4  BEGIN
      5      IF t1 <= t2
      6        THEN
      7          DBMS_OUTPUT.PUT_LINE('t1 <= t2');
      8      END IF;
      9  END;
    10  /
    t1 <= t2
    PL/SQL procedure successfully completed.
    SQL> DECLARE
      2      t1 TIMESTAMP WITH TIME ZONE := TIMESTAMP '2008-01-10 10:25:16.123456 US/EASTERN';
      3      t2 TIMESTAMP WITH TIME ZONE := TIMESTAMP '2008-01-10 10:25:17.323456 US/EASTERN';
      4  BEGIN
      5      IF t1 <= t2
      6        THEN
      7          DBMS_OUTPUT.PUT_LINE('t1 <= t2');
      8      END IF;
      9  END;
    10  /
    t1 <= t2
    PL/SQL procedure successfully completed.
    SQL> Based on your:
    But when the difference between them is in milliseconds, comparison is failing. Most likely your code does implicit/explicit timestamp conversion to date. Post your code.
    SY.

  • Unique and primary key

    column with unique constraint + not null constraint = primary key! (to some extent) Is it correct?
    I invite your ideas

    http://www.techonthenet.com/oracle/unique.php
    http://www.allapplabs.com/interview_questions/db_interview_questions.htm#q13
    Difference between Unique key and Primary key(other than normal difference)

  • Primary Key Multiple Column with Date - parameter issue

    All,
    I am having an issue that I cannot find the answer to. I have looked high and low to no avail. Please help.
    The issue at hand is that I have a table that has a multiple column primary key and one of the columns happens to be a date and the other is a string. I have a basic search and I want an update picture in the results table that the users can click on and go to a different page to update that record. The issue is when I fire an action based on the update picture I also want to set parameters based on the record that I selected. So I set the string parameter and that works fine. The issue is with the date. When i set the date parameter it works but it chops off the timestamp. Later when I try to get this parameter 'pageContext.getParameter("dateParameter");' it will bring in a date like 15-Dec-2008 but I need the entire date and timestamp (i.e. 15-Dec-2008 10:20:33) to correctly identify the record.
    Please help!
    Thanks,
    Colby J

    Hi
    since every parameter go in url as a string format so u will never get the date parameter with complete timestamp,the solution would de
    1.) Set a fire action on update picture,give its event name as "update",
    2.) clicking on update picture will fire this event .
    3.) in processFormrequest method of controller
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    if ("update".equals(pageContext.getParameter("event")))
    // this will give the select row where update is clicked
    String rowReference = pageContext.getParameter(OAWebBeanConstants.EVENT_SOURCE_ROW_REFERENCE);
    VORowImpl row = (EmployeeSummaryVORowImpl)am.findRowByRef(rowReference);
    Timestamp sdateVal=(String)row.getAttribute("Date value");
    // this will transfer the values to next page
    pageContext.putTransactionTransientValue("transferdvalue",sdateVal);
    // and in the next page u can get the value like this
    timestamp getDateVal=pageContext.getTransactionTransientValue("transferdvalue"l);
    hope this will resolve your issue,Please let me know if u face any issue
    thanx
    Pratap

  • How can we export the Primary key values (along with other data) from an Advantage database?

    One of our customers is moving from our application (which uses Advantage Database Server) to another application (which uses other database technology). They have asked us to help export their data, so that they can migrate it to another database system. So far, we have used the Advantage Data Architect (ARC32) "Export Table Structures as Code" functionality to generate SQL. We used the "Include existing data" option. The SQL contains the necessary code to recreate the tables and indexes. The customer's IT staff will alter the SQL statements as necessary for their new system.
    However, there is an issue with the Primary Keys in these table. The resulting INSERT statements use AutoInc as the type for the Primary Key in each Table. These INSERT statements contains "DEFAULT" for the value of each of these AutoInc fields. The customer would like to output an integer value for each of these Primary Key values in order to maintain referential integrity in their new system.
    So far, I have not found any feature of ARC32 that allows us to export the Primary Key values. We had been using an older version of ARC32, since our application does not use the latest version of ADS. I did download the latest version of ARC32 (11.10), but it does not appear to include any new functionality that would facilitate doing this sort of export.
    Can somebody tell me if there is such a feature in ARC32?
    Or, is there is another Advantage tool to facilitate what we are trying to accomplish?
    If there are no Advantage tools to provide such functionality, what else would you suggest?

    George,
      It sounds like the approach you are using is the correct one. This seems to be the cleanest solution to me especially since the customer is able to modify the generated SQL statements for their new system.
      In order to preserve the AutoInc values I would recommend altering the table and changing the field datatype from AutoInc to Integer. Then export the table as code which will export the actual values. After the tables have been created on the new system they can change the field datatype back to an AutoInc type if necessary.
    Regards,
    Chris Franz

  • Primary key problem using with oc4j

    Hi everyone
    I have deployed my entity bean in the oc4j container without any problem.But when I use the search->primary key in the console,no results display.
    detail:
    Step1I open the oc4j console by typing java -jar orion.jar -console
    the oc4j container is successfully built
    and in the left part of my console I see my entity bean
    step2 I click my entity bean and in the right of the console in the search->primary key I type the a number which exists in my table in the database.
    but no results display.
    the following is my datasource-file anf orion-ejb-jar file
    data-sources.xml
    <?xml version="1.0"?>
    <!DOCTYPE data-sources PUBLIC "-//Evermind//- Data-sources configuration" "http://xmlns.oracle.com/ias/dtds/data-sources.dtd">
    <data-sources>
         <data-source
              class="com.evermind.sql.DriverManagerDataSource"
              name="jdbc/OracleDSCore"
              location="jdbc/OracleDSCore"
              pooled-location="jdbc/OracleDSPooled"
              xa-location="jdbc/xa/OracleDSXA"
              connection-driver="oracle.jdbc.driver.OracleDriver"
              username="SCOTT"
              password="TIGER"
              url="jdbc:oracle:thin:@localhost:1521:b2b"
         />
    </data-sources>
    orion-ejb-jar.xml
    <?xml version = '1.0' encoding = 'GBK'?>
    <!DOCTYPE orion-ejb-jar PUBLIC "-//Evermind//DTD Enterprise JavaBeans 1.1 runtime//EN" "http://xmlns.oracle.com/ias/dtds/orion-ejb-jar.dtd">
    <orion-ejb-jar>
    <enterprise-beans>
    <entity-deployment name="EMP" data-source="jdbc/OracleDSCore" table="EMP" >
    <primkey-mapping>
    <cmp-field-mapping>
    <fields>
    <cmp-field-mapping name="EMPNO"
    persistence-name="EMPNO" persistence-type="VARCHAR2(4)"/>
    </fields>
    </cmp-field-mapping>
    </primkey-mapping>
    </entity-deployment>
    </enterprise-beans>
    <assembly-descriptor>
    <default-method-access>
    <security-role-mapping name="&lt;default-ejb-caller-role>" impliesAll="true"/>
    </default-method-access>
    </assembly-descriptor>
    </orion-ejb-jar>
    Any answer is welcome. Thankou in advance!

    Fernando,
    I see you suffer a lot with ADF...write me at [email protected] and let´s keep in touch.
    Maybe we can do a Brazilian list for JDev/ADF.
    Regards,
    Marcelo Alcantara

  • Primary key columns dropped with cascade constraint

    Hi,
    My developer dropped one column from table which was having primary key . (primary key on two columns now one column is there)
    he used SQL > alter table table_name drop columns cascade constraints.
    Now i want to enable the constraint. the constraint is not there. if i am creating the primary key with the existing single column alone.
    My question how do i know which was the dependency it had? (like foreign key / child tables it had?) and how to rebuild the relationship?
    Thanks
    --Raman                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hemangi,
    i am just wondering before dropping the column we had primary key. (as i mentioned earlier the primary key was created for two columns ) .
    now if i am re-building by just adding primary key to the existinc column alone i am facing this error.
    Let me see if there is any null or duplicate values in the column.
    Thanks
    --Raman                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to add primary key for table with existing data?

    The table is occupied data already. There was no primary key before, so for every column, there are some duplicate values.
    I want to add a new column, which should be of the datatype integer, and can automatically increment, starting from 001. I tried this in Oracle SQL Developer, but it says "ORA-01758: table must be empty to add mandatory (NOT NULL) column". How can I do it? Thanks!

    Hello, don't call the column ID, that could be an ID relating to anything. Perhaps be a little more specific like emp_id .
    Then to update it:
    UPDATE Employee emp
      SET emp_id = (
      SELECT row_num
        FROM (
      SELECT ROWID,
                 ROW_NUMBER() OVER (ORDER BY ROWID) row_num
        FROM Employee emp2) emp2
      WHERE emp.ROWID = emp2.ROWID);That will assign a new EMP_ID for each, beginning at 1.
    Then:
    ALTER TABLE Employee MODIFY emp_id NOT NULL;
    ALTER TABLE Employee ADD CONSTRAINT EMP_PK PRIMARY KEY (EMP_ID);Then create a sequence for future population of the Employee table:
    CREATE SEQUENCE emp_seq START WITH <maximum value of emp_id + 1>;

  • Php input date/time as timestamp with timezone

    This is a nightmare!!!!
    I have numerous databases, all of which use timestamp format
    date/times, which are easy to echo according to user timezone
    preferences using putenv ("TZ=".$_SESSION['MM_UTZ']); and echo
    date($_SESSION['MM_UTF'], ($whatever));
    The only problem is, I have only used these for stamping
    "date created" or "date edited" values using Time()
    What I am trying to achieve is:
    User 1 in UK enters date and time, using a javascript
    datetime picker (which normally enters data into field in Y-m-d
    H:i:s) and the php inserts this in timestamp format according to
    timezone.
    User 2 in US looks at date and time and this is echo'd
    according to his timezone.
    Sounds simple...
    I have managed to get so far with the new DateTime object
    which incorporates the user timezone preference ($utz)
    $ndttime= new DateTime($timefield, new DateTimeZone($utz));
    I can then echo this effectively using
    echo $ndttime->format('$utf'); ($utf being user timeformat
    preference)
    My stupid problem is trying to get the $ndtime into the
    database!!!!
    I know this sounds ridiculous but I use the DW insert wizard
    which only uses values from a form and if I echo $ndtime into a
    hidden field, it doesn't process this value in time.
    I attach the current insert script.
    Is this simple?
    Heeeeelp.

    quote:
    Originally posted by:
    AXEmonster
    how does this format when you echo to the page
    echo $ndttime->format('$utf');
    This will echo as a date/time object - i.e. Y-m-d H:i:s, but
    the $utf variable is a session variable with user time format
    preferences, so it could be D, d/m/Y H:i:s or m-d-Y H:i:s
    etc.

Maybe you are looking for

  • Problem with Decklink card during voice over

    Hi, i have PMG5 2.5 GHz with FCS & Blackmagic Decklink extreme card. all these days i had a great time working on FCP . till i faced a peculiar problem when i am capturing video from Beta or DV 50 , i am able to select video Only or Audio only , or V

  • Hp pavilion dv6 3049tx recovery disc info needed...

    i lost my 1st recovery dvd...can anyone please upload the 1st revovery dvd  in any website? i need the 1st revovery dvd only for my dv6 3049tx. i have rest 5dvds...only my 1st dvd is lost. please help someone. NB - I bought the laptop last year Septe

  • Aperture and colorchecker passport from X-rite

    the colorchecker passport is a tool to make color corrections by camera profiles. (http://www.xritephoto.com/phproductoverview.aspx?id=1257&tab=videos) nice program to get my color workflow better accept i use aperture and.. that just doesn't work so

  • Filling of mara-volum and -voleh within BAPI_MATERIAL_SAVEDATA

    I like to update mara-volum and mara-voleh by using BAPI_MATERIAL_SAVEDATA, but these fields are not available in structure BAPI_MARA, only in structure BAPI_MARM. Please let me know how to solve this problem.

  • Create Function Module  Extractor

    Hello Friends, Please help me in developing the extractor. I want to write the custom extractor using the three Table fields FAGLFLEXA and FAGLFLEXT with some logic to merge data. if you have any abap code. please email me at [email protected] will b