WO2021259290A1 - 存储过程转换方法、装置、设备和存储介质 - Google Patents

存储过程转换方法、装置、设备和存储介质 Download PDF

Info

Publication number
WO2021259290A1
WO2021259290A1 PCT/CN2021/101643 CN2021101643W WO2021259290A1 WO 2021259290 A1 WO2021259290 A1 WO 2021259290A1 CN 2021101643 W CN2021101643 W CN 2021101643W WO 2021259290 A1 WO2021259290 A1 WO 2021259290A1
Authority
WO
WIPO (PCT)
Prior art keywords
stored procedure
database
stored
procedure
syntax
Prior art date
Application number
PCT/CN2021/101643
Other languages
English (en)
French (fr)
Inventor
李强周
Original Assignee
中兴通讯股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2021259290A1 publication Critical patent/WO2021259290A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • G06F16/214Database migration support
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/253Grammatical analysis; Style critique

Definitions

  • This application relates to the technical field of database storage, and in particular to a storage process conversion method, device, equipment, and storage medium.
  • an embodiment of the present application provides a stored procedure conversion method, including: obtaining the stored procedure of the source database; parsing and translating the stored procedure to obtain the corresponding syntax block list; processing the syntax block list to obtain the target Stored procedures required by the database.
  • an embodiment of the present application provides a stored procedure conversion device, which includes: an obtaining module configured to obtain a stored procedure of the source database; an analysis translation module configured to parse and translate the stored procedure to obtain the corresponding A list of syntax blocks; the processing module is configured to process the list of syntax blocks to obtain a stored procedure that meets the requirements of the target database.
  • an embodiment of the present application provides a device, including: one or more processors; a memory, used to store one or more programs; when one or more programs are executed by one or more processors, one Or multiple processors implement any one of the methods provided in the embodiments of the present application.
  • an embodiment of the present application provides a storage medium, and the storage medium stores a computer program.
  • the computer program When executed by a processor, it implements any of the methods provided in the embodiments of the present application.
  • Fig. 1 is a flowchart of a storage process conversion method according to an embodiment of the present application
  • FIG. 2 is a flowchart of Oracle database stored procedure conversion provided according to an embodiment of the present application
  • FIG. 3 is a schematic diagram of the structure of an Oracle database stored procedure lexical parse tree provided according to an embodiment of the present application
  • FIG. 4 is a schematic structural diagram of a storage process conversion apparatus according to an embodiment of the present application.
  • Fig. 5 is a schematic structural diagram of a device provided according to an embodiment of the present application.
  • the stored procedure is a set of structured query language (Structured Query Language, SQL) statement sets in order to complete specific functions in a large database system, which are stored in the database, and they do not need to be called again after a second compilation.
  • SQL Structured Query Language
  • the user executes it by specifying the name of the stored procedure and giving parameters.
  • the stored procedure is an important object in the database.
  • Database stored procedures have the characteristics of diverse syntax and complex logic. Especially applications based on Oracle databases use a lot of stored procedures. Even a stored procedure contains thousands of lines of code. The migration process in heterogeneous databases will bring a lot of Large migration workload.
  • the storage process conversion method, device, equipment, and storage medium provided in this application can save labor and time costs in the database migration process, and improve the efficiency of the storage process migration.
  • a method for converting a stored procedure is provided. As shown in FIG. 1, the method for converting a stored procedure provided in an embodiment of the present application mainly includes steps S11, S12, and S13.
  • the stored procedure is a computer term, corresponding to a piece of code, which is a set of SQL statements to complete a specific function, and is a program written in the Transact-SQL language provided by SQL Server.
  • the stored procedure there can be one or more stored procedures in the source database.
  • the stored procedure of the source database is parsed. Before parsing, it is necessary to determine which database vendor’s SQL syntax rules the source database adopts.
  • the source database can be a traditional database that uses SQL to write stored procedures, for example, Oracle Database
  • the target database can be a database that uses a query language (Hibernate Query Language, HQL) to write stored procedures, such as Hive (data warehouse tool).
  • Hive data warehouse tool
  • the stored procedure of the source database is written in SQL language
  • the stored procedure that meets the requirements of the target database is written in HQL language.
  • a stored procedure is created according to the Java Database Connectivity (JDBC) protocol. After the stored procedure is created, the stored procedure can be invoked. Initiating a call to a stored procedure can be a stored procedure loaded by the stored procedure loader of the source database.
  • JDBC Java Database Connectivity
  • obtaining the stored procedure of the source database includes: connecting to the source database online and exporting the stored procedure of the source database.
  • the stored procedure loader When the stored procedure loader is in online mode, it directly connects to the source database and exports the stored procedures of the source database.
  • the stored procedure loader when the stored procedure loader is in online mode, it directly connects to the Oracle database and exports stored procedures from the Oracle database.
  • obtaining the stored procedure of the source database includes: reading the database schema definition language (DDL) file of the source database offline; and splitting the DDL file into the stored procedure of the source database.
  • DDL database schema definition language
  • the stored procedure loader supports both offline and online modules.
  • the stored procedure loader When the stored procedure loader is in offline mode, it reads DDL files and splits them into stored procedures.
  • storing DDL files in the source database is a language used to describe the real-world entities to be stored in the database.
  • the definition of database schema is commonly used to describe the schema through the data description language DDL. That is, the related content of the stored procedure is encapsulated in the DDL file, and the stored procedure of the source database can be obtained by splitting this content.
  • parsing and translating the stored procedure to obtain the corresponding grammatical block list includes: parsing the stored procedure based on the grammatical structure of the stored procedure to generate a parsed lexical tree; for each grammatical block in the lexical tree, Translate in different database languages to get a list of corresponding syntax blocks.
  • the stored procedures correspond to different grammatical structures. Determine the grammatical structure in the source database, and parse the stored procedure based on the determined grammatical structure to generate the corresponding lexical tree. For example: defining modules, grammar sets, etc.
  • each grammar block in the lexical tree is translated using a different database language to obtain a grammar block list corresponding to each grammar block.
  • the syntax block list includes syntax blocks written in each database language.
  • parsing the stored procedure to generate the parsed lexical tree includes: parsing each entry in the stored procedure; generating the first declaration part and the procedure body part of the stored procedure based on each parsed entry; The first statement part and the procedure body part are respectively parsed to generate the parsed lexical tree.
  • the procedure body part includes a second declaration part and a grammar part, the second declaration part is directly parsed, and the grammar part includes a single statement and a grammar block.
  • a single grammar includes parameter definitions, insert, delete, update, select, select...into and other parts; syntax blocks include loop syntax blocks, case syntax blocks, while syntax blocks, if syntax blocks, etc. These syntax blocks can be nested , Combined to form a new grammar block, so it is necessary to analyze the lexical method in a loop until the end of the grammar block appears.
  • the first declaration part includes a stored procedure name and a parameter list, where the parameter list includes one or more of the following: parameter type, parameter name, and parameter data type.
  • the procedure body part includes a second declaration part and a syntax part
  • the syntax part includes a single statement and a syntax block.
  • processing the syntax block list to obtain a stored procedure that meets the requirements of the target database includes: determining the database type of the target database; obtaining the syntax block corresponding to the database type in the syntax block list; and assigning the syntax block corresponding to the database type The blocks are combined to obtain a stored procedure that meets the requirements of the target database.
  • the target database type is determined
  • the language for writing the database is determined based on the database type
  • the syntax block corresponding to the language is obtained. Combine the obtained language blocks to obtain a stored procedure that meets the requirements of the target database.
  • the migration of the stored procedure of the Oracle database to the MySQL database is taken as an example for description.
  • MySQL database is widely used, and there are many kinds of databases based on MySQL syntax. Migrating stored procedures from Oracle database to MySQL database is a very widely used case.
  • the stored procedure loader loads Oracle database stored procedures.
  • the stored procedure is loaded and the lexical analysis stream is added to read the entry at a time.
  • "create or replace test” can parse out an entry as “create”
  • the second entry is "or”
  • the third entry is "replace”
  • the fourth entry is the stored procedure name " test”
  • entry parsing can identify multiple spaces, etc.
  • the lexical parser performs lexical analysis on Oracle database stored procedures and parses them into corresponding lexical trees.
  • lexical analysis needs to parse out the first declaration (declare) part of the information.
  • the first declare part is in a special format, including the stored procedure name (name) and the parameter list (param list).
  • the param list contains the parameter name (param name), parameter type (param type) and input and output (in/out) three dimensions.
  • the body part of the parsing process of the lexical parser also includes the second declare part and the statement set.
  • the declare part is the parameter list.
  • the parameter list contains the parameter name (param name) and parameter type (param type). ) And default value (default value) three dimensions.
  • a single grammar includes parameter definition, insert, delete, update, select, select...into and other parts; grammar blocks include loop grammar block, case grammar block, while grammar block, if grammar block, set grammar block, exit grammar block, exception syntax block, etc.
  • the grammar translator obtains that the type that currently needs to be translated is MySQL.
  • Each grammar type corresponds to different database writing operations, such as defining statements:
  • the stored procedure generator will translate the syntax output of the MySQL stored procedure.
  • the stored procedure generator will generate the corresponding stored procedure grammar framework according to the current database type, and select the corresponding statement grammatical structure for splicing, and finally generate the converted stored procedure grammar.
  • the storage process conversion apparatus provided in the embodiment of the present application mainly includes an acquisition module 41, an analysis and translation module 42, and a processing module 43.
  • the obtaining module 41 is configured to obtain the stored procedure of the source database;
  • the parsing and translation module 42 is configured to parse and translate the stored procedure to obtain the corresponding grammar block list;
  • the processing module 43 is configured to obtain the grammatical block list After processing, a stored procedure that meets the requirements of the target database is obtained.
  • obtaining the stored procedure of the source database includes: connecting to the source database online and exporting the stored procedure of the source database.
  • obtaining the stored procedure of the source database includes: reading the database schema definition language DDL file of the source database offline; and splitting the DDL file into the stored procedure of the source database.
  • parsing and translating the stored procedure to obtain the corresponding grammatical block list includes: parsing the stored procedure based on the grammatical structure of the stored procedure to generate a parsed lexical tree; for each grammatical block in the grammatical block list, Translate in different database languages to get a list of corresponding syntax blocks.
  • parsing the stored procedure to generate the parsed lexical tree includes: parsing each entry in the stored procedure; generating the first declaration part and the procedure body part of the stored procedure based on each parsed entry; The first statement part and the procedure body part are respectively parsed to generate the parsed lexical tree.
  • the first declaration part includes a stored procedure name and a parameter list, where the parameter list includes one or more of the following: parameter type, parameter name, and parameter data type.
  • the procedure body part includes a second declaration part and a syntax part
  • the syntax part includes a single statement and a syntax block.
  • processing the syntax block list to obtain a stored procedure that meets the requirements of the target database includes: determining the database type of the target database; obtaining the syntax block corresponding to the database type in the syntax block list; and assigning the syntax block corresponding to the database type The blocks are combined to obtain a stored procedure that meets the requirements of the target database.
  • the stored procedure conversion device provided in this embodiment can execute the stored procedure conversion method provided in any embodiment of the present application, and has the corresponding functional modules and beneficial effects for executing the method.
  • the stored procedure conversion method provided in any embodiment of this application please refer to the stored procedure conversion method provided in any embodiment of this application.
  • FIG. 5 is a schematic structural diagram of a device provided by an embodiment of the present application.
  • the device includes a processor 51, a memory 52, an input device 53, an output device 54, and Communication device 55; the number of processors 51 in the device can be one or more.
  • one processor 51 is taken as an example; the processor 51, memory 52, input device 53, and output device 54 in the device can be connected via a bus or Other ways to connect, Figure 5 takes the bus connection as an example.
  • the memory 52 can be used to store software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the storage process conversion method in the embodiment of the present application (for example, the storage process conversion device in the storage process conversion device).
  • the processor 51 executes various functional applications and data processing of the device by running software programs, instructions, and modules stored in the memory 52, that is, implements any method provided in the embodiments of the present application.
  • the memory 52 may mainly include a program storage area and a data storage area.
  • the program storage area may store an operating system and an application program required by at least one function; the data storage area may store data created according to the use of the device, and the like.
  • the memory 52 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices.
  • the memory 52 may further include a memory remotely provided with respect to the processor 51, and these remote memories may be connected to the device through a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
  • the input device 53 can be used to receive inputted number or character information, and generate key signal input related to user settings and function control of the device.
  • the output device 54 may include a display device such as a display screen.
  • the communication device 55 may include a receiver and a transmitter.
  • the communication device 55 is configured to perform information transceiving and communication under the control of the processor 51.
  • an embodiment of the present application further provides a storage medium containing computer-executable instructions.
  • the computer-executable instructions When executed by a computer processor, they are used to perform a storage process conversion method, including: obtaining The stored procedure of the source database; the stored procedure is parsed and translated to obtain the corresponding grammar block list; the grammar block list is processed to obtain the stored procedure that meets the requirements of the target database.
  • a storage medium containing computer-executable instructions provided by the embodiments of the present application and the computer-executable instructions are not limited to the above-mentioned method operations, and can also execute the related storage process conversion methods provided by any embodiment of the present application. operate.
  • ROM Read-Only Memory
  • RAM Random Access Memory
  • FLASH Flash memory
  • hard disk or optical disk etc., including several instructions to make a computer device (which can be a personal computer) , A server, or a network device, etc.) execute the stored procedure conversion method of each embodiment of the present application.
  • user terminal encompasses any suitable type of wireless user equipment, such as a mobile phone, a portable data processing device, a portable web browser, or a vehicle-mounted mobile station.
  • the various embodiments of the present application can be implemented in hardware or dedicated circuits, software, logic or any combination thereof.
  • some aspects may be implemented in hardware, while other aspects may be implemented in firmware or software that may be executed by a controller, microprocessor, or other computing device, although the application is not limited thereto.
  • Computer program instructions can be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code written in any combination of one or more programming languages or Object code.
  • ISA instruction set architecture
  • the block diagram of any logic flow in the drawings of the present application may represent program steps, or may represent interconnected logic circuits, modules, and functions, or may represent a combination of program steps and logic circuits, modules, and functions.
  • the computer program can be stored on the memory.
  • the memory can be of any type suitable for the local technical environment and can be implemented using any suitable data storage technology, such as but not limited to read-only memory (ROM), random access memory (RAM), optical storage devices and systems (digital multi-function discs) DVD or CD disc) etc.
  • Computer-readable media may include non-transitory storage media.
  • the data processor can be any type suitable for the local technical environment, such as but not limited to general-purpose computers, special-purpose computers, microprocessors, digital signal processors (DSP), application-specific integrated circuits (ASIC), programmable logic devices (FGPA) And processors based on multi-core processor architecture.
  • DSP digital signal processors
  • ASIC application-specific integrated circuits
  • FGPA programmable logic devices

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Mathematical Physics (AREA)
  • Artificial Intelligence (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

一种存储过程转换方法、装置、设备和存储介质,方法包括:获取源数据库的存储过程(S11);对所述存储过程进行解析和翻译,得到对应的语法块列表(S12);对所述语法块列表进行处理,得到满足目标数据库要求的存储过程(S13)。

Description

存储过程转换方法、装置、设备和存储介质
交叉引用
本申请基于申请号为“202010576991.3”、申请日为2020年06月22日的中国专利申请提出,并要求该中国专利申请的优先权,该中国专利申请的全部内容在此以引入方式并入本申请。
技术领域
本申请涉及数据库存储技术领域,具体涉及一种存储过程转换方法、装置、设备和存储介质。
背景技术
目前数据库迁移一般是由认为操作来完成,每人每天只能改造约5-10个。这样导致大量的人力和时间的浪费,效率低下。
发明内容
第一方面,本申请实施例提供一种存储过程转换方法,包括:获取源数据库的存储过程;对存储过程进行解析和翻译,得到对应的语法块列表;对语法块列表进行处理,得到满足目标数据库要求的存储过程。
第二方面,本申请实施例提供一种存储过程转换装置,其中,包括:获取模块,被配置为获取源数据库的存储过程;解析翻译模块,被配置为对存储过程进行解析和翻译,得到对应的语法块列表;处理模块,被配置为对语法块列表进行处理,得到满足目标数据库要求的存储过程。
第三方面,本申请实施例提供一种设备,包括:一个或多个处理器;存储器,用于存储一个或多个程序;当一个或多个程序被一个或多个处理器执行,使得一个或多个处理器实现如本申请实施例提供的任一项的方法。
第四方面,本申请实施例提供一种存储介质,存储介质存储有计算机程序,计算机程序被处理器执行时实现如本申请实施例提供的任一项的方法。
附图说明
图1是根据本申请一个实施例提供的一种存储过程转换方法的流程图;
图2是根据本申请一个实施例提供的Oracle数据库存储过程转换的流程图;
图3是根据本申请一个实施例提供的Oracle数据库存储过程词法解析树的结构示意图;
图4是根据本申请一个实施例提供的一种存储过程转换装置的结构示意图;
图5是根据本申请一个实施例提供的一种设备的结构示意图。
具体实施方式
为使本申请的目的、技术方案和优点更加清楚明白,下文中将结合附图对本申请的实施 例进行详细说明。需要说明的是,在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互任意组合。
在附图的流程图示出的步骤可以在诸如一组计算机可执行指令的计算机系统中执行。并且,虽然在流程图中示出了逻辑顺序,但是在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤。
随着大数据时代的到来,传统的关系型数据库己经满足不了众多企业的需求,因此越来越多的企业需要将在传统的关系型数据库中存储的数据迁移到大数据平台中。其中,存储过程(Stored Procedure)是在大型数据库系统中,一组为了完成特定功能的结构化查询语言(Structured Query Language,SQL)语句集,存储在数据库中,经过次编译后再次调用不需要再次编译,用户通过指定存储过程的名字并给出参数来执行它。存储过程是数据库中的一个重要对象。
数据库的存储过程具有语法多样和逻辑复杂的特点,尤其基于Oracle数据库的应用,使用非常多的存储过程,甚至一个存储过程包含几千行的代码,在异构数据库迁移的过程,会带来很大的迁移工作量。
本申请提供的存储过程转换方法、装置、设备和存储介质,以节约数据库迁移过程中的人力和时间成本,提高存储过程迁移的效率。
在一个实施例中,提供一种存储过程转换方法,如图1所示,本申请实施例提供的存储过程转换方法主要包括步骤S11、S12和S13。
S11、获取源数据库的存储过程。
S12、对存储过程进行解析和翻译,得到对应的语法块列表。
S13、对语法块列表进行处理,得到满足目标数据库要求的存储过程。
在本实施例中,存储过程是计算机用语,对应的是一段代码,是一组为了完成特定功能的SQL语句集,是利用SQL Server所提供的Transact-SQL语言所编写的程序。其中,源数据库中的存储过程可以是一个也可以是多个。
在实施过程中,对源数据库的存储过程进行解析,在解析之前,需要确定源数据库采用哪个数据库厂商的SQL语法规则,例如:源数据库可以是使用SQL语言编写存储过程的传统数据库,例如,Oracle数据库;目标数据库可以是使用查询语言(Hibernate Query Language,HQL)编写存储过程的数据库,例如Hive(数据仓库工具)。
例如:源数据库的存储过程是使用SQL语言编写,满足目标数据库要求的存储过程是通过HQL语言编写。
在具体的实施过程中,在获取源数据库的存储过程之前,根据Java数据库连接(Java Database Connectivity,JDBC)协议创建存储过程,存储过程创建完成后,可以对存储过程发起调用。对存储过程发起调用可以是存储过程加载器加载源数据库的存储过程。
提供两种获取源数据库的存储过程的方式。
在一个实施例中,获取源数据库的存储过程,包括:在线连接源数据库,导出源数据库的存储过程。
存储过程加载器是在线模式时,直接连接源数据库,导出源数据库的存储过程。
例如:存储过程加载器是在线模式时,直接连接Oracle数据库,从Oracle数据库中导出存储过程。
在一个实施例中,获取源数据库的存储过程,包括:离线读取源数据库的数据库模式定义语言(Data Definition Language,DDL)文件;将DDL文件拆分成源数据库的存储过程。
进一步的,使用存储过程加载器来实现存储过程的获取。存储过程加载器支持离线和在线两种模块。
存储过程加载器是离线模式时,读取DDL文件,并拆分成存储过程。
例如:在源数据库中存储DDL文件,是用于描述数据库中要存储的现实世界实体的语言。数据库模式的定义常用的是通过数据描述语言DDL描述文本定义模式。即在DDL文件中封装着存储过程的相关内容,对此内容进行拆分可以得到源数据库的存储过程。
在一个实施例中,对存储过程进行解析和翻译,得到对应的语法块列表,包括:基于存储过程的语法结构解析存储过程,生成解析后的词法树;对于词法树中的每个语法块,以不同的数据库语言进行翻译,得到对应的语法块列表。
在本实施例中,基于源数据库使用的编程语言的不同,存储过程对应在不同的语法结构。确定源数据库中的语法结构,并基于确定的语法结构对存储过程进行解析,生成对应的词法树。例如:定义模块,语法集等。
生成解析后的词法树之后,对于词法树中的每个语法块采用不用的数据库语言进行翻译,得到每个语法块对应的语法块列表。语法块列表中包括各个数据库语言编写的语法块。
在一个实施例中,解析存储过程,生成解析后的词法树,包括:解析存储过程中的每个词条;基于解析后的每个词条生成存储过程的第一声明部分和过程体部分;分别解析第一声明部分和过程体部分,生成解析后的词法树。
解析存储过程的过程体部分。过程体部分包括第二声明部分和语法部分,第二声明部分直接解析,语法部分包括单条语句和语法块。单条语法包括参数定义,insert,delete,update,select,select...into等部分;语法块包括如loop语法块,case语法块,while语法块,if语法块等,这些语法块可以进行嵌套、组合,进而形成新的语法块,所以,需循环进行解析词法,直至出现语法块结束标志。
在一个实施例中,第一声明部分包括存储过程名称和参数列表,其中,参数列表包括如下一个或多个:参数类型,参数名,参数的数据类型。
在一个实施例中,过程体部分包括第二声明部分和语法部分,语法部分包括单条语句和语法块。
在一个实施例中,对语法块列表进行处理,得到满足目标数据库要求的存储过程,包括:确定目标数据库的数据库类型;在语法块列表中获取数据库类型对应的语法块;将数据库类型对应的语法块进行组合,得到满足目标数据库要求的存储过程。
在本实施例汇总,确定目标数据库类型,基于数据库类型确定编写数据库的语言,获取该语言对应的语法块。将得到的语言块进行组合,得到满足目标数据库要求的存储过程。
在一个实施例中,以Oracle数据库存储过程迁移至MySQL数据库为例进行说明。
目前MySQL数据库应用较为广泛,基于MySQL语法的各类数据库也很多。Oracle数据库的存储过程迁移至MySQL数据库是一个应用非常广泛的案例。
如图2所示,Oracle数据库存储过程迁移至MySQL数据库的步骤主要包括以下几点:
1、存储过程加载器加载Oracle数据库存储过程。
如图3所示,加载存储过程,添加词法解析流,能够一次读取词条。如“create or replace test”,能解析出个词条为“create”,第二个词条为“or”,第三个词条为“replace”,第四个词条即为存储过程名“test”,词条解析能够识别多个空格等。
2、词法解析器将Oracle数据库存储过程进行词法解析,解析成对应的词法树。
如图3所示,词法解析需解析出第一声明(declare)部分信息,第一declare部分为特殊格式,包括存储过程名(name)和参数列表(param list),param list包含参数名(param name),参数类型(param type)和输入输出(in/out)三个维度。
词法解析器解析过程体(body)部分,body部分同样包括第二declare部分和语句集合(statement)两个部分,declare部分为参数列表,参数列表包含参数名(param name),参数类型(param type)和默认值(default value)三个维度。单条语法包括参数定义,insert,delete,update,select,select...into等部分;语法块包括如loop语法块,case语法块,while语法块,if语法块,set语法块,exit语法块,exception语法块等。
3、语法翻译器获取当前需要翻译的类型是MySQL。
每种语法类型对应不同数据库的写法操作,如定义语句:
Figure PCTCN2021101643-appb-000001
4、存储过程生成器将翻译成MySQL存储过程的语法输出。
存储过程生成器会依据当前的数据库类型,生成对应的存储过程语法框架,并选择对应的statement的语法结构进行拼接,最终生成转换后的存储过程语法。
在一个实施例中,提供一种存储过程转换方法,如图4所示,本申请实施例提供的存储过程转换装置主要包括获取模块41、解析翻译模块42和处理模块43。
其中,获取模块41,被配置为获取源数据库的存储过程;解析翻译模块42,被配置为对存储过程进行解析和翻译,得到对应的语法块列表;处理模块43,被配置为对语法块列表进行处理,得到满足目标数据库要求的存储过程。
在一个实施例中,获取源数据库的存储过程,包括:在线连接源数据库,导出源数据库的存储过程。
在一个实施例中,获取源数据库的存储过程,包括:离线读取源数据库的数据库模式定义语言DDL文件;将DDL文件拆分成源数据库的存储过程。
在一个实施例中,对存储过程进行解析和翻译,得到对应的语法块列表,包括:基于存储过程的语法结构解析存储过程,生成解析后的词法树;对于语法块列表的每个语法块,以 不同的数据库语言进行翻译,得到对应的语法块列表。
在一个实施例中,解析存储过程,生成解析后的词法树,包括:解析存储过程中的每个词条;基于解析后的每个词条生成存储过程的第一声明部分和过程体部分;分别解析第一声明部分和过程体部分,生成解析后的词法树。
在一个实施例中,第一声明部分包括存储过程名称和参数列表,其中,参数列表包括如下一个或多个:参数类型,参数名,参数的数据类型。
在一个实施例中,过程体部分包括第二声明部分和语法部分,语法部分包括单条语句和语法块。
在一个实施例中,对语法块列表进行处理,得到满足目标数据库要求的存储过程,包括:确定目标数据库的数据库类型;在语法块列表中获取数据库类型对应的语法块;将数据库类型对应的语法块进行组合,得到满足目标数据库要求的存储过程。
本实施例中提供的存储过程转换装置可执行本申请任意实施例所提供的存储过程转换方法,具备执行该方法相应的功能模块和有益效果。未在本实施例中详尽描述的技术细节,可参见本申请任意实施例所提供的存储过程转换方法。
值得注意的是,上述存储过程转换装置的实施例中,所包括的各个单元和模块只是按照功能逻辑进行划分的,但并不局限于上述的划分,只要能够实现相应的功能即可;另外,各功能单元的具体名称也只是为了便于相互区分,并不用于限制本申请的保护范围。
本申请实施例还提供一种设备,图5是本申请实施例提供的一种设备的结构示意图,如图5所示,该设备包括处理器51、存储器52、输入装置53、输出装置54和通信装置55;设备中处理器51的数量可以是一个或多个,图5中以一个处理器51为例;设备中的处理器51、存储器52、输入装置53和输出装置54可以通过总线或其他方式连接,图5中以通过总线连接为例。
存储器52作为一种计算机可读存储介质,可用于存储软件程序、计算机可执行程序以及模块,如本申请实施例中的存储过程转换方法对应的程序指令/模块(例如,存储过程转换装置中的获取模块41、解析翻译模块42和处理模块43)。处理器51通过运行存储在存储器52中的软件程序、指令以及模块,从而执行设备的各种功能应用以及数据处理,即实现本申请实施例提供的任一方法。
存储器52可主要包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需的应用程序;存储数据区可存储根据设备的使用所创建的数据等。此外,存储器52可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件、闪存器件、或其他非易失性固态存储器件。在一些实例中,存储器52可进一步包括相对于处理器51远程设置的存储器,这些远程存储器可以通过网络连接至设备。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。
输入装置53可用于接收输入的数字或字符信息,以及产生与设备的用户设置以及功能控制有关的键信号输入。输出装置54可包括显示屏等显示设备。
通信装置55可以包括接收器和发送器。通信装置55设置为根据处理器51的控制进行信息收发通信。
在一个示例性的实施方式中,本申请实施例还提供一种包含计算机可执行指令的存储介质,计算机可执行指令在由计算机处理器执行时用于执行一种存储过程转换方法,包括:获取源数据库的存储过程;对存储过程进行解析和翻译,得到对应的语法块列表;对语法块列表进行处理,得到满足目标数据库要求的存储过程。
当然,本申请实施例所提供的一种包含计算机可执行指令的存储介质,其计算机可执行指令不限于如上的方法操作,还可以执行本申请任意实施例所提供的存储过程转换方法中的相关操作。
通过以上关于实施方式的描述,所属领域的技术人员可以清楚地了解到,本申请可借助软件及必需的通用硬件来实现,当然也可以通过硬件实现,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如计算机的软盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、闪存(FLASH)、硬盘或光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例的存储过程转换方法。
以上,仅为本申请的示例性实施例而已,并非用于限定本申请的保护范围。
本领域内的技术人员应明白,术语用户终端涵盖任何适合类型的无线用户设备,例如移动电话、便携数据处理装置、便携网络浏览器或车载移动台。
一般来说,本申请的多种实施例可以在硬件或专用电路、软件、逻辑或其任何组合中实现。例如,一些方面可以被实现在硬件中,而其它方面可以被实现在可以被控制器、微处理器或其它计算装置执行的固件或软件中,尽管本申请不限于此。
本申请的实施例可以通过移动装置的数据处理器执行计算机程序指令来实现,例如在处理器实体中,或者通过硬件,或者通过软件和硬件的组合。计算机程序指令可以是汇编指令、指令集架构(ISA)指令、机器指令、机器相关指令、微代码、固件指令、状态设置数据、或者以一种或多种编程语言的任意组合编写的源代码或目标代码。
本申请附图中的任何逻辑流程的框图可以表示程序步骤,或者可以表示相互连接的逻辑电路、模块和功能,或者可以表示程序步骤与逻辑电路、模块和功能的组合。计算机程序可以存储在存储器上。存储器可以具有任何适合于本地技术环境的类型并且可以使用任何适合的数据存储技术实现,例如但不限于只读存储器(ROM)、随机访问存储器(RAM)、光存储器装置和系统(数码多功能光碟DVD或CD光盘)等。计算机可读介质可以包括非瞬时性存储介质。数据处理器可以是任何适合于本地技术环境的类型,例如但不限于通用计算机、专用计算机、微处理器、数字信号处理器(DSP)、专用集成电路(ASIC)、可编程逻辑器件(FGPA)以及基于多核处理器架构的处理器。
通过示范性和非限制性的示例,上文已提供了对本申请的示范实施例的详细描述。但结合附图和权利要求来考虑,对以上实施例的多种修改和调整对本领域技术人员来说是显而易见的,但不偏离本申请的范围。因此,本申请的恰当范围将根据权利要求确定。

Claims (10)

  1. 一种存储过程转换方法,包括:
    获取源数据库的存储过程;
    对所述存储过程进行解析和翻译,得到对应的语法块列表;
    对所述语法块列表进行处理,得到满足目标数据库要求的存储过程。
  2. 根据权利要求1所述的方法,其中,所述获取源数据库的存储过程,包括如下方法之一:
    在线连接所述源数据库,导出所述源数据库的存储过程;
    离线读取所述源数据库的数据库模式定义语言DDL文件,将所述DDL文件拆分成所述源数据库的存储过程。
  3. 根据权利要求1-2任一项所述的方法,其中,所述对所述存储过程进行解析和翻译,得到对应的语法块列表,包括:
    基于所述存储过程的语法结构解析所述存储过程,生成解析后的词法树;
    对于所述词法树的每个语法块,以不同的数据库语言进行翻译,得到对应的语法块列表。
  4. 根据权利要求3所述的方法,其中,所述解析所述存储过程,生成解析后的词法树,包括:
    解析所述存储过程中的每个词条;
    基于解析后的每个词条生成所述存储过程的第一声明部分和过程体部分;
    分别解析所述第一声明部分和所述过程体部分,生成解析后的词法树。
  5. 根据权利要求4所述的方法,其中,所述第一声明部分包括存储过程名称和参数列表,其中,所述参数列表包括如下一个或多个:参数类型,参数名,参数的数据类型。
  6. 根据权利要求4-5任一项所述的方法,其中,所述过程体部分包括第二声明部分和语法部分,所述语法部分包括单条语句和语法块。
  7. 根据权利要求1-6任一项所述的方法,其中,所述对所述语法块列表进行处理,得到满足目标数据库要求的存储过程,包括:
    确定目标数据库的数据库类型;
    在所述语法块列表中获取所述数据库类型对应的语法块;
    将所述数据库类型对应的语法块进行组合,得到满足目标数据库要求的存储过程。
  8. 一种存储过程转换装置,包括:
    获取模块,被配置为获取源数据库的存储过程;
    解析翻译模块,被配置为对所述存储过程进行解析和翻译,得到对应的语法块列表;
    处理模块,被配置为对所述语法块列表进行处理,得到满足目标数据库要求的存储过程。
  9. 一种设备,包括:
    一个或多个处理器;
    存储器,用于存储一个或多个程序;
    当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现如权利要求1-7任一项所述的方法。
  10. 一种存储介质,所述存储介质存储有计算机程序,所述计算机程序被处理器执行时实现权利要求1-7任一项所述的方法。
PCT/CN2021/101643 2020-06-22 2021-06-22 存储过程转换方法、装置、设备和存储介质 WO2021259290A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010576991.3A CN114064601B (zh) 2020-06-22 2020-06-22 存储过程转换方法、装置、设备和存储介质
CN202010576991.3 2020-06-22

Publications (1)

Publication Number Publication Date
WO2021259290A1 true WO2021259290A1 (zh) 2021-12-30

Family

ID=79282004

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/101643 WO2021259290A1 (zh) 2020-06-22 2021-06-22 存储过程转换方法、装置、设备和存储介质

Country Status (2)

Country Link
CN (1) CN114064601B (zh)
WO (1) WO2021259290A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117992436A (zh) * 2024-04-03 2024-05-07 深圳九有数据库有限公司 基于不同类型数据库的信息系统自动改造方法及设备

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115809063B (zh) * 2022-12-05 2023-08-22 星环信息科技(上海)股份有限公司 一种存储过程编译方法、系统、电子设备和存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106339384A (zh) * 2015-07-07 2017-01-18 小米科技有限责任公司 存储过程的转换方法及装置
CN108629035A (zh) * 2018-05-10 2018-10-09 福建星瑞格软件有限公司 一种基于jdbc代理的异构数据库应用迁移方法
CN109408493A (zh) * 2018-10-17 2019-03-01 成都四方伟业软件股份有限公司 一种数据源的迁移方法及系统
CN109992595A (zh) * 2019-04-11 2019-07-09 北京启迪区块链科技发展有限公司 异构数据库转换方法、装置、设备和存储介质
CN110647579A (zh) * 2019-08-16 2020-01-03 北京百度网讯科技有限公司 数据同步方法及装置、计算机设备与可读介质

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6523172B1 (en) * 1998-12-17 2003-02-18 Evolutionary Technologies International, Inc. Parser translator system and method
CN111241071A (zh) * 2020-02-14 2020-06-05 苏州浪潮智能科技有限公司 一种数据迁移方法、系统、设备及计算机可读存储介质

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106339384A (zh) * 2015-07-07 2017-01-18 小米科技有限责任公司 存储过程的转换方法及装置
CN108629035A (zh) * 2018-05-10 2018-10-09 福建星瑞格软件有限公司 一种基于jdbc代理的异构数据库应用迁移方法
CN109408493A (zh) * 2018-10-17 2019-03-01 成都四方伟业软件股份有限公司 一种数据源的迁移方法及系统
CN109992595A (zh) * 2019-04-11 2019-07-09 北京启迪区块链科技发展有限公司 异构数据库转换方法、装置、设备和存储介质
CN110647579A (zh) * 2019-08-16 2020-01-03 北京百度网讯科技有限公司 数据同步方法及装置、计算机设备与可读介质

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117992436A (zh) * 2024-04-03 2024-05-07 深圳九有数据库有限公司 基于不同类型数据库的信息系统自动改造方法及设备

Also Published As

Publication number Publication date
CN114064601A (zh) 2022-02-18
CN114064601B (zh) 2023-04-07

Similar Documents

Publication Publication Date Title
US9058360B2 (en) Extensible language framework using data cartridges
US8959106B2 (en) Class loading using java data cartridges
CN110704479A (zh) 任务处理方法、装置、电子设备及存储介质
CN107861728B (zh) 用于传统程序语言向现代程序语言转换的方法及其系统
WO2021259290A1 (zh) 存储过程转换方法、装置、设备和存储介质
CN108255837B (zh) 一种sql解析器及方法
CN106933869B (zh) 一种操作数据库的方法和装置
US10635666B2 (en) System, method and device for index compilation to optimize index usage
US11995075B2 (en) System and method for efficient transliteration of machine interpretable languages
CN111078729B (zh) 医疗数据溯源方法、装置、系统、存储介质以及电子设备
US20160132308A1 (en) Leveraging legacy applications for use with modern applications
WO2023035563A1 (zh) 小程序跨应用迁移方法、设备、终端、系统及存储介质
CN114036183A (zh) 一种数据etl处理方法、装置、设备及介质
CN111309751A (zh) 大数据处理方法及装置
CN111159215A (zh) Java类与关系型数据库的映射方法、装置及计算设备
CN112988163B (zh) 编程语言智能适配方法、装置、电子设备和介质
CN105867886B (zh) 一种写表格的方法及装置
CN116628066B (zh) 数据传输方法、装置、计算机设备和存储介质
CN114764558A (zh) 一种sql方言转换方法、装置、系统及存储介质
WO2020024778A1 (zh) xml文件批量修改方法、系统、设备和计算机可读存储介质
CN116775599A (zh) 数据迁移方法、装置、电子设备、存储介质
CN116955393A (zh) 一种数据处理方法、装置、电子设备及存储介质
US11604774B2 (en) Method and apparatus of converting schema in deep learning framework, and computer storage medium
CN117349332B (zh) 一种应用程序编程接口api的生成方法、装置和电子设备
CN114896273B (zh) 一种兼容存储过程的sql语句配置方法、设备及存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21828899

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 12.05.2023)

122 Ep: pct application non-entry in european phase

Ref document number: 21828899

Country of ref document: EP

Kind code of ref document: A1