Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- palec@Palec:~$ mysql
- Reading table information for completion of table and column names
- You can turn off this feature to get a quicker startup with -A
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 134
- Server version: 5.1.49-3~bpo50+1 (Debian)
- Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
- This software comes with ABSOLUTELY NO WARRANTY. This is free software,
- and you are welcome to modify and redistribute it under the GPL v2 license
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- mysql> CREATE TABLE clients (clientNum VARCHAR(11) NOT NULL, name VARCHAR(20) NOT NULL, PRIMARY KEY (clientNum));
- Query OK, 0 rows affected (0.00 sec)
- mysql> INSERT INTO clients VALUES('000-100-000', 'A'),('000-000-100', 'B'),('500-000-000', 'C');
- Query OK, 3 rows affected (0.00 sec)
- Records: 3 Duplicates: 0 Warnings: 0
- mysql> INSERT INTO clients SELECT INSERT(INSERT(LPAD(CAST(COALESCE(MAX(CAST(REPLACE(clientNum, '-', '') AS UNSIGNED)), 0) + 1 AS CHAR), 9, '0'), 7, 0, '-'), 4, 0, '-'),'John Doe' FROM clients WHERE clientNum BETWEEN '000-100-000' AND '000-199-999';
- Query OK, 1 row affected (0.00 sec)
- Records: 1 Duplicates: 0 Warnings: 0
- mysql> SELECT * FROM clients;
- +-------------+----------+
- | clientNum | name |
- +-------------+----------+
- | 000-100-000 | A |
- | 000-000-100 | B |
- | 500-000-000 | C |
- | 000-100-001 | John Doe |
- +-------------+----------+
- 4 rows in set (0.01 sec)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement