search
HomeDatabaseMysql Tutorial利用DB2 V10.1中的全局变量实现全球化

本文的第 1 部分 展示了 DB2 V10.1 的安全性特性如何满足将来自多个国家(行政区)的数据整合到单独一组表中的组织的关键业务需求: 1. 使本地用户仅能访问其所在国家(行政区)的数据 2. 使地区用户仅能访问其所在地区的数据 3. 针对地区用户,实现地方敏感

本文的第 1 部分 展示了 DB2 V10.1 的安全性特性如何满足将来自多个国家(行政区)的数据整合到单独一组表中的组织的关键业务需求:

1. 使本地用户仅能访问其所在国家(行政区)的数据
2. 使地区用户仅能访问其所在地区的数据
3. 针对地区用户,实现“地方敏感型”,自动将不同国家(行政区)的币种值转为通用币种(例如,为了汇总分别使用新加坡货币和中国香港货币的两种商品的价格,需要进行币种转换)
4. 根据用户是本地用户还是地区用户来屏蔽列数据

本文以第1 部分作为基础,展示了如何利用全局变量和角色来降低代码复杂性、提高有用性,同时动态计算对地方敏感的日期/时间段。

提高指定日期/时间值时的有用性

全局变量可用于使 SQL 更易理解。您不必再在 SQL 语句中指定复杂的公式,而是可以为该公式创建一个全局变量,直接指定该变量。全局变量提供了共享的通用例程,可在任何 SQL 中使用它们,这些例程消除了重复编写相同代码的需要。除此之外,利用全局变量时,只需在指定公式的位置创建变量一次,因此可减少 SQL 中的错误。

全局变量支持使用描述性名称,这有助于用户或读者确定应执行哪些计算。例如,指定一周的第一天时,可以在查询中包含这样的计算:

SELECT … FROM REAL_ESTATE_SALES
WHERE PROPERTY_TYPE = ‘CONDO’
AND EFFECTIVE_DATE =
CURRENT_DATE – (DAYOFWEEK_ISO (CURRENT_DATE)-1) DAYS)

我们也可以创建一个全局变量来改善可读性。这允许任何查看 SQL 语句的用户确定查询执行的日期计算:

CREATE VARIABLE FIRST_DAY_OF_WEEK DATE
DEFAULT
(CURRENT_DATE – (DAYOFWEEK_ISO (CURRENT_DATE)-1) DAYS)

现在,可将查询写为:

SELECT … FROM REAL_ESTATE_SALES
WHERE PROPERTY_TYPE = ‘CONDO’
AND EFFECTIVE DATE = FIRST_DAY_OF_WEEK

全局变量允许我们指定一个“常量”,全局变量的名称表示业务查询执行的操作。下面给出了几个常用的日期/时间段:
1. 今天
2. 昨天
3. 明天
4. 一个月的第一天
5. 一个月的最后一天
6. 一个星期的第一天
7. 当前季度的第一天
利用全局变量,可以通过用户友好、易于阅读的格式表示这些时间段。下面给出了上述时间段的定义。
今天:

CREATE VARIABLE TODAY DATE DEFAULT CURRENT DATE

昨天:

CREATE VARIABLE YESTERDAY DATE DEFAULT CURRENT DATE – 1 DAY

明天:

CREATE VARIABLE TOMORROW DATE DEFAULT CURRENT DATE + 1 DAY

一个月的第一天:

CREATE VARIABLE FIRST_DAY_OF_CURRENT_MONTH DATE
DEFAULT
(CURRENT_DATE – (DAY (CURRENT_DATE)-1) DAYS)

一个月的最后一天:

CREATE VARIABLE LAST_DAY_OF_CURRENT_MONTH DATE
DEFAULT
(LAST_DAY (CURRENT DATE))

一个星期的第一天:

CREATE VARIABLE FIRST_DAY_OF_WEEK DATE
DEFAULT
(CURRENT_DATE – (DAYOFWEEK_ISO (CURRENT_DATE)-1) DAYS)

当前季度的第一天(请注意,定义中也使用了全局变量 FIRST_DAY_OF_THE_CURRENT_MONTH):

CREATE VARIABLE FIRST_DAY_OF_QUARTER DATE
DEFAULT
(ROUND (FIRST_DAY_OF_CURRENT_MONTH,’Q'))

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor