首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Real SQL Programming

Real SQL Programming

作者头像
小陈又菜
发布2025-12-23 16:28:43
发布2025-12-23 16:28:43
130
举报

SQL in Real Programs

  • We have seen only how SQL is used at the generic query interface --- an environment where we sit at a terminal and ask queries of a database.
  • Reality is almost always different:

conventional programs interacting with SQL.

(我们只是看见了SQL是如何在常规的查询接口中的使用,也就是直接通过终端 对数据库进行交互,但实际上通常是常规程序与SQL语言的交互)

Options

  • Code in a specialized language is stored in the database itself (e.g.PSM, PL/SQL).
  • SQL statements are embedded in a host language (e.g., C).
  • Connection tools are used to allow a conventional language to access a database (e.g., CLI, JDBC, PHP/DB).

(常规程序与SQL语言的交互模式: 数据库储存代码、SQL内嵌、连接工具)

Stored Procedures

  • PSM, or “persistent stored modules, ” allows us to store procedures as database schema elements.(持久储存模块允许我们将储存模式作为数据库模式元素)
  • PSM = a mixture of conventional statements (if, while, etc.) and SQL.
  • Lets us do things we cannot do in SQL alone.

数据库中的储存过程和函数的区别在于,函数可以直接通过函数名的引用得到函数值,但是储存过程不行

Advantages of Stored Procedures

  • Share Application Logic(共享应用逻辑)
  • Shield Database Schema Details(屏蔽数据库细节)
  • Provide Security Mechanisms(提供安全机制 )
  • Improve Performance(提升性能)
  • Reduce Network Traffic(减少网络流量)

Parameters in PSM

Unlike the usual name-type pairs in languages like C, PSM uses mode- name-type triples, where the mode can be:

  • IN = procedure uses value, does not change value.(传入参数,只能调用不能修改)
  • OUT = procedure changes, does not use.(传出参数,可以在储存过程被修改)
  • INOUT = both

想得到储存过程的返回值,虽然不能直接通过调用储存过程名字,但是可以调用OUT参数

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-05-31,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • SQL in Real Programs
  • Options
  • Stored Procedures
    • Advantages of Stored Procedures
    • Parameters in PSM
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档