回答
使用組()
和或|
運營商例如驗證用戶輸入您做前人的精力:
set serveroutput on;
declare
l_value varchar2(32767) := '<p>test and data</p>';
begin
if regexp_like(l_value,'(<|>)','i') then
dbms_output.put_line('invalid');
else
dbms_output.put_line('valid');
end if;
end;
/
好運。
使用[
和]
來定義要匹配的一組字符,例如, [abc]
,[a-z]
,
select string
, case
when regexp_like(string,'[<>]') then 'Invalid'
else 'Valid'
end as test
from
(select '<p>text</p>' as string from dual union all
select 'text' from dual);
STRING TEST
---------------- -------
<p>text</p> Invalid
text Valid
或者在PL/SQL:
declare
teststring varchar2(100) := '<p>test and data</p>';
regex varchar2(100) := '[<>]';
begin
dbms_output.put('"'||teststring||'"');
dbms_output.put(case when regexp_like(teststring,regex) then ' matches ' else ' does not match ' end);
dbms_output.put(regex);
dbms_output.new_line();
end;
/
"<p>test and data</p>" matches [<>]
PL/SQL procedure successfully completed
作爲檢查約束:
create table mytable
(col varchar2(20)
constraint mytable_ltgt_chk check (not regexp_like(col,'[<>]'))
);
測試:
insert into mytable (col) values ('kitten > puppy');
拒絕了:
ORA-02290: check constraint (MYRIAD_OWNER_82.MYTABLE_LTGT_CHK) violated
如果你想排除方括號內爲好,這將是:
constraint mytable_symbol_chk check (not regexp_like(col,'[][<>]'));
或沒有任何正則表達式:
constraint mytable_symbol_chk check (col = translate(col,'[]<>','.'))
這也非常有幫助。如果我不需要'['或']'符號怎麼辦?在這種情況下會有幫助嗎? –
你的意思是你想檢查文本是否包含符號'['或']'?只需將它們包含在正則表達式中即可。 –
嗨,我想要的是,我想對列值設置一個約束,以允許除< or >之外的所有內容。所以我想嘗試像ALTER TABLE mytable ADD CONSTRAINT「mytable_CHK」CHECK((REGEXP_LIKE(col,^'(<|>)','i')))。不知道它會以這種方式工作。 –
- 1. 如何限制在文本框中輸入的任何特殊字符
- 2. 如何使用jquery阻止或限制輸入字段中的特殊字符?
- 3. 限制特殊字符
- 4. 在輸入中插入特殊字符
- 5. 如何在Vim中回顯特殊字符,如%,<cfile>?
- 6. 限制用戶輸入特殊字符和數字
- 7. 通過ng-pattern在輸入字段中限制少量特殊字符
- 8. 如何在jQuery中對特殊字符(>,<,%)進行編碼
- 9. 如何在jquery中輸入特殊字符後檢索字符?
- 10. Python:如何將字符串包含在列表中< and >
- 11. 我不希望用戶輸入!@ ## $%$#*&&< - 這些特殊字符在我的TextField中..如何限制這個?
- 12. jquery在ID中輸入特殊字符
- 13. 在Excel VBA中輸入特殊字符
- 14. On Key Down限制用戶輸入一些特殊字符
- 15. 如何限制searchView中的特殊字符和數字?
- 16. 如何限制objective-c中的數字和特殊字符
- 17. 允許特殊字符輸入密碼
- 18. 使用jQuery限制特殊字符
- 19. 如何刪除「<" and ">」之間的所有字符,包括「<" and ">」?
- 20. 如何將<input>中的特殊字符轉換爲轉義序列
- 21. 如何阻止HTML輸入字段中的特殊字符?
- 22. 阻止在PHP中輸入作爲輸入的特殊字符
- 23. 特殊列的mysql限制
- 24. 如何使用xamarin限制iOS中的特殊字符?
- 25. 如何限制asp.net文本框中特殊字符的組合?
- 26. 如何限制輸入的字符數
- 27. 檢查特殊符號的輸入值
- 28. 如何在cmd中輸入特殊字符?
- 29. 如何在vi編輯器中輸入特殊字符
- 30. 如何在oracle數據庫中輸入「§」等特殊字符?
哇! !非常感謝你,那很準確。我正在嘗試什麼不..再次感謝。 –
嗨,如果我在您的有效案例字符串中使用< or >,它仍然顯示有效,但現在應該變爲無效。 –
@SachinVaidya請注意,有效的案例已被註釋掉,在提供的示例中,我必須編輯答案以防止模棱兩可的解釋。威廉羅伯遜說,其他變化將起作用。 – Ftaveras