2012-10-03 9 views
8

कैरियर रिटर्न के साथ एक वर्चर कॉलम मान समाप्त होता है या नहीं, यह जांचने का सही तरीका जानने का प्रयास कर रहा है। इस कोशिश की, लेकिन यह काम नहीं करता, डेटाबेस Oracle 11g है ...एसक्यूएल क्वेरी जांचने के लिए कि क्या स्ट्रिंग वैल्यू में कैरिज रिटर्न

select name from myTable where name LIKE '%\r' OR name like '%\n' 

उत्तर

5

प्रयास करें कि इस तरह की गाड़ी वापसी या खड़ी टैब या पंक्ति के अंत के रूप में प्रिंट न हो सकने वर्ण हैं एक मूल्य जानने के लिए आप regexp_like फ़ंक्शन का उपयोग कर सकते हैं। आपके मामले में पंक्तियां प्रदर्शित करने के लिए जहां किसी विशेष कॉलम के स्ट्रिंग मान में अंत में कैरिज रिटर्न होता है, उसी तरह की क्वेरी का उपयोग किया जा सकता है।

select * 
    from your_table_name 
where regexp_like(trim(string_column), '[[:space:]]$') 

Demo


टिप्पणी

Trim समारोह डिफ़ॉल्ट रूप से, प्रमुख और रिक्त स्थान अनुगामी हटाने से करने के लिए उत्तर और यह पंक्ति का गाड़ी वापसी या अंत नहीं हटेंगे अक्षर। एक साधारण परीक्षण बाहर ले जाने की सुविधा देता है:

SQL> create table Test_Table(
    2 id number, 
    3 col1 varchar2(101) 
    4 ); 

Table created 

SQL> insert into Test_Table (id, col1) 
    2 values(1, 'Simple string'); 

1 row inserted 

SQL> commit; 

Commit complete 

SQL> insert into Test_Table (id, col1) 
    2 values(1, 'Simple string with carriage return at the end' || chr(13)); 

1 row inserted 

SQL> commit; 

Commit complete 

SQL> insert into Test_Table (id, col1) 
    2 values(1, ' Simple string with carriage return at the end leading and trailing spaces' || chr(13)||' '); 

1 row inserted 

SQL> commit; 

Commit complete 

SQL> insert into Test_Table (id, col1) 
    2 values(1, ' Simple string leading and trailing spaces '); 

1 row inserted 

SQL> commit; 

Commit complete 

SQL> select * 
    2 from test_table; 

     ID COL1 
-------------------------------------------------------------------------------- 
     1 Simple string 
     1 Simple string with carriage return at the end 
     1 Simple string with carriage return at the end leading and trailing spaces 
     1 Simple string leading and trailing spaces 

SQL> 
SQL> select * 
    2 from test_table 
    3 where regexp_like(trim(col1), '[[:space:]]$') 
    4 ; 

     ID COL1 
---------------------------------------------------------------------------------- 
     1 Simple string with carriage return at the end 
     1 Simple string with carriage return at the end leading and trailing spaces 

SQL> 
+0

'[[: space:]] $ 'का क्या हिस्सा वास्तव में कैरिज रिटर्न की जांच कर रहा है? क्या यह '$' है? – raffian

+0

'[[: space:]]' - कैरिज रिटर्न की तलाश (और उत्तर में उल्लिखित अन्य गैर-प्रिंट करने योग्य वर्ण)। '$' - स्ट्रिंग के अंत में मैचों की खोज करें। –

+0

मैंने कोशिश की, लेकिन यह अंत में रिक्त स्थान के साथ कॉलम उठा रहा है, निश्चित रूप से कैरिज रिटर्न वाले लोगों पर छोड़ रहा है ... बीटीडब्लू, एसक्यूएलफ़िल्ड के लिए +1! – raffian

10

SELECT name from myTable where name like '%'||chr(10) or name like '%'||chr(13) 
+1

सही संख्या के लिए डेटाबेस वर्ण सेट पर निर्भर करेगा उपयोग करने के लिए [वर] चार [2] प्रकार और डेटाबेस राष्ट्रीय चरित्र एन [वर] चार [2] प्रकार के लिए निर्धारित किया है। (इस जवाब में ईबीसीडीआईसी का उपयोग करने वाले किसी भी मौके पर टिप्पणी की गई।) –

संबंधित मुद्दे