英文:
I want to replace '&' character with '&' in SQL
问题
以下是翻译好的部分:
这是一个特殊需求,他们希望将此结果用于部署。请查找所有DDL和DML命令以及我的尝试。
CREATE TABLE my_table (
my_column VARCHAR2(100)
);
INSERT INTO my_table (my_column) VALUES ('Apples & Bananas');
SELECT REPLACE(my_column, '&', '&') AS modified_column
FROM my_table;
SELECT REPLACE(my_column, CHR(38), '&') AS modified_column
FROM my_table;
请提供一个SQL查询以获得结果。
我得到的输出:
MY_COLUMN
Apples & Bananas
我想要的输出:
MODIFIED_COLUMN
Apples & Bananas
英文:
This is special requirnment this result they want to use for there deployment .please find all ddl and dml commands with my trials
CREATE TABLE my_table (
my_column VARCHAR2(100)
);
INSERT INTO my_table (my_column) VALUES ('Apples & Bananas');
SELECT REPLACE(my_column, '&', '&') AS modified_column
FROM my_table;
SELECT REPLACE(my_column, CHR(38), '&') AS modified_column
FROM my_table;
Please suugest a sql query which will give result
Output I am getting:
MY_COLUMN
Apples & Bananas
Output I want:
MODIFIED_COLUMN
Apples & Bananas
答案1
得分: 2
你的目标字符 &
和替换字符 &
是相同的。替换应该是 &
:
SELECT REPLACE(my_column, ''&'', ''&'') AS modified_column
FROM my_table;
查看 在线演示。
但实际上,你不应该以这种方式进行 HTML 转义。相反,应该使用具有适当的 HTML 转义函数的编程语言,例如 JavaScript 或 Python。
英文:
Your target character &
and replacement &
are the same thing. The replacement should be &
:
<!-- language: sql -->
SELECT REPLACE(my_column, '&', '&amp;') AS modified_column
FROM my_table;
See live demo.
But really you shouldn't be doing HTML escaping this way. Rather, use a programming language which has a proper HTML escaping function, such as JavaScript or Python.
答案2
得分: 0
SQL> set define off
SQL> CREATE TABLE my_table
2 (
3 my_column VARCHAR2 (100)
4 );
Table created.
SQL> INSERT INTO my_table (my_column)
2 VALUES ('Apples & Bananas');
1 row created.
SQL> SELECT * FROM my_table;
MY_COLUMN
Apples & Bananas
SQL> UPDATE my_table
2 SET my_column = REPLACE (my_column, '&', '&');
1 row updated.
SQL> SELECT * FROM my_table;
MY_COLUMN
Apples & Bananas
SQL>
英文:
replace should work OK.
SQL> set define off
SQL> CREATE TABLE my_table
2 (
3 my_column VARCHAR2 (100)
4 );
Table created.
SQL> INSERT INTO my_table (my_column)
2 VALUES ('Apples & Bananas');
1 row created.
SQL> SELECT * FROM my_table;
MY_COLUMN
--------------------------------------------------------------------------------
Apples & Bananas
SQL> UPDATE my_table
2 SET my_column = REPLACE (my_column, '&', '&amp;');
1 row updated.
SQL> SELECT * FROM my_table;
MY_COLUMN
--------------------------------------------------------------------------------
Apples &amp; Bananas
SQL>
答案3
得分: 0
你尝试过这样吗:
SELECT REPLACE(my_column, '&', '&') AS modified_column FROM my_table;
因为您当前的替换字符与'&'相同。所以,请使用'&'代替。
英文:
Have you tried this:
SELECT REPLACE(my_column, '&', '&amp;') AS modified_column FROM my_table;
as your current and replace characters are same '&'. So, use '&' instead.
答案4
得分: 0
尝试将字符串值中的 '&' 分离,如下所示:
SELECT REPLACE(my_column, ''&'', ''&&'') AS modified_column
FROM my_table
英文:
Try to separate '&' in the String value like:
SELECT REPLACE(my_column, '&', '&'||'amp;') AS modified_column
FROM my_table
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论