How to enter a single quotation mark in Oracle?
2009-03-23 21:26
591 查看
Answer: Although this may be a undervalued question, I got many a search for my blog with this question. This is where I wanted to address this question elaborately or rather in multiple ways.
The output of the above statement would be:
test single quote'
Simply stating you require an additional single quote character to print a single quote character. That is if you put two single quote characters Oracle will print one. The first one acts like an escape character.
This is the simplest way to print single quotation marks in Oracle. But it will get complex when you have to print a set of quotation marks instead of just one. In this situation the following method works fine. But it requires some more typing labour.
The same example inside PL/SQL I will use like following:
The output above is same as the Method 1.
Now my favourite while in SQL is CHR(39) function. This is what I would have used personally:
The output is same in all the cases.
Now don't ask me any other methods, when I come to know of any other methods I will share here.
Regards,
Anantha
Method 1
The most simple and most used way is to use a single quotation mark with two single quotation marks in both sides.SELECT 'test single quote''' from dual;
The output of the above statement would be:
test single quote'
Simply stating you require an additional single quote character to print a single quote character. That is if you put two single quote characters Oracle will print one. The first one acts like an escape character.
This is the simplest way to print single quotation marks in Oracle. But it will get complex when you have to print a set of quotation marks instead of just one. In this situation the following method works fine. But it requires some more typing labour.
Method 2
I like this method personally because it is easy to read and less complex to understand. I append a single quote character either from a variable or use the CHR() function to insert the single quote character.The same example inside PL/SQL I will use like following:
DECLARE l_single_quote CHAR(1) := ''''; l_output VARCHAR2(20); BEGIN SELECT 'test single quote'||l_single_quote INTO l_output FROM dual; DBMS_OUTPUT.PUT_LINE(l_single_quote); END;
The output above is same as the Method 1.
Now my favourite while in SQL is CHR(39) function. This is what I would have used personally:
SELECT 'test single quote'||CHR(39) FROM dual;
The output is same in all the cases.
Now don't ask me any other methods, when I come to know of any other methods I will share here.
Regards,
Anantha
相关文章推荐
- How to adjust the high watermark in ORACLE 10g -- ALTER TABLE SHRINK
- How to display column values in a single cell in Web Intelligence using Oracle database ?
- Learn How To Attach PL/SQL Library In Oracle Forms
- How to find Master Node in Oracle RAC
- How to enter text into a textfield in a web view using UIAutomation
- How to Delete From or Add Resource to OCR in Oracle Clusterware (文档 ID 1069369.1)
- How To Access Forms Directly In Oracle Applications R12 [ID 552301.1]
- How to use expdp/empdp in Oracle Database (使用expdp/impdp导入导出oracle数据 )
- How to change the language of oracle sqlplus from chinese to english in windows(如何将oracle sql plus中的中文变成英文版)
- How to switch to another database in oracle 11g(如何在oracle中从一个数据库切换到另一个数据库)
- how to reset sys password in oracle
- How to enter deep idle with USB plugged in (Used For Debugging)
- How to refresh materialized view in oracle
- How to Modify Private Network Information in Oracle Clusterware [ID 283684.1]
- How to install oracle by Command Line Interface(CLI) in silent mode on Linux
- How to add Oracle JDBC driver in your Maven local repository
- How to Turn On “About This Page” in Oracle R12 OAF Pages
- How to Check Whether Oracle Binary/Instance is RAC Enabled and Relink Oracle Binary in RAC (文档 ID 28
- HOW TO Kill The Running Job in Oracle
- Shell: how to list all db links in oracle DB to generate a flat file (生成dblink列表文件)