2013-02-04 2 views
2

dbms_output 문에 작은 따옴표를 포함해야합니다. 나는 이것을 시도했다 :
dbms_output 문에서 작은 따옴표가 사용됩니까?

dbms_output.put_line('\''first_name||'\''); 

을 여기 variable FIRST_NAME입니다; 이 작은 따옴표 안에 표시해야합니다.

+0

first_name이 xyx를 유지하면 내 출력이 'xyz'가됩니다. 이것은 내가 얻으려고 한 것입니다. –

+0

[Oracle SQL에서 작은 따옴표를 처리하는 방법] 가능한 복제본 (http://stackoverflow.com/questions/2875257/how-to-handle-a-single-quote-in-oracle-sql) –

+0

가능한 중복 [Oracle SQL에서 작은 따옴표를 처리하는 방법] (https://stackoverflow.com/questions/2875257/how-to-handle-a-single-quote-in-oracle-sql) –

답변

7

당신이 배에서 탈출 것 :

dbms_output.put_line('''' || first_name || ''''); 

또는 q-quote 메커니즘을 사용하여 :

dbms_output.put_line(q'[']'||first_name||q'[']'); 

예 : 이것은 단지 PL/SQL에 대한 것을

SQL> var b1 varchar2(30) 
SQL> exec :b1 := 'this is a test'; 

PL/SQL procedure successfully completed. 

SQL> exec dbms_output.put_line(q'[']'||:b1||q'[']'); 
'this is a test' 

PL/SQL procedure successfully completed. 

SQL> exec dbms_output.put_line(''''||:b1||''''); 
'this is a test' 

PL/SQL procedure successfully completed. 

SQL> exec dbms_output.put_line(chr(39)||:b1||chr(39)); 
'this is a test' 

PL/SQL procedure successfully completed. 
+0

2 초 안에 나에게 이길 수있다. :) – Randy

+0

나중에 나는 첫 번째 하나를 사용하여 출력을 가지고있어하지만 지루한 너무 구조가없는 것 같다! 복용 두 번째 작품 하나? –

+0

@Thiyagu 네, 맞습니다. – DazzaL

0

주 활성화되어 있어야합니다.

begin 
DBMS_OUTPUT.PUT_LINE('DELETE FROM MYTABLE WHERE MYFIELD <> ''A'';'); 
end; 
/

CHAR 'A'와 일치한다고 가정합니다.

관련 문제