JDBC SQL轉義語法是什麼意思?請解釋一下

PHPz
發布: 2023-08-23 20:29:07
轉載
1041 人瀏覽過

JDBC SQL转义语法是什么意思?请解释一下

轉義語法可讓您使用特定於資料庫的功能,這些功能無法透過使用標準的JDBC方法和屬性來實現。

一般的SQL轉義語法格式如下:

{keyword 'parameters'}
登入後複製

Following are various escape syntaxes in JDBC:

d, t, ts Keywords: They help identify date, time, and timestamp literals. As you know, no two DBMSs represent time and date the same way. This escape syntax tells the driver to render the date or time in the target database's for| yyyy = year, mm = month; dd = date. Using this syntax {d '2009-09-03'} is March 9, 2009.

Example

{d 'yyyy-mm-dd'}
登入後複製

escape關鍵字

#escape關鍵字

此關鍵字用於標識在LIKE子句中使用的轉義字元。當使用SQL通配符%,該字元可以匹配零個或多個字元時非常有用。例如−

//Create a Statement object
stmt = conn.createStatement();
//Insert data ==> ID, First Name, Last Name, DOB
String sql="INSERT INTO STUDENTS VALUES" + "(100,'Zara','Ali', {d '2001-12-16'})";
stmt.executeUpdate(sql);
登入後複製

If you use the backslash character (\) as the escape character, you also have to use two backslash characters in your Java String literal, because the backslash is also a Javascape character.

##fn Keyword

This keyword represents scalar functions used in a DBMS. For example, you can use SQL function

length

to get the length of a string −##

String sql = "SELECT symbol FROM MathSymbols WHERE symbol LIKE '\%' {escape '\'}";
stmt.execute(sql);
登入後複製
ee
{fn length('Hello World')}
登入後複製
#這回傳11,字串'Hello World'的長度。呼叫關鍵字

此關鍵字用於呼叫預存程序。例如,對於需要IN參數的預存程序,請使用下列語法−

{call my_procedure(?)};
登入後複製

對於需要一個IN參數並傳回OUT參數的預存程序,請使用下列語法−

{? = call my_procedure(?)};
登入後複製

oj關鍵字

該關鍵字用於表示外連接。語法如下−

{oj outer-join}
登入後複製

Where outer-join = table {LEFT|RIGHT|FULL} OUTERJOIN {table | outer-join} on search-condition.

String sql = "SELECT Employees FROM {oj ThisTable RIGHT OUTER JOIN ThatTable on id = '100'}";
stmt.execute(sql);
登入後複製

以上是JDBC SQL轉義語法是什麼意思?請解釋一下的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:tutorialspoint.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!