In an Oracle database table, how do you produce a letter + number when inserting data?

Source: Internet
Author: User

"| |" in Oracle statement What does it mean?in an Oracle database table, how do you produce a letter + number when inserting data?
Sort, you can do it with order by.
Like what:
Col
A123
a234
b999
b335
SELECT * FROM tablename order by Col;

The result is

Col
A123
a234
b335
b999

If ordered in reverse order:
SELECT * FROM tablename order by Col Desc;

The result is

Col
b999
b335
a234
A123
Other answersfirst create a sequence
Then write a trigger;before insert for the table that inserts the data to set the value of this field to
sd| | Sequence.nextvalAsk
Not very clear, do not know the eldest brother, can you put out an example ...
Chase Answer
Create sequence seq_1 start with 1 nocache;
Seq_1 is a sequence name
The triggers are as follows:

Create TRIGGER XXX_ID_TRG--trigger name
Before insert



: new.column_name:=sd| | Lpad (seq_1.nextval,6, ' 0 ');
End
Ask
--users is a table name, including two fields, u_id and U_name
--seq_1 is a sequence name
--U_ID is the column name, which is the column to generate the number, type VARCHAR2
--the sequence has been created with the name Seq_1
Create Trigger USER_ID_TRG
Before insert
On users


: new.u_id:=sd| | Lpad (seq_1.nextval,6, ' 0 ');
End
--Error when executing INSERT, invalid trigger
Insert into users (u_name) VALUES (' a ')
More questioning this answer was adopted by the questioner Moreazy | posted on 2012-03-22 Report | Reviews================= 2 0 Create sequence table name _seq increment by 1 start with 100000001 NoCache;

Insert into table name (field, field, field, field)
VALUES (' SD ' | | Table name _seq.nextval, ' Zhang San ', ' 123 ', ' Y ');

This thing does not have any logic, do not know the landlord exactly how to effectAsk
Well, that makes sense, how to produce a letter + date + number (number is self-increasing) For example:  AC20120330001 code?
Patooo | posted on 2012-03-27 Report | Reviews============= 2 0 build a self-increment column ID, like 000001. So sd| | The ID is equal to SD000001.

In an Oracle database table, how do you produce a letter + number when inserting data?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.