Oracle PL/SQL/Select Query/Quote
Содержание
- 1 Alternative Quoting Mechanism in Oracle 10g: two quotes really means one quote
- 2 q"{32 O"Hara Avenue}"): Use a "q" as the leading character after the parentheses
- 3 Quoted Identifiers
- 4 Quoting syntax is q"[ ... ]" where the [] is the user-defined
- 5 Using two single-quotes print the string correctly
Alternative Quoting Mechanism in Oracle 10g: two quotes really means one quote
SQL> create table TestTable(
2 ID VARCHAR2(4 BYTE) NOT NULL,
3 Description VARCHAR2(30 BYTE)
4 )
5 /
Table created.
SQL>
SQL>
SQL> insert into TestTable (ID, Description) values("1","1234 5th Street");
1 row created.
SQL> insert into TestTable (ID, Description) values("2","1 Culloden Street");
1 row created.
SQL> insert into TestTable (ID, Description) values("3","1234 Road");
1 row created.
SQL> insert into TestTable (ID, Description) values("4","33 Thrid Road");
1 row created.
SQL> insert into TestTable (ID, Description) values("5","One than another");
1 row created.
SQL> insert into TestTable (ID, Description) values("6","2003 Movie");
1 row created.
SQL> insert into TestTable (ID, Description) values("7","Start With Letters");
1 row created.
SQL>
SQL> select * from TestTable;
ID DESCRIPTION
---- ------------------------------
1 1234 5th Street
2 1 Culloden Street
3 1234 Road
4 33 Thrid Road
5 One than another
6 2003 Movie
7 Start With Letters
7 rows selected.
SQL>
SQL> -- Alternative Quoting Mechanism in Oracle 10g
SQL>
SQL> -- two quotes really means one quote
SQL>
SQL> INSERT INTO testTable VALUES (99,"32 O""Neal Drive");
1 row created.
SQL>
SQL> select * from testTable;
ID DESCRIPTION
---- ------------------------------
1 1234 5th Street
2 1 Culloden Street
3 1234 Road
4 33 Thrid Road
5 One than another
6 2003 Movie
7 Start With Letters
99 32 O"Neal Drive
8 rows selected.
SQL>
SQL>
SQL>
SQL> drop table TestTable;
Table dropped.
SQL>
SQL>
SQL>
q"{32 O"Hara Avenue}"): Use a "q" as the leading character after the parentheses
SQL> create table TestTable(
2 ID VARCHAR2(4 BYTE) NOT NULL,
3 Description VARCHAR2(30 BYTE)
4 )
5 /
Table created.
SQL>
SQL>
SQL> insert into TestTable (ID, Description) values("1","1234 5th Street");
1 row created.
SQL> insert into TestTable (ID, Description) values("2","1 Culloden Street");
1 row created.
SQL> insert into TestTable (ID, Description) values("3","1234 Road");
1 row created.
SQL> insert into TestTable (ID, Description) values("4","33 Thrid Road");
1 row created.
SQL> insert into TestTable (ID, Description) values("5","One than another");
1 row created.
SQL> insert into TestTable (ID, Description) values("6","2003 Movie");
1 row created.
SQL> insert into TestTable (ID, Description) values("7","Start With Letters");
1 row created.
SQL>
SQL> select * from TestTable;
ID DESCRIPTION
---- ------------------------------
1 1234 5th Street
2 1 Culloden Street
3 1234 Road
4 33 Thrid Road
5 One than another
6 2003 Movie
7 Start With Letters
7 rows selected.
SQL>
SQL>
SQL> --Uses a "q" as the leading character after the parentheses and allows specification
of a "different" sequence to define quotes
SQL>
SQL> INSERT INTO testTable VALUES (99, q"{32 O"Hara Avenue}");
1 row created.
SQL>
SQL> select * from testTable;
ID DESCRIPTION
---- ------------------------------
1 1234 5th Street
2 1 Culloden Street
3 1234 Road
4 33 Thrid Road
5 One than another
6 2003 Movie
7 Start With Letters
99 32 O"Hara Avenue
8 rows selected.
SQL>
SQL> drop table TestTable;
Table dropped.
SQL>
SQL>
Quoted Identifiers
SQL> DECLARE
2 "End" NUMBER := 1;
3 BEGIN
4 dbms_output.put_line("A quoted identifier End ["||"End"||"]");
5 END;
6 /
A quoted identifier End [1]
PL/SQL procedure successfully completed.
SQL>
Quoting syntax is q"[ ... ]" where the [] is the user-defined
SQL>
SQL>
SQL> BEGIN
2 DBMS_OUTPUT.PUT_LINE("Colorado""s National Parks are BEAUTIFUL");
3 END;
4 /
Colorado"s National Parks are BEAUTIFUL
PL/SQL procedure successfully completed.
SQL> BEGIN
2 DBMS_OUTPUT.PUT_LINE(q"!Colorado"s National Parks are BEAUTIFUL!");
3 END;
4 /
Colorado"s National Parks are BEAUTIFUL
PL/SQL procedure successfully completed.
SQL> BEGIN
2 DBMS_OUTPUT.PUT_LINE(q"[Colorado"s National Parks are BEAUTIFUL]");
3 END;
4 /
Colorado"s National Parks are BEAUTIFUL
PL/SQL procedure successfully completed.
SQL> BEGIN
2 DBMS_OUTPUT.PUT_LINE(q"<Colorado"s National Parks are BEAUTIFUL>");
3 END;
4 /
Colorado"s National Parks are BEAUTIFUL
PL/SQL procedure successfully completed.
SQL> BEGIN
2 DBMS_OUTPUT.PUT_LINE(q"%Colorado"s National Parks are BEAUTIFUL%");
3 END;
4 /
Colorado"s National Parks are BEAUTIFUL
PL/SQL procedure successfully completed.
Using two single-quotes print the string correctly
SQL>
SQL> BEGIN
2 DBMS_OUTPUT.PUT_LINE("C""s");
3 END;
4 /
C"s
PL/SQL procedure successfully completed.