Real SQL Programming

目录

[SQL in Real Programs](#SQL in Real Programs)

Options

[Stored Procedures](#Stored Procedures)

[Advantages of Stored Procedures](#Advantages of Stored Procedures)

[Parameters in PSM](#Parameters in PSM)


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 modecan be:

  • IN = procedure uses value, does not change value.(传入参数,只能调用不能修改)

  • OUT = procedure changes, does not use.(传出参数,可以在储存过程被修改)

  • INOUT = both

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

相关推荐
JAVA面经实录9171 小时前
Hibernate面试题库
数据库·oracle·hibernate
迷枫7121 小时前
DM8 目录结构与常用排查入口梳理
服务器·数据库
Mr.Daozhi2 小时前
RAG 进阶实战:跑通 Demo 后我连续翻了 6 次车,逐一修复才真正可用(含 Gradio Web 版)
前端·数据库·langchain·大模型·gradio·rag·科研工具
小程故事多_802 小时前
Claude Code自定义workflow skills用法
数据库·人工智能·智能体
大鹏说大话2 小时前
SQL 排序与分组实战:解决“分组后取最新数据“
android·java·数据库
夏贰四3 小时前
数据建模工具如何筑牢数据根基?数据建模工具怎样落实标准体系?
数据库·数学建模·数据建模工具
程序猿阿伟4 小时前
《一套完整方法论:搞定图形应用的Docker镜像优化》
数据库·docker·容器
二等饼干~za8986685 小时前
geo优化源码开发搭建技术分享
大数据·网络·数据库·人工智能·音视频
数据库小学妹5 小时前
HTAP混合负载架构:如何用一个数据库同时搞定交易和分析
数据库·经验分享·架构·dba