Home > database >  When performing insert statement, consult everybody bosses how to generate this number 001 001001 00
When performing insert statement, consult everybody bosses how to generate this number 001 001001 00

Time:09-22

001
001001
001001001
001001002
001002
002
002001

CodePudding user response:

This is a tree coding
Get the parent node coding, and then in the spell of the current node code is ok, don't quite understand what you mean,

Select to_char (1, 'fm000) from dual; This statement is generated as a result, 001, how to have a look

CodePudding user response:

Just want to when performing the insert, this is automatically generated the tree coding forms of organization code

CodePudding user response:

Impossible to automatically, can only through the code to achieve

CodePudding user response:

This how to write a stored procedure??? O teach

CodePudding user response:

Such a simple thing it is not necessary to write a stored procedure

Table design? Specific to how to write to see whether the table structure

CodePudding user response:

The select sys_connect_by_path (id, '00')
The from (select level id from dual connect by level & lt; 3) t1
Connect by level & lt; 4.

CodePudding user response:

Just don't know how to splice child node number, can I get the parent node number

CodePudding user response:

String concatenation with | |

CodePudding user response:

I just don't know how to splice now,,,,

CodePudding user response:

The select parent_id | | child_id from dual;
Or
With variable directly
V_ID:=parent_id | | child_id;

CodePudding user response:

Tried, but without a filling, want to insert the 001, 001001, 001002, 001002 this, or take the architectural node number plus 1, also is in the middle of the lost 0 001003 to 1003

CodePudding user response:

If a table node type field is the character of the definition of inside, is not lost 0

How is it you want to get the next node number?
Can consider to grab the current parent node of the architectural codes, converted to integers + 1 and then converted to character

You can stick table structure, so that we can answer more clear

CodePudding user response:

The create table organization
(
Id is an INTEGER not null,
Org_code VARCHAR2 (32) default NULL,
Org_name VARCHAR2 (128) the default NULL,
Org_no VARCHAR2 (32) default NULL,
Parent_id INTEGER default NULL,
The constraint PK_ORGANIZATION primary key (id)
);

This is the table structure, turn again to plastic character also seemed lost 0

CodePudding user response:

How do you convert? Stick the code

CodePudding user response:

The select Max (org_no) + 1 orgNo from uap_organization p where p.p arent_id='1'
Results 1003

CodePudding user response:

The select to_char (Max (org_no) + 1, 'fm000000) orgNo from uap_organization p where p.p arent_id=' 1 '

CodePudding user response:

The writing is better, can need not tube in which the hierarchy
The select to_char (Max (org_no) + 1, rpad (' FM, length (org_no), '0')) orgNo from uap_organization p where p.p arent_id='1'

CodePudding user response:

The select to_char (Max (org_no) + 1, rpad (' FM, length (org_no), '0')) orgNo from uap_organization p where p.p arent_id='1' group by org_no
Results: 1003 0 lost in front of 1002

CodePudding user response:

You are didn't get it, the group identifier,

CodePudding user response:

The select to_char (Max (org_no) + 1, rpad (' FM, length (org_no) + 2, '0')) orgNo from uap_organization p where p.p arent_id='1'

CodePudding user response:

 
Insert into organization
Select the top 1 (select Max (id) + 1 from organization)
, (the select isnull (Max (org_no), ' ') from the organization where id=@ pid) + right (' 000 '+ convert (varchar, Max (
Convert (int,
Right (org_no,
Len (org_no) - len (select Max (org_no) from organization where id=@ pid)
)
)
) + 1
),
Len (select Max (org_no) from organization where id=@ pid) + 3
)
@ orgname,
, @ pid
The from organization
Where parent_id=@ pid

CodePudding user response:

Directly defined as a string!

CodePudding user response:

String concatenation with | |

CodePudding user response:

Directly defined as a string, then pieced together in JS, generally project will be limited number length inside, so need to add a string length judgment and interception
  • Related