Such as:
'15012341234', '4161123' can add right
Add '4161123 a', 'a4161123', 'aaaaaaa', '4161 a123, 15012341234 will be displayed in violation of the constraint condition
Someone's solution is to check on baidu (phoneNumber not like '% [^ 0-9] %) but add a string containing the letter can also add success, what should be how to implement the
In the up sqlplus
CodePudding user response:
SQL>
SQL> Create table test (ph varchar (20));
The Table created
SQL> The alter table test add constraint ck_test check (not regexp_like (ph, '[^ 0-9]));
Table altered
SQL> Insert into test values (' 111111 ');
1 row inserted
SQL> Insert into test values (' A1111 ');
Insert into test values (' A1111)
ORA - 02290: a violation of check constraint conditions (ORACLE. CK_TEST)
SQL> Insert into test values (' ABC ');
Insert into test values (' ABC ')
ORA - 02290: a violation of check constraint conditions (ORACLE. CK_TEST)
SQL> Insert into test values (' 111 ');
Insert into test values (' 111 ')
ORA - 02290: a violation of check constraint conditions (ORACLE. CK_TEST)
SQL> Insert into test values (' 111 aa111 ');
Insert into test values (' 111 aa111)
ORA - 02290: a violation of check constraint conditions (ORACLE. CK_TEST)
SQL> Insert into test values (' Chinese people ');
Insert into test values (' Chinese people ')
ORA - 02290: a violation of check constraint conditions (ORACLE. CK_TEST)
SQL> Select * from the test;
PH
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
111111
SQL> Drop table test purge;
Table dropped
SQL>
CodePudding user response: