"| |" 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?