powerbuilder的SQL語句

PB的sql語句以怜俐;結束翠胰,可寫成多行形式而不用&

1韧拒、SELECT

一個例子:

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="sql" cid="n5" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">SELECT Employee.Emp_id,Employee.Emp_name, Employee.Emp_salary,Dept.Dept_name
FROM Employee,Dept
WHERE (Emp_name like ''''張%'''') AND (Emp_sex=''''男'''') AND Employee.Dept_id=Dept.Dept_id
ORDER BY Employee.Emp_id; </pre>

給變量的例子:

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="sql" cid="n7" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">Dec Emp_salary
SELECT max(Emp_salary) INTO :Emp_salary FROM Employee;</pre>

注意:變量前加‘:’ ,sql語句不需要加‘$’

2贞谓、INSERT

一個例子:

emp_tran為數據庫事務對象限佩,一般在主窗口就會用settransobject()函數關聯(lián)這個事務對象

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="sql" cid="n12" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">Int Emp_nbr
String Emp_name
Emp_nbr=Integer(sle_number.Text)
Emp_name=sle_name.Text
INSERT INTO Employee(employee.Emp_nbr,employee.Emp_name)
VALUES(:Emp_nbr,:Emp_name) USING Emp_tran; </pre>

3、UPDATE

UPDATE 表名稱 SET 列名稱 = 新值 WHERE 列名稱 = 某值裸弦,更新某一行中的若干列祟同,例如:

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n15" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">UPDATE Person
SET Address = 'Zhongshan 23', City = 'Nanjing'
WHERE LastName = 'Wilson'</pre>

一個例子:

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="sql" cid="n17" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">int Emp_num
Emp_num=Integer(sle_Number.Text )
UPDATE Employee
SET emp_name = :sle_Name.Text
WHERE Employee.emp_num = :Emp_num
USING Emp_tran ;
IF Emptran.SQLNRows > 0 THEN
COMMIT USING Emp_tran ;
messagebox('恭喜', '已經成功更新數據庫!')
else
rollback using sqlca;
messagebox('提示', '更新數據庫失敗!')
END IF</pre>

注:有些實例沒有commit,但update后也可以同步到數據庫理疙,原因如下

4晕城、DELETE

一個例子:

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="sql" cid="n22" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">DELETE FROM Employee //從表Employee
WHERE Emp_nbr <100;刪除條件滿足的記錄 </pre>

5、CONNECT和DISCONNECT

執(zhí)行DISCONNECT前自動執(zhí)行COMMIT

6窖贤、COMMIT和ROLLBACK

上述為嵌入式sql語句砖顷,更多的是用動態(tài)sql贰锁,參考:https://blog.csdn.net/ClearLoveQ/article/details/83277640

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市滤蝠,隨后出現的幾起案子豌熄,更是在濱河造成了極大的恐慌,老刑警劉巖物咳,帶你破解...
    沈念sama閱讀 216,544評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件锣险,死亡現場離奇詭異,居然都是意外死亡览闰,警方通過查閱死者的電腦和手機囱持,發(fā)現死者居然都...
    沈念sama閱讀 92,430評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來焕济,“玉大人纷妆,你說我怎么就攤上這事∏缙” “怎么了掩幢?”我有些...
    開封第一講書人閱讀 162,764評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長上鞠。 經常有香客問我际邻,道長,這世上最難降的妖魔是什么芍阎? 我笑而不...
    開封第一講書人閱讀 58,193評論 1 292
  • 正文 為了忘掉前任世曾,我火速辦了婚禮,結果婚禮上谴咸,老公的妹妹穿的比我還像新娘轮听。我一直安慰自己,他們只是感情好岭佳,可當我...
    茶點故事閱讀 67,216評論 6 388
  • 文/花漫 我一把揭開白布血巍。 她就那樣靜靜地躺著,像睡著了一般珊随。 火紅的嫁衣襯著肌膚如雪述寡。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,182評論 1 299
  • 那天叶洞,我揣著相機與錄音鲫凶,去河邊找鬼。 笑死衩辟,一個胖子當著我的面吹牛螟炫,可吹牛的內容都是我干的。 我是一名探鬼主播惭婿,決...
    沈念sama閱讀 40,063評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼不恭,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了财饥?” 一聲冷哼從身側響起换吧,我...
    開封第一講書人閱讀 38,917評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎钥星,沒想到半個月后沾瓦,有當地人在樹林里發(fā)現了一具尸體,經...
    沈念sama閱讀 45,329評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡谦炒,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,543評論 2 332
  • 正文 我和宋清朗相戀三年贯莺,在試婚紗的時候發(fā)現自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片宁改。...
    茶點故事閱讀 39,722評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡缕探,死狀恐怖,靈堂內的尸體忽然破棺而出还蹲,到底是詐尸還是另有隱情爹耗,我是刑警寧澤,帶...
    沈念sama閱讀 35,425評論 5 343
  • 正文 年R本政府宣布谜喊,位于F島的核電站潭兽,受9級特大地震影響,放射性物質發(fā)生泄漏斗遏。R本人自食惡果不足惜山卦,卻給世界環(huán)境...
    茶點故事閱讀 41,019評論 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望诵次。 院中可真熱鬧账蓉,春花似錦、人聲如沸逾一。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,671評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽嬉荆。三九已至归敬,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間鄙早,已是汗流浹背汪茧。 一陣腳步聲響...
    開封第一講書人閱讀 32,825評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留限番,地道東北人舱污。 一個月前我還...
    沈念sama閱讀 47,729評論 2 368
  • 正文 我出身青樓,卻偏偏與公主長得像弥虐,于是被迫代替她去往敵國和親扩灯。 傳聞我的和親對象是個殘疾皇子媚赖,可洞房花燭夜當晚...
    茶點故事閱讀 44,614評論 2 353

推薦閱讀更多精彩內容

  • 一:不要讓Oracle做得太多 1.避免復雜的多表關聯(lián) 2.避免使用 ‘ * ‘ (1)當你想在SELECT子句中...
    程序猿小小白閱讀 726評論 0 0
  • 一、事務概念 事務是一種機制珠插、是一種操作序列惧磺,它包含了一組數據庫操作命令,這組命令要么全部執(zhí)行捻撑,要么全部不執(zhí)行磨隘。因...
    清茶了了_閱讀 361評論 0 1
  • java事務的處理 轉 https://www.cnblogs.com/Bonker/p/5417967.html...
    小小的Jobs閱讀 1,388評論 0 1
  • 我們要做到不但會寫SQL,還要做到寫出性能優(yōu)良的SQL,以下為筆者學習、摘錄顾患、并匯總部分資料與大家分享番捂! (1) ...
    安易學車閱讀 474評論 0 4
  • 1. 了解SQL 1.1 數據庫基礎 ? 學習到目前這個階段,我們就需要以某種方式與數據庫打交道江解。在深入學習MyS...
    鋒享前端閱讀 1,066評論 0 1