How to create an automatically increment column in Oracle DB Table?
Hi To All
Here I am trying to create a table in Oracle that creates an automatically increment column in Oracle DB Table. i searched almost all Forums.(Even in Oracle). They are saying that, that logic u must implement in Java Code.(*Takes Maximum no from table, add +1 to it, and store it back again)*. apart from this, while creating an table in Oracle, is there any facility like MySQL Database? please help me. Thanks in advance.
Hi BalusC
Thanks for Your Response and clue. with that, i succeeded in my application. Thank you very much. here i am giving you the details which i did.
1. I Created a table named orders in Oracle like this.
CREATE TABLE ORDERS (ORDER_ID NUMBER, CUSTOMER_ID NUMBER, ISBN NUMBER,
DESCRIPTION NCHAR(5));
2. I created one sequence in Oracle like CREATE SEQUENCE SEQ01 INCREMENT BY 1 START WITH 1000 3. Then i have written jdbc program like this
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class SequenceTest {
public static void main(String[] args)throws Exception{
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.135:1521:orcl","scott","tiger");
String cols[] = {"ORDER_ID", "DESCRIPTION"};
PreparedStatement pstmt = con.prepareStatement("INSERT INTO ORDERS (ORDER_ID, CUSTOMER_ID, ISBN,DESCRIPTION) VALUES (SEQ01.NEXTVAL, 104, 966431505,?)", cols);
pstmt.setString(1,"Desc3");
pstmt.executeUpdate();
ResultSet rs=pstmt.getGeneratedKeys();
System.out.println("---- One Row Inserted ----");
} catch (Exception e) {
System.out.println("---- Failed Due To "+e);
4. When i ran above program 5 times, i got the following Data into my Oracle Table (select * from orders)
ORDER_ID CUSTOMER_ID ISBN DESCR
1000 101 966431502 Desc0
1001 102 966431503 Desc1
1002 103 966431504 Desc2
1003 104 966431505 Desc3
1004 104 966431505 Desc3
1005 105 966431506 Desc4
6 rows selected.
But i dont know how to do this type of program with out using prepared statements. i tried, and i got exception *"Missing Expression"* .
Once again Thank You very much for your clue.
Similar Messages
-
How to create a view indicating column's length?
SQL>create table abc (a number(12));
I want to create a view cde with a length of number(5) by "describe cde" in sql*plus.
SQL>create view cde(a) as select a from abc;
SQL>desc cde
A NUMBER(12)
how to create a view indicating column's length? the actual value in abc only <1000
I want to create a view cde with a length of number(5) .
SQL>desc cde
A NUMBER(12)
Thank You
Ming-An ZhangThis does not make sense. How can a view be a NUMBER(5) and the actual column a NUMBER(12)?
What happens if there is a 10 or 12 digit number in the table? Just what is the view suppose to do? Crash and burn? Where is the logic in that?!
If the table's column has an incorrect precision and size, THEN FIX IT!! Do not hack it with view!
It is silly purposefully building constructs into the database that can easily result in run-time errors. -
How to create a fixed-width column within an APEX 4 interactive report?
This thread is a follow-up to {message:id=9191195}. Thanks fac586.
Partial success: The following code provided by fac586 limits the column width of the Apex 4 interactive report column as long as the column data contains whitespace within a Firefox 3.6 browser:
<pre class="jive-pre">
<style type="text/css">
th#T_DESCRIPTION {
width: 300px;
td[headers="T_DESCRIPTION"] {
width: 300px;
word-wrap: break-word;
</style>
</pre>
Notes:
1. The code above is put into the HTML header section for the page.
2. T_DESCRIPTION is defined as VARCHAR2(2000).
3. The code above works within the Firefox 3.6.12 browser but does not work within the Internet Explorer 7.0.5730.13 browser.
I tried adding "float: left;":
<pre class="jive-pre">
<style type="text/css">
th#T_DESCRIPTION {
width: 300px;
td[headers="T_DESCRIPTION"] {
width: 300px;
word-wrap: break-word;
<font color="red"> float: left;</font>
</style>
</pre>
Notes:
1. "float: left;" does not require whitespace and successfully splits the column between characters in lieu of whitespace.
2. "float: left;" shrinks the cell height and allows the page background to show through... couldn't determine how to fix this.
3. The code above works within the Firefox 3.6.12 browser but does not work within the Internet Explorer 7.0.5730.13 browser.
I've done some more research, but I still haven't discovered how to create a fixed-width column within an APEX 4 interactive report that displays properly within an Internet Explorer 7 browser.
Any ideas and help will be appreciated.Thanks for your help with this!
<pre class="jive-pre">
what theme are you using?
</pre>
A customized version of theme 15.
<pre class="jive-pre">
Floating a table cell makes no sense (to me anyway).
</pre>
You are correct. I was just trying a different approach ... trying to think out of the box.
<pre class="jive-pre">
Think you'll need to create an example on apex.oracle.com with sample data
if there are any further problems.
</pre>
Great suggestion! The code your provided works in the Firefox 3.6.12 browser, but still doesn't work within my Internet Explorer 7.0.5730.13 browser.
UPDATE:
I have recreated the problem at apex.oracle.com, you can use the following information to check it out:
URL: http://apex.oracle.com/pls/apex/f?p=43543:100::::::
Workspace: IR_FIXED_WIDTH_COLS
Username: GUEST
Password: Thx4help
Application: 43543 - CM_RANDY_SD
Note: Table name is TEST_DATA
The following code provided by fac586 works in both Firefox 3.6 and IE7 using default theme "21. Scarlet" at apex.oracle.com; however, it doesn't work when I use a copy of our customized theme "101. Light Blue":
<pre class="jive-pre">
<style type="text/css">
.apexir_WORKSHEET_DATA {
th#T_DESCRIPTION {
width: 300px;
max-width: 300px;
td[headers="T_DESCRIPTION"] {
max-width: 300px;
word-wrap: break-word;
</style>
<!--[if lt IE 8]>
<style type="text/css">
/* IE is broken */
th#T_DESCRIPTION,
td[headers="T_DESCRIPTION"] {
width: 300px;
</style>
<![endif]-->
</pre>
Any idea what in the theme could be causing the fixed width column to be ignored in IE 7?
Edited by: CM Randy SD on Dec 7, 2010 11:22 AM -
How can I add a new column in compress partition table.
I have a compress partition table when I add a new column in that table it give me an error "ORA-22856: CANNOT ADD COLUMNS TO OBJECT TABLES". I had cretaed a table in this clause. How can I add a new column in compress partition table.
CREATE TABLE Employee
Empno Number,
Tr_Date Date
COMPRESS PARTITION BY RANGE (Tr_Date)
PARTITION FIRST Values LESS THAN (To_Date('01-JUL-2006','DD-MON-YYYY')),
PARTITION JUNK Values LESS THAN (MAXVALUE));
Note :
When I create table with this clause it will allow me to add a column.
CREATE TABLE Employee
Empno Number,
Tr_Date Date
PARTITION BY RANGE (Tr_Date)
PARTITION FIRST Values LESS THAN (To_Date('01-JUL-2006','DD-MON-YYYY')),
PARTITION JUNK Values LESS THAN (MAXVALUE));
But for this I have to drop and recreate the table and I dont want this becaue my table is in online state i cannot take a risk. Please give me best solution.Hi Fahed,
I guess, you are using Oracle 9i Database Release 9.2.0.2 and the Table which you need to alter is in OLTP environment where data is usually inserted using regular inserts. As a result, these tables generally do not get much benefit from using table compression. Table compression works best on read-only tables that are loaded once but read many times. Tables used in data warehousing applications, for example, are great candidates for table compression.
Reference : http://www.oracle.com/technology/oramag/oracle/04-mar/o24tech_data.html
Topic : When to Use Table Compression
Bug
Reference : http://dba.ipbhost.com/lofiversion/index.php/t147.html
BUG:<2421054>
Affects: RDBMS (9-A0)
NB: FIXED
Abstract: ENH: Allow ALTER TABLE to ADD/DROP columns for tables using COMPRESS feature
Details:
This is an enhancement to allow "ALTER TABLE" to ADD/DROP
columns for tables using the COMPRESS feature.
In 9i errors are reported for ADD/DROP but the text may
be misleading:
eg:
ADD column fails with "ORA-22856: cannot add columns to object tables"
DROP column fails with "ORA-12996: cannot drop system-generated virtual column"
Note that a table which was previously marked as compress which has
now been altered to NOCOMPRESS also signals such errors as the
underlying table could still contain COMPRESS format datablocks.
As of 10i ADD/SET UNUSED is allowed provided the ADD has no default value.
Best Regards,
Muhammad Waseem Haroon
[email protected] -
How to Create and Deploy Web Services Using Oracle 9i JDeveloper
Hi,
My Question is how to create and deploy Web Services using Oracle 9i JDeveloper.Anybody please give me a detailed Reply.Please Reply to [email protected]
Hopr to Hear From you,
Regards,
G SreekumarYou could use datasources. You should do this in your BC4J Configuration. Then when deploying your applicaiton use the command -installDataSource (from admin.jar) to create the right datasource.
You could probably use the name of your connection + "DS" so you can also use it locally in JDeveloper as JDev seesm to create this automaticly for your Connections. -
How to find the number of columns in an internal table DYNAMICALLY ?
Hi,
How to find the number of columns in an internal table DYNAMICALLY ?
Thanks and Regards,
saleem.Hi,
you can find the number of columns and their order using
the <b>'REUSE_ALV_FIELDCATALOG_MERGE'</b>
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = sy-repid
I_INTERNAL_TABNAME = 'ITAB'
I_INCLNAME = sy-repid
changing
ct_fieldcat = IT_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif
now describe your fieldcat . and find no of columns.
and their order also..
regards
vijay -
How can I add a new column to an Attachments Table
How can I add a new column to an Attachments Table??
And I want to remove the usage column also!
Thanks!I tried to remove the usage column doing this:
OAAttachmentTableBean attachTable = (OAAttachmentTableBean)webBean.findChildRecursive("attachTable");
if (attachTable != null)
attachTable.findChildRecursive("UsageTypeColumn").setRendered(false);
but I'm getting null pointer exception on "UsageTypeColumn"...
:( -
How to create a relational view base on an xmltype table which included sev
Hi,
I am using oracle 11.2.0.1.0.
how to create a relational view base on an xmltype table which content several different .xml files?
Thanks.
for examle:
SQL> SELECT OBJECT_VALUE FROM document;
Edited by: Cow on Jan 6, 2011 7:57 PMFor example I already have these three xml files inserted into the document xmltype table.
These xml files have same schemas. I have attached below.
I want to show all elements/attribute values in xml files to relational view.
Is this possible to create one big relational view to show everything
or I have to create three separate relation views then use UNION to put together? Thanks a lot. Cow
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="http://www.accessdata.fda.gov/spl/stylesheet/spl.xsl" type="text/xsl"?>
<document xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 http://localhost:8080/home/DEV/xsd/spl.xsd">
<id root="5ca4e3cb-7298-4948-8cc2-58e71ad32694"/>
</component>
</document>
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="http://www.accessdata.fda.gov/spl/stylesheet/spl.xsl" type="text/xsl"?>
<document xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 http://localhost:8080/home/DEV/xsd/spl.xsd">
</component>
</document>
Edited by: Cow on Jan 4, 2011 9:51 AM -
How do I get and set column attributes in a table or a treetable with Java?
Using 11.1.1.4.0
Hi,
How do I get and set column attributes in a table or a treetable with Java? For a simple example, say I have a table and want certain roles to see all columns (including address), and other roles can see only certain columns (no address). In a Java method, I want to test if a table's column visible attribute is true and if so, set it to false before rendering it.
Thanks in advance,
TroyHi,
this use case would be a perfect example for using seeded MDS customization. Instead of checking what users are allowed to see or not upon rendering time, you have a customization class and thus the framework doing this for you.
http://www.oracle.com/technetwork/developer-tools/adf/learnmore/31-mds-sample-169173.pdf
In this paper and sample, specific users see different layouts. It also contains a customization class that shows how this can leverage ADF Security
Frank -
How to create a new admin user in oracle 9i?.
Hi I am new to oracle. I want to set up a new database for my application.
How to create a new admin user in oracle 9i?. I would like to have a new schema. where I can create tables for my application from scratch.If I understand your question correctly:
You need to be connected to the database with the user SYS.
open a command-line session and do the following to create an Oracle user with DBA option other than SYS.
C:\>sqlplus /nolog
SQL*Plus: Release 9.2.0.1.0 - Production on Fri Oct 14 08:46:13 2005
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
SQL> conn / as sysdba
Connected.
SQL>
SQL> create user test identified by pass;
User created.
SQL> grant create session to test;
Grant succeeded.
SQL> alter user test account unlock;
User altered.
SQL> grant dba to test with admin option;
Grant succeeded.
SQL> conn test/pass
Connected.
SQL>
SQL> sho user
USER is "TEST"
SQL>Now you have a user with username 'test' and password 'pass' with DBA role with Admin option
Tony Garabedian
From now on you can connect directly with SQL*Plus no need for comman-line. Just provide the username/password and you're logged in.
Message was edited by:
Tony Garabedian -
How to display horizontally to vertically column in oracle
Dear All
How to display horizontally to vertically column in oracle,Please give me Sol. ASAPSunil,
Which column is the sal column? I canât see any numeric columns in your query. If you use htmldb_item calls in your query column, then this makes them strings and you canât build sums on string columns. If you want to build sums in an updateable report / tabular form, then donât use the htmldb_item API. Instead use the built-in display types on the report column attributes page. Using the built-in display types is the better options in most cases anyway and they do allow you to calculate sums even if the column is a text field or display and save type field.
Regards,
Marc -
How do you set up csv as an oracle external table
How do you set up csv as an oracle external table?
Hi,
>>where do I specify which csv file to read from the external table..
Please, read either the link provided by Andrew or the link that I have posted in my previous post.
"# DEFAULT DIRECTORY - specifies the default location of files that are read or written by external tables. The location is specified with a directory object, not a directory path. See Location of Datafiles and Output Files for more information.
# LOCATION - specifies the location of the external data. The location is specified as a list of directory objects and filenames. If the directory object is not specified, then the default directory object is used as the file location."
Cheers
Legatti -
How to create index for a column of a view
Hi,
I have created view for a table and then i am trying to create index for a column of that view. i am using the query "CREATE INDEX index_name ON view_name (col)". but Mysql is showing error like "view_name is not a base table".
How can i do that......As mentioned this is a java forum not a mysql forum, but as I know the answer - you can't create an index directly on a view in mysql.
-
How to create Presentation variable for columns and to use it in Narrative?
Hi All,
Anybody know how to create presentation variable for a column (i.e., i need to create it in edit formula section itself). And then, I should use it in Narrative section to display that column value. Is it possible? Or do i need to use any other variable for this requirement? If so please let me know, how to create it? This is very urgent requirement.
Thanks in Advance
ThenmozhiHi Satya,
I just want to create a table that should horizontally display the values like below:
SUID Tag # :123456 Year Mfg: 2007
Description: computer corporation FA ID#: 4576
Model Number: 4569 hESC: #ert
Serial Number: 78945 Flags: c
Department: Hematology
User: thenmozhi
Database: OLAP
I think we can create this type of report using either Narrative or Static Text. But I am not sure whether it is possible or not? And also another thing is that sectioning is applied for SUID Tag # column. So, depending on the dashboard prompt if the SUID Tag # retrieves two or more values.
Then the first value for example 123456 and the values for the other columns related to this SUID Tag # value should display in the first page (i.e., page 1). And if the next value of the SUID Tag # for example say 678901 then the values should move to second page that is like this:
SUID Tag # :678901 Year Mfg: 2008
Description: Computer Manufacturing FA ID#: 4577
Model Number: 4570 hESC: #eth
Serial Number: 78946 Flags: G
Department: Hematology
User: Rehman
Database: OLAP
Thanks
Thenmozhi -
How to create report with dynamic columns with static row labels
Hi All,
I am creating one report as per attached format. I have labels on the right side of the report
and data in 3 columns. The data is taken dynamically from the command query.
It gets data from 3 different result sets/command queries.
I tried creating the report horizontally instead of vertically, but the logo image I am not able to rotate in 270degrees.
Can anybody tell me how to create the report...??Hi Abhilash,
Thanks for the quick reply.
Actually the problem is with the image, as I am not able to rotate 270 degree. Crystal report cannot support the rotation of image.
i have another problem, I have to create a report in which
Lables are fixed on the left side of report and 3 columns per portrait page. Those columns are
dynamically created and shown in the report.
The format is like the above. Can you please help me in doing this report, as I tried it doing
with CrossTab. I am really stuck to this report.
Maybe you are looking for
-
Mac pro and gateway 24 inch display
No more sleep issues as this 2400 gate way works perfect with my pro which has the 7300 gt which is incompatible with some displays with dvi as far as sleep goes
-
How to convert xml to non xml in business service
I have created a business service which routes the data to the respective given email addresses.But the body of the body is in the form of xml tags but need the body to be in normal document type format. I have tried converting xml to mlf format(with
-
I can't download the itunes in my mac book
I can't download the itunes in my mac book,What can I do?
-
Hi there, I just installed Solaris 9 on my HP Vectra machine, I have a Mitsumi CD Writer , is there something like cd writing under solaris, if yes then how can one write a cd in solaris, and where can we find drivers and softwares for burnig cd's un
-
BIOS - Full Theft Protection module Activation - Current setting Permanently disabled
Hi, Recently purchased a Lenevo X301 laptop and installed with Windows XP. Unfortunately while changing the BIOS setiings, i have selected permanently disable option for computrance anti theft agent under Security settings. Now I have settings are as