pl sql面试题

If you have worked on Oracle database and going for an interview, you should go through PL SQL interview questions and answers.

如果您曾经在Oracle数据库上工作过并且要进行面试,则应该阅读PL SQL面试问题和答案。

PLSQL stands for Procedural Language extension to Structured Query Language. As the definition suggests it’s a Block Structured programming language that extends the capabilities of SQL to provide a more versatile query and update solutions regarding relational databases.

PLSQL代表对结构化查询语言的过程语言扩展。 顾名思义,它是一种块结构化编程语言,它扩展了SQL的功能,以提供有关关系数据库的更通用的查询和更新解决方案。

A few of the many key features that P/L SQL provides are procedures, functions, triggers, cursors etc. A portion of P/L SQL is framed from the SQL programming syntax with added procedural features. For prerequisites, it is highly recommended to have fundamental knowledge in SQL (Structured Query Language).

P / L SQL提供的许多关键功能中的一些是过程,函数,触发器,游标等。P/ L SQL的一部分由SQL编程语法构成,并带有附加的过程功能。 对于先决条件,强烈建议您具有SQL(结构化查询语言)的基础知识。

PL SQL面试问题 (PL SQL Interview Questions)

Listed below are various PL SQL interview questions that will help you in your upcoming interview. You should also go through SQL Interview Questions.

下面列出了各种PL SQL面试问题,这些问题将在您即将进行的面试中为您提供帮助。 您还应该阅读SQL面试问题 。

  1. 什么是PL SQL? (What is PL SQL?)

  2. PL SQL is a Block Structured programming language created by Oracle in the 1990s in hoping to provide additional procedural programming solutions to SQL.

    PL SQL是Oracle在1990年代创建的一种块结构编程语言,希望为SQL提供其他过程编程解决方案。

  3. SQL和PL SQL之间的主要区别是什么? (What are the key differences between SQL and PL SQL?)

  4. SQL is a Structured Query Language as opposed to P/L SQL which is a full procedural language. SQL code is processed one statement block at a time, while P/L SQL code is executed as a single program at one time. SQL can be within P/L SQL, but P/L SQL cannot be within SQL.

    SQL是一种结构化查询语言,而P / L SQL是一种完整的过程语言。 SQL代码一次处理一个语句块,而P / L SQL代码一次作为一个程序执行。 SQL可以在P / L SQL内,但P / L SQL不能在SQL内。

  5. PL / SQL的基本结构是什么? (What is the basic structure of PL/SQL?)

  6. PL SQL, as much as any other procedural language, contains blocks. These blocks which are the basic unit of sensible code are primarily categorized by two types: anonymous blocks and named blocks.

    与其他任何过程语言一样,PL SQL包含块。 这些块是明智代码的基本单元,主要分为两种类型:匿名块和命名块。

    [DECLARE]Declaration statements;
    BEGINExecution statements;[EXCEPTION]Exception handling statements;
    END;

    They are called anonymous because they have no names and are not saved in an Oracle Database.

    它们之所以称为匿名的,是因为它们没有名称并且没有保存在Oracle数据库中。

    The figure below shows a detailed PL SQL block structure:

    下图显示了详细的PL SQL块结构:

    Header Section is for naming/labeling named blocks. This may or may not be used.

    标题部分用于命名/标记命名块。 可能会或可能不会使用。

    Declaration Section is for declaring variables, cursors, or sub-blocks that will be used in the Execution Section and Exception Section. This may or may not be used.

    声明部分用于声明将在执行部分和异常部分中使用的变量,游标或子块。 可能会或可能不会使用。

    Execution Section block is where runtime code is placed. Statements in this section are required to exist for the structure to run.

    执行节块是放置运行时代码的位置。 要运行该结构,必须存在本节中的语句。

    Exception Section contains the exception and error handling of the code.

    异常部分包含代码的异常和错误处理。

    Essential keywords such as IS, BEGIN, EXCEPTION, and END are vital in the program for the runtime engine to distinguish each block sections.

    IS,BEGIN,EXCEPTION和END等基本关键字在程序中对于运行时引擎区分每个块节至关重要。

  7. 触发器及其用途是什么? (What are triggers and its uses?)

  8. Triggers are blocks of code which are run whenever the criteria for a specific event is satisfied. They are hardcoded within the PL SQL program and listens to events such as: DML(database manipulation), DDL(database definition), and database operation. They can be coded within a view, table, database, or scheme for which the mentioned event belongs.

    触发器是代码块,只要满足特定事件的条件,就会运行该代码块。 它们在PL SQL程序中进行了硬编码,并侦听以下事件:DML(数据库操作),DDL(数据库定义)和数据库操作。 它们可以在提到的事件所属的视图,表,数据库或方案中进行编码。

    There are many uses of triggers. They can be used to generate column values upon activating. For event logging within the table activities, auditing, and creating table duplicates. For security, they can implement security authorization, and handle invalid transactions.

    触发器有很多用途。 它们可用于在激活时生成列值。 对于表活动中的事件记录,审核和创建表重复项。 为了安全,他们可以实施安全授权,并处理无效的交易。

    General Structure of creating a Trigger:

    创建触发器的一般结构:

    CREATE [OR REPLACE ] TRIGGER triggerName
    {BEFORE | AFTER | INSTEAD OF }
    {INSERT [OR] | UPDATE [OR] | DELETE}
    [OF colName]
    ON tableName
    [REFERENCING OLD AS o NEW AS n]
    [FOR EACH ROW]
    WHEN (condition)
    DECLARE Declaration-statements
    BEGIN  Executable-statements
    EXCEPTION Exception-handling-statements
    END;
  9. 如何编译PL / SQL代码? (How is a PL/SQL code compiled?)

  10. Firstly, PL/SQL code is transferred to the server and is compiled to byte code. This process takes place prior to program execution. To increase the performance of the procedural code, the procedures are converted to native code shared libraries which are conveniently linked to the kernel. Note that increase in performance still greatly depends on the code structure. This is independent to database calls, and affects performance only on loops, calculations, etc.

    首先,PL / SQL代码被传输到服务器并被编译为字节码。 该过程在程序执行之前进行。 为了提高过程代码的性能,将过程转换为方便地链接到内核的本机代码共享库。 请注意,性能的提高仍然很大程度上取决于代码结构。 这与数据库调用无关,并且仅影响循环,计算等性能。

  11. 使用PL / SQL创建的模式对象有哪些? (What are few of the schema objects that are created using PL/SQL?)

  12. A schema is a user-owned set of schema objects, or logical data structures. These schema objects types are as follows:

    模式是用户拥有的一组模式对象或逻辑数据结构。 这些架构对象类型如下:

  • Clusters集群
  • Database links数据库链接
  • Database triggers数据库触发器
  • Dimensions外型尺寸
  • External procedure libraries外部程序库
  • Indexes and index types索引和索引类型
  • Java classes, Java resources, and Java sourcesJava类,Java资源和Java源
  • Materialized views and materialized view logs物化视图和物化视图日志
  • Object tables, object types, and object views对象表,对象类型和对象视图
  • Operators经营者
  • Sequences顺序
  • Stored functions, procedures, and packages存储的函数,过程和程序包
  • Synonyms同义字
  • Tables and index-organized tables表和索引组织表
  • Views观看次数

Among other objects which are not contained in a schema are:

模式中未包含的其他对象包括:

  • Contexts语境
  • Directories目录
  • Profiles个人资料
  • Roles的角色
  • Tablespaces表空间
  • Users用户数
  • Rollback segments回滚段
  • 定义提交,回滚和保存点。 (Define Commit, Rollback and Savepoint.)

  • The COMMIT Statement finalizes to end your transaction and sets all changes to permanent. A transaction in SQL is any of statements that the Oracle Database treats as a single block. This also enables users to see the updates and changes made by the transaction. Finally, the COMMIT statement deletes all the savepoints prior to the transaction and releases transaction locks.

    COMMIT语句最终确定结束您的交易并将所有更改设置为永久更改。 SQL中的事务是Oracle数据库将其视为单个块的任何语句。 这也使用户能够查看事务所做的更新和更改。 最后,COMMIT语句在事务之前删除所有保存点并释放事务锁。

    The ROLLBACK statement undoes the changes that the transaction has made. This is practically the opposite of the COMMIT Statement. Also, any locks made due to the transaction are released.

    ROLLBACK语句撤消该事务已进行的更改。 这实际上与COMMIT语句相反。 同样,由于事务而进行的任何锁定都将被释放。

    In conjunction, the SAVEPOINT statement is also used to set a restoration point when the ROLLBACK Statement is used. This limits the bounds of the ROLLBACK Statement by only reverting to the SAVEPOINT set point.

    结合使用SAVEPOINT语句还可以在使用ROLLBACK语句时设置恢复点。 这仅通过恢复到SAVEPOINT设置点来限制ROLLBACK语句的范围。

  • PL / SQL中有哪些不同的数据类型? (What are the different datatypes available in PL/SQL?)

  • PL SQL data types can be broadly divided into following categories. There are many data types available in PL SQL but mostly you will be using some of the popular ones.

    PL SQL数据类型可以大致分为以下几类。 PL SQL中有许多可用的数据类型,但是大多数情况下,您将使用一些流行的数据类型。

    1. Numbers – INT, INTEGER, FLOAT, NUMBER, SMALLINT, REAL etc.数字-INT,INTEGER,FLOAT,NUMBER,SMALLINT,REAL等
    2. Character or String – CHAR, CHARACTER, RAW, VARCHAR, VARCHAR2, NCHAR, NVARCHAR2 etc.字符或字符串-CHAR,CHARACTER,RAW,VARCHAR,VARCHAR2,NCHAR,NVARCHAR2等
    3. Boolean – BOOLEAN布尔值-BOOLEAN
    4. Date Time – DATE, TIMESTAMP etc.日期时间-DATE,TIMESTAMP等

    Refer them in detail at oracle Database Documentation.

    请在oracle数据库文档中详细参考它们。

  • %TYPE和%ROWTYPE有什么用? (What are %TYPE and %ROWTYPE for?)

  • The %ROWTYPE allows the coder to indirectly represent a full or partial row of a database table or view, whereas the %TYPE allows for the coder to indirectly represent the data type from a previously declared variable or column. Basically, %ROWTYPE works on a full object whereas %TYPE works on a single column. The advantage to using either of these enables the coder to maintain data type declarations without ever having to know or change the data type for the items that use these. Below is an example of how the %TYPE allows for a layer of abstraction between names; allowing the coder to just change the first occurrence of the data type.

    %ROWTYPE允许编码器间接表示数据库表或视图的全部或部分行,而%TYPE允许编码器间接表示先前声明的变量或列的数据类型。 基本上,%ROWTYPE适用于完整对象,而%TYPE适用于单个列。 使用这两种方法的好处是,编码人员可以维护数据类型声明,而不必知道或更改使用这些声明的项目的数据类型。 以下是%TYPE如何在名称之间允许抽象层的示例; 允许编码人员仅更改数据类型的首次出现。

    DECLAREname   VARCHAR(50);firstName  name%TYPE;lastName  name%TYPE;province   name%TYPE;nationality name%TYPE;emp  employees_table%ROWTYPE;
    BEGINExecution section;
    END;
  • PL / SQL中有什么例外? 两种例外是什么? (What is an exception in PL/SQL? What are the two types of exceptions?)

  • Exceptions are manageable errors in a program. This means that errors handled by exceptions are within the bounds of the programmer to repair and PL/SQL provides catch features to encapsulate these errors to enable debugging and preventing the program to stop working.

    异常是程序中的可管理错误。 这意味着由异常处理的错误在程序员可以修复的范围之内,并且PL / SQL提供了捕获功能来封装这些错误,以启用调试功能并防止程序停止工作。

    There are two main types of exceptions – System Exceptions and User-Defined Exceptions. System Exceptions are such as no_data_found or too_many_rows and already defined by PL SQL. User-Defined Exceptions are exceptions defined by the user to handle particular errors.

    异常主要有两种类型:系统异常和用户定义的异常。 系统异常例如no_data_found或too_many_rows,并且已经由PL SQL定义。 用户定义的异常是用户定义的用于处理特定错误的异常。

  • 在PL / SQL中如何调用函数和过程? (How are functions and procedures called in PL/SQL?)

  • For Procedures:

    对于程序:

    • CALL <procedure name> to call it directly调用<过程名称>以直接调用它
    • EXECUTE <procedure name> from calling environment从调用环境中执行<过程名称>
    • <Procedure name> from other procedures or functions or packages<过程名称>来自其他过程或功能或程序包

    Functions are called directly from other programs or procedures, no additional keyword is required.

    直接从其他程序或过程调用函数,不需要其他关键字。

  • 引用触发器和存储过程的执行之间的区别吗? (Cite the differences between execution of triggers and stored procedures?)

  • Triggers are activated automatically if the criteria for activation is met. This requires virtually no input or action from the user. On the other hand, a stored procedure requires to be explicitly called for it to be activated.

    如果符合激活条件,触发器将自动激活。 这实际上不需要用户输入或采取任何行动。 另一方面,存储过程需要显式调用才能被激活。

  • 导致表格错误的原因是什么,我们该如何解决? (What is the cause of mutating table error and how can we solve it?)

  • This error occurs when an activated trigger causes a change or update in currently used table row. This is fixed using views or temp tables instead of the actual table being used so that the database can provide use for the table row, while updating/changing the other.

    当激活的触发器在当前使用的表行中引起更改或更新时,会发生此错误。 这是使用视图或临时表而不是实际表来解决的,以便数据库可以在更新/更改另一个表行的同时提供对表行的使用。

  • 有哪些不同类型的约束? (What are the different types of Constraints?)

  • Some of the popular constraints are:

    一些流行的约束是:

    • Check检查一下
    • Not NULL不为空
    • Primary key首要的关键
    • Unique独特
    • Foreign Key外键
  • 为什么%ISOPEN为隐式游标返回false? (Why does %ISOPEN return false for an implicit cursor?)

  • Implicit cursors: SQL%ISOPEN always returns FALSE, indicating that the implicit cursor has been closed.

    隐式游标:SQL%ISOPEN始终返回FALSE,表示隐式游标已关闭。

  • 包裹有哪些不同部分? (What are the different parts of a package?)

  • (1) Package Specification – it holds the global package declaration
    (2) Package Body – holds the functions, procedures (along with its local declarations), and cursor declarations.

    (1)软件包规格-它包含全局软件包声明
    (2)包主体–包含函数,过程(以及其本地声明)和游标声明。

  • 隐式游标和显式游标之间有什么区别? (What are the differences between Implicit and Explicit Cursors?)

  • Explicit cursors are cursors created by the programmer to improve the manipulation of the context area. It is declared within the Declaration Section of the PL/SQL Block using the SELECT Statement. For example:

    显式游标是程序员为改善上下文区域的操作而创建的游标。 使用SELECT语句在PL / SQL块的声明部分中声明它。 例如:

    CURSOR cursorName [ parameter ] [ RETURN returnType ]IS SELECT STATEMENT;

    On the other hand, Implicit Cursors are automatically generated by Oracle if there is no existing explicit cursor for the statement. This happens at the instant the SQL statement is ran. The developer has no control over the content and data within implicit cursors.

    另一方面,如果该语句不存在显式游标,则Oracle会自动生成隐式游标。 这是在运行SQL语句的那一刻发生的。 开发人员无法控制隐式游标中的内容和数据。

  • 为什么需要SQLCODE和SQLERRM变量? (Why is there a need for SQLCODE and SQLERRM variables?)

  • SQLCODE AND SQLERRM are globally-defined variables that handles the error description whenever a statement invokes an exception block. They are important due to their capability to trace exceptions that are highlighted by the OTHERS handler. The difference between the two is that SQLEERM returns the exact error message of the recently raised error, while SQLCODE returns the error code number of the last encountered error.

    SQLCODE和SQLERRM是全局定义的变量,每当语句调用异常块时,该变量就会处理错误描述。 由于它们具有跟踪OTHERS处理程序突出显示的异常的能力,因此它们很重要。 两者之间的区别在于,SQLEERM返回最近引发的错误的确切错误消息,而SQLCODE返回最后遇到的错误的错误代码号。

  • [OR REPLACE]参数有什么作用? (What does the argument [OR REPLACE] do?)

  • The [OR REPLACE] argument grants the developer to reinvent an existing trigger. This means that with [OR REPLACE] it is possible to edit the specifics of a trigger without removing it.

    [OR REPLACE]参数允许开发人员重新发明现有的触发器。 这意味着使用[OR REPLACE]可以编辑触发器的详细信息而无需删除它。

  • 什么是错误ORA-12154:TNS:无法解析指定的连接标识符? (What is error ORA-12154: TNS:could not resolve the connect identifier specified?)

  • This error normally occurs when trying to establish a connection with your database. This is due to typographical error in database naming, rending the Oracle unable to know what database you wish to connect to. This is a very popular error as this is one of the headscratchers faced by developers when trying to connect to a database. This maybe also an issue with the connection string within your tnsnames.ora file. Be sure to check that the tnsnames.ora is accessible and has the service name that you are currently using. But most commonly, syntax and typographical errors are the reason behind this error.

    尝试与数据库建立连接时,通常会发生此错误。 这是由于数据库命名出现印刷错误,导致Oracle无法知道您希望连接到哪个数据库。 这是一个非常普遍的错误,因为这是开发人员在尝试连接数据库时面临的麻烦之一。 这可能与tnsnames.ora文件中的连接字符串有关。 确保检查tnsnames.ora是否可访问并且具有您当前正在使用的服务名称。 但最常见的是,语法和印刷错误是造成此错误的原因。

  • 定义重载过程 (Define Overloaded Procedure)

  • An overloaded procedure is a feature in PL/SQL that enables the developer to re-use and existing procedure with the exact name by varying the parameter structure such as the data type and parameter number. This is synonymous to the overloaded methods/functions in fundamental programming. This promotes uniformity and versatility of a PL/SQL block by giving a specific name procedure multiple ways to be called and multiple circumstances to operate.

    重载过程是PL / SQL中的一项功能,通过更改参数结构(例如数据类型和参数编号),开发人员可以重用现有名称准确的过程。 这与基础编程中重载的方法/功能同义。 通过为特定的名称过程提供多种调用方式和多种操作环境,可以提高PL / SQL块的统一性和通用性。

    An overloaded procedure is nothing more than a mechanism that allows the coder to reuse the same procedure name for different subprograms inside a PL/SQL block by varying the number of parameters or the parameter data type. Below is an example of where the same subprogram (callit) is reused but the data type for the input parameter is changed from INTEGER to VARCHAR2; Oracle is smart enough to know the input parameter type and call the proper subprogram.

    重载过程不过是一种机制,该机制允许编码人员通过更改参数数量或参数数据类型,将同一过程名称重用于PL / SQL块内的不同子程序。 以下是重用相同子程序但输入参数的数据类型从INTEGER更改为VARCHAR2的示例。 Oracle足够聪明,可以知道输入参数的类型并调用适当的子程序。

    SQL>
    DECLARE
    PROCEDURE ovlprocedure (num1 INTEGER) IS
    BEGIN
    DBMS_OUTPUT.PUT_LINE('Parameter is an INTEGER');
    END ovlprocedure;PROCEDURE ovlprocedure (character VARCHAR2) IS
    BEGIN
    DBMS_OUTPUT.PUT_LINE('Parameter is a VARCHAR2');
    END ovlprocedure;
    BEGIN
    ovlprocedure (99);
    ovlprocedure ('Hello');
    * END;
    SQL> /
    Parameter is an INTEGER
    Parameter is a VARCHAR2
    PL/SQL procedure successfully completed.
  • 什么是诚信规则? (What are Integrity Rules?)

  • The Entity Integrity Rule(EIR) states that the Primary key must have value always or not Null.
    The Foreign Key Integrity Rule(FKIR) states that if there exists a database relationship between a foreign key and a primary key, the Master Table cannot be deleted WHEN THERE IS DATA EXISTING IN THE CHILD TABLE.
    The Business Integrity Rules encompasses the underlying processing not included in FKIR and EIR.

    实体完整性规则(EIR)声明主键必须始终具有值,或者不为Null。
    外键完整性规则(FKIR)指出,如果外键和主键之间存在数据库关系,则当孩子表中存在数据时,无法删除主表。
    业务完整性规则涵盖FKIR和EIR中未包含的基础处理。

  • 我们如何在SELECT语句中创建IF语句? (How can we make an IF Statement within a SELECT Statement?)

  • We make use of the DECODE keyword. For example,
    e.g. select DECODE (EMP_CAT,’3?,’Third’,’4?,’Fourth’Null);

    我们使用DECODE关键字。 例如,
    例如选择DECODE(EMP_CAT,'3?,'Third','4?,'Fourth'Null);

  • 什么是规范化? (What is Normalization?)

  • Normalization is a neat feature where redundant tables and duplicate attributes are purposely removed to optimize the logical layout of the structure makes it easier to manage. This also improves data retrieval and nowadays, more and more servers implement normalized databases because of improvisations.
    a) 1 Normal Form : This states that the database doesn’t have duplicate attributes.
    b) 2 Normal Form: This states that all the candidate keys are linked on the primary key. Problems related to 2 Normal Form occurs when a multiple columned primary key exists.
    c) 3rd Normal Form : This states that if transitive dependency doesn’t occur in a table, it is of 3rd Normal Form

    规范化是一个很好的功能,其中有目的地删除了冗余表和重复属性,以优化结构的逻辑布局,使其更易于管理。 这也改善了数据检索,如今,由于即兴创作,越来越多的服务器实现了标准化数据库。
    a)1正常形式:这表明数据库没有重复的属性。
    b)2正常形式:这表明所有候选键都链接在主键上。 当存在多列主键时,会出现与2范式有关的问题。
    c)第三范式:这表示如果表中未出现传递依赖项,则为第三范式

  • 什么是错误ORA-01000:超出最大打开游标 (What is error ORA-01000: maximum open cursors exceeded)

  • There are two common scenarios in which this error might occur:
    (1) When the value for OPEN_CURSORS is very low compared to the demand of cursors in your program. It is possible to increase the value of OPEN_CURSORS but discouraged, as it doesn’t identify the problem in your program and only allocates more resources than it should, which is very inefficient and wasteful for a developer.
    (2) A more recommended approach is considering your program and search for problems that are concerning cursors. Take note of the implicit and explicit cursors as they also take up the available cursors available. Common issues of developers having this problem is they failed to close their cursor that is inside a loop, which in turn creates the error.

    在两种常见情况下,可能会发生此错误:
    (1)与程序中游标的需求相比,OPEN_CURSORS的值非常低。 可以增加OPEN_CURSORS的值但不鼓励使用,因为它不能识别程序中的问题,并且只能分配比应有的资源更多的资源,这对于开发人员而言非常低效且浪费。
    (2)一种更推荐的方法是考虑程序并搜索与游标有关的问题。 注意隐式和显式游标,因为它们也会占用可用的游标。 开发人员遇到此问题的常见问题是,他们无法关闭循环内的游标,从而导致错误。

  • 什么是错误ORA-03113:通信通道上的文件结束? (What is error ORA-03113: end-of-file on communication channel?)

  • This is a common error which developers tend to overthink. A rather no-brainer cause for this is that the physical connection between the client’s end and the database server might have been severed. Check your connection and make sure the cable properly connected to its intended port. Also make sure to check the status of the server if it is still functioning, some developers report an issue in their server that causes this error.

    这是开发人员容易想到的常见错误。 这样做的一个显而易见的原因是客户端与数据库服务器之间的物理连接可能已断开。 检查您的连接,并确保电缆正确连接到其预期的端口。 此外,请确保检查服务器的状态(如果它仍在运行),一些开发人员会报告服务器中的问题,从而导致此错误。

    Most of the time, the problem lies on the physical layer and nothing more. But if you think the problem lies on the server itself, try accessing the alert log and take note of the catalog.

    大多数时候,问题出在物理层,仅此而已。 但是,如果您认为问题出在服务器本身上,请尝试访问警报日志并记下目录。

  • 将日期转换为儒略格式的例子是什么? (What is an example of translating a date into Julian Format?)

  • We make use of the String Format: ‘J’
    For example, SQL > select to_char(to_date(‘5-Dec-2017’,’dd-mon-yyyy’),’J’)

    我们使用字符串格式:'J'
    例如,SQL>选择to_char(to_date('5-Dec-2017','dd-mon-yyyy'),'J')

  • 什么是一致性? (What is consistency?)

  • Consistency simply means that each user sees the consistent view of the data.
    Consider an example: there are two users A and B. A transfers money to B’s account. Here the changes are updated in A’s account (debit) but until it will be updated to B’s account (credit), till then other users can’t see the debit of A’s account. After the debit of A and credit of B, one can see the updates. That’s consistency.

    一致性只是意味着每个用户都能看到一致的数据视图。
    考虑一个例子:有两个用户A和B。A将钱转入B的帐户。 在这里,更改将在A的帐户(借方)中更新,但直到将其更新为B的帐户(贷方)为止,然后其他用户才能看到A的帐户的借方。 在借记A和贷记B之后,可以看到更新。 这就是一致性。

  • DML对View施加了哪些各种限制? (What are the various restrictions imposed on View in terms of DML?)

  • These are you are NOT ALLOWED to delete rows of Views containing: The Distinct keyword, Group Functions, The Pseudocolumn ROWNUM keyword, or a Group by Clause.

    这些是不允许您删除包含以下内容的视图的行:Distinct关键字,Group Functions,Pseudocolumn ROWNUM关键字或Group by子句。

    The other restriction is that you are NOT ALLOWED to change contents in a View that contains: The Distinct keyword, Group Functions, The Pseudocolumn ROWNUM keyword, a Group by Clause, or Expression-defined Columns (e.g. number_of_days * 7)
    Few restrictions of DML operations on Views are:
    You cannot DELETE a row if the View contains the following:
    1) Group Functions
    2) A Group By clause
    3) The Distinct Keyword
    4) The Pseudo column ROWNUM Keyword.
    You cannot MODIFY data in a View if it contains the following:
    1) Group Functions
    2) A Group By clause
    3) The Distinct Keyword
    4) The Pseudo column ROWNUM Keyword.
    5) Columns defined by expressions (Ex; Salary * 12)

    另一个限制是您不允许在包含以下内容的视图中更改内容:Distinct关键字,Group Functions,Pseudocolumn ROWNUM关键字,Group by子句或表达式定义的列(例如number_of_days * 7)
    对View进行DML操作的一些限制是:
    如果视图包含以下内容,则无法删除行:
    1)组功能
    2)组别子句
    3)独特的关键字
    4)伪列ROWNUM关键字。
    如果视图中包含以下内容,则无法修改数据:
    1)组功能
    2)组别子句
    3)独特的关键字
    4)伪列ROWNUM关键字。
    5)由表达式定义的列(例如;工资* 12)

  • 什么是PL / SQL记录? (What is PL/SQL Records?)

  • PS/SQL Records is type of data structure that contain a set of data(can be of various types), or distinct information values that can be referenced with each other as fields. They are useful for classifying and retrieving data with common attributes or properties. With this, it is much easier to identify similar data by tracing the attributes.
    PL/SQL can manage three types of records:
    • Table based records
    • Programmer based records
    • Cursor based records

    PS / SQL记录是一种数据结构,其中包含一组数据(可以是各种类型),或者可以作为字段相互引用的不同信息值。 它们对于分类和检索具有公共属性或属性的数据很有用。 这样,通过跟踪属性来识别相似数据要容易得多。
    PL / SQL可以管理三种类型的记录:
    •基于表的记录
    •基于程序员的记录
    •基于游标的记录

  • PL / SQL中的范围和可见性是什么? (What is scope and visibility in PL/SQL?)

  • The scope of a variable pertains to range within PL/SQL that it can be referenced. To expound, it is the block that contains the linked blocks along with the declared block.

    变量的范围与PL / SQL中可以引用的范围有关。 要说明的是,该块包含链接的块以及声明的块。

    The definition of scope and visibility for a variable is quite close with the only difference being if you have to qualify the variable. The scope of a variable refers to the region (breadth) of code where the variable can be referenced. The visibility refers to the region of code you can reference the variable without qualifying it. So, hopefully you can see, visibility is a subset of the scope and requires the variable to be qualified (told where it comes from) in order to use. An example is clearly the best option here to help explain. Consider the PL/SQL code:

    变量的范围和可见性的定义非常接近,唯一的区别是您是否必须限定变量。 变量的范围是指可以引用该变量的代码区域(宽度)。 可见性是指您可以在不限定变量的情况下引用该变量的代码区域。 因此,希望您可以看到,可见性是作用域的子集,并且要求变量必须经过限定(告诉变量来源)才能使用。 一个例子显然是帮助解释的最佳选择。 考虑一下PL / SQL代码:

    SQL>CREATE OR REPLACE PROCEDURE proceduretest ISvar1 VARCHAR2(1); -- scope of proceduretest.var1 beginsPROCEDURE prodOneISvar1 VARCHAR2(1); -- scope of prodOne.var1 beginsBEGIN -- visible prodOne.var1var1:= 'prodOne';DBMS_OUTPUT.PUT_LINE('In procedure prodOne, var1 = ' || var1);-- even though proceduretest.var1 is not visible it can still be qualified/referencedDBMS_OUTPUT.PUT_LINE('In procedure prodOne, proceduretest.var1 = ' || proceduretest.var1);END; -- scope of prodOne.var1 endsPROCEDURE prodTwoISBEGIN -- visible proceduretest.var1DBMS_OUTPUT.PUT_LINE('In procedure prodTwo, var1(proceduretest) = ' || var1);DBMS_OUTPUT.PUT_LINE('In procedure prodOne, proceduretest.var1 = ' || proceduretest.var1);END;BEGIN -- visible proceduretest.var1var1:='0';DBMS_OUTPUT.PUT_LINE('In proceduretest, var1= ' || var1);prodOne;prodTwo;
    * END; -- scope of proceduretest.var1 ends
    SQL> exec proceduretest
    In proceduretest, var1 = 0
    In procedure prodOne, var1 = prodOne
    In procedure prodOne, proceduretest.var1 = 0
    In procedure prodTwo, var1 (proceduretest) = 0
    In procedure prodOne, proceduretest.var1 = 0
    PL/SQL procedure successfully completed.

    In the sample code above, we can observe the referenced variable, var1 is identical on the procedures. We can also see that var1 is not locally declared within procedure prodTwo. In this instance, the var1 used is the one declared from proceduretest which is visible on the perspective prodTwo. You can still be able to declare it locally like prodOne as well. This code tests the scope and visibility of variable var1 within different procedures. Oracle also provides debugging log to determine the scope of your variables.

    在上面的示例代码中,我们可以观察到所引用的变量var1在过程上是相同的。 我们还可以看到var1不在过程prodTwo中本地声明。 在这种情况下,使用的var1是从proceduretest声明的变量,该变量在透视图prodTwo上可见。 您仍然可以像prodOne一样在本地声明它。 此代码在不同过程中测试变量var1的范围和可见性。 Oracle还提供调试日志以确定变量的范围。

  • 是否可以在PL / SQL中读写文件? (Is it possible to read/write files to-and-from PL/SQL?)

  • By making use of the UTL_FILE package, which was introduced in Oracle 7.3, we can make our PL/SQL code write and read files to and from our computer. However, you still need to receive an access grant by a DBA user to do such an activity. This promotes security and prevent intrusive coding.

    通过使用Oracle 7.3中引入的UTL_FILE包,我们可以使我们的PL / SQL代码在计算机之间读写文件。 但是,您仍然需要获得DBA用户的访问权限才能进行此类活动。 这提高了安全性并防止了侵入式编码。

    For example:

    例如:

    CONNECT / AS SYSDBA

    连接/ AS SYSDBA

    CREATE OR REPLACE DIRECTORY dir AS ‘/temp’;

    创建或替换目录dir为'/ temp';

    GRANT read, write ON DIRECTORY dir to test;

    授予读取权限,在DIRECTORY目录下写入以进行测试;

    To grant the user to access to UTL_FILE:
    GRANT EXECUTE ON UTL_FILE to test;

    授予用户访问UTL_FILE的权限:
    在UTL_FILE上执行GRANT EXECUTE进行测试;

    To write to a File:

    要写入文件:

    DECLARE
    handlerOne UTL_FILE.FILE_TYPE;
    BEGINhandlerOne := UTL_FILE.FOPEN(‘DIR’, ‘tofile’, ‘w’);UTL_FILE.PUTF(handlerOne, ‘Write To File. \n’);UTL_FILE.FCLOSE(handlerOne);
    EXCEPTIONWHEN utl_file.invalid_path THENraise_application_error(-20000, ‘Path is Invalid. Check UTL_FILE_DIR’);
    END;

    To read from a File:

    要读取文件:

    DECLARE
    handlerOne UTL_FILE.FILE_TYPE;
    bufferOne varchar2(4000);
    BEGINhandlerOne := UTL_FILE.FOPEN(‘DIR’, ‘tofile’, ‘r’);UTL_FILE.GET_LINE(handlerOne, bufferOne);Dbms_output.put_line(‘The Contents from the File are: ’ || bufferOne);UTL_FILE.FCLOSE(handlerOne);
    EXCEPTIONWHEN utl_file.invalid_path THENraise_application_error(-20000, ‘Path is Invalid. Check UTL_FILE_DIR’);
    END;
  • 如何在PL SQL中声明固定长度的字符串值 (How to Declare Fixed Length String Value In PL SQL)

  • We can use CHAR to declare fixed length string value. Note that if the assigned string value is smaller then white spaces will be padded to end of it to create the value.

    我们可以使用CHAR声明固定长度的字符串值。 请注意,如果所分配的字符串值较小,则将在其末尾填充空格以创建值。

    DECLAREv1 VARCHAR2 (10) := 'PANKAJ';v2 CHAR (10) := 'PANKAJ';v3 CHAR (6) := 'PANKAJ';
    BEGINIF v1 = v2THENDBMS_OUTPUT.put_line ('v1 = v2');ELSEDBMS_OUTPUT.put_line ('v1 != v2');END IF;IF v1 = v3THENDBMS_OUTPUT.put_line ('v1 = v3');ELSEDBMS_OUTPUT.put_line ('v1 != v3');END IF;END;
  • 我们如何在触发器中实现Rollback或Commit语句? (How can we implement Rollback or Commit statement in a Trigger?)

  • We cannot. It is not logical to put a Rollback or Commit within a Trigger because these statements impose a savepoint which affects the logical transaction processing.

    我们不可以。 将回滚或提交置于触发器内是不合逻辑的,因为这些语句强加了一个保存点,该保存点会影响逻辑事务处理。

  • 如何修复Oracle错误ORA-00942:表或视图不存在 (How to Fix Oracle Error ORA-00942: table or view does not exist)

  • There are two ways to check and fix this error.

    有两种方法可以检查和修复此错误。

    • Check for typo error in your program, also check if the table and views are created or not and you are connecting to correct database.检查程序中是否存在拼写错误,还检查是否创建了表和视图,并且您正在连接到正确的数据库。
    • Check if your user has required permissions or not, this is also one of the reason where you can’t see the table or view.检查您的用户是否具有必需的权限,这也是您无法查看表或视图的原因之一。
  • 我们如何在PL / SQL中调试? (How can we debug in PL/SQL?)

  • We can make use of the DBMS_OUTPUT for printing breakpoint activities. We can also use DBMS_DEBUG.

    我们可以利用DBMS_OUTPUT来打印断点活动。 我们还可以使用DBMS_DEBUG。

  • 是否可以将对象或表作为参数传递给过程? (Is it possible to pass an object or table to a procedure as an argument?)

  • Using database links, we can pass an object type of a certain database into another database. By this, we can pass these as arguments and be used by another procedure that contains the appropriate parameter argument type to receive this object. For example

    使用数据库链接,我们可以将某个数据库的对象类型传递给另一个数据库。 这样,我们就可以将它们作为参数传递,并由另一个包含适当参数实参类型的过程来接收该对象。 例如

    -- Database One: receives the table as an argument and stored to TableTestCREATE OR REPLACE PROCEDURE receiveTable(TableTest DBMS_SQL.VARCHAR2S) IS
    BEGIN--null;
    END;
    /-- Database Two: passes the table as an argument and is hoped to be received by ‘receiveTable’CREATE OR REPLACE PROCEDURE sendTable ISTableTest DBMS_SQL.VARCHAR2S@DBLINK2;
    BEGINreceiveTable @DBLINK2(TableTest);
    END;
    /
  • 我们可以循环提交几次? (How many times can we COMMIT in a loop?)

  • It is advised to commit as least as possible especially within loops or iterative statements. This is to minimize resource over usage on instances that the loops were poorly constructed or no end keyword, resulting in a leak and infinite calls to the COMMIT block. This scenario results in a ORA-1555 error.

    建议尽可能地提交,尤其是在循环或迭代语句中。 这是为了最大程度地减少循环构造不良或没有end关键字的实例上的资源过度使用,从而导致泄漏和对COMMIT块的无限调用。 这种情况下会导致ORA-1555错误。

    In declaring undo or rollback statements, having the least number COMMITS lessens the stress and code execution of these state, resulting in a faster and much more responsive rollbacks.

    在声明撤消或回滚语句时,COMMITS的数目最少,可以减轻这些状态的压力和代码执行,从而使回滚更快且响应速度更快。

    Also it is of good programming habit to allocate the least amount of memory resource as much as possible while keeping the same functionality of the code. This is done by minimizing the overuse of COMMIT within the code.

    同样好的编程习惯是,在保持代码功能相同的同时,分配尽可能少的内存资源。 这是通过最小化代码中对COMMIT的过度使用来完成的。

  • 在运行期间我们如何接受用户的输入? (How do we accept inputs from user during runtime?)

  • The ACCEPT keyword is used to receive inputs from the user. It also allows the received data to be buffered to a variable for storage.
    For example:

    ACCEPT关键字用于接收用户的输入。 它还允许将接收到的数据缓冲到变量中进行存储。
    例如:

    > accept y number prompt 'Enter your desired number: '>declarez number;
    beginz := &y;
    end;
  • 我们如何将Android App连接到Oracle数据库并使用PL / SQL程序代码? (How can we connect an Android App to an Oracle database and use the PL/SQL procedural code?)

  • Before getting into the PL/SQL, we must create a REST API using JSON for establishing connection. You can import the Retrofit libraries along with dependencies to establish communication with your Android App. Then prepare the functions and procedures using PL/SQL, and then once your oracle database is connected you are good to go.

    在进入PL / SQL之前,我们必须使用JSON创建REST API来建立连接。 您可以导入Retrofit库以及相关性,以与Android App建立通信。 然后使用PL / SQL准备功能和过程,然后在连接oracle数据库后就可以使用了。

    That’s all for PL SQL interview questions and answers. It’s a very vast programming language and it’s not feasible to cover everything here, but I have tried to cover most of the important questions asked in the interview. If you think that I have missed any important interview questions, please let me know through comments and I will try to add them to the list.

    PL SQL面试问题和答案就这些了。 这是一种非常广泛的编程语言,在这里涵盖所有内容并不可行,但是我已尝试涵盖采访中提出的大多数重要问题。 如果您认为我错过了任何重要的面试问题,请通过评论让我知道,我将尝试将其添加到列表中。

    翻译自: https://www.journaldev.com/17786/pl-sql-interview-questions-answers

    pl sql面试题

pl sql面试题_PL SQL面试问答相关推荐

  1. sql面试题问答题_SQL面试问答

    sql面试题问答题 SQL interview questions are asked in almost all interviews because database operations are ...

  2. SQL Server高级数据库管理员面试问答

    In this article, we will discuss a number of questions that you may be asked when applying to a seni ...

  3. pl sql mysql 版本_pl sql developer连oracle哪个版本的数据库都可以吗

    使用PL/SQL Developer连接OracleX64版本: •1. 下载32位Oracle InstantClient,并展开到某目录,例如C:\instantclient-basic-nt-1 ...

  4. java常见手写sql面试题_java sql常见面试题

    为管理学员培训信息,建立3个表: S (S#,SN,SD,SA) S#,SN,SD,SA 分别代表学号.学员姓名.所属单位.学员年龄 C (C#,CN ) C#,CN 分别代表课程编号.课程名称 SC ...

  5. oracle常见sql面试题,oracle sql面试题2

    一.简单SQL查询: 1):统计每个部门员工的数目 select dept,count(*) from employee group by dept; 2):统计每个部门员工的数目大于一个的记录 se ...

  6. oracle之sql面试题,oracle sql面试题

    1删除重复记录 delete from t  where t.rowid not in ( select  max(rowid)  from t group by name); 2根据2表的关联列,更 ...

  7. 面试阿里必知的SQL面试题 100讲

    SQL 常见面试题解析 内容简介 本文介绍并分析了 100 道常见 SQL 面试题,主要分为三个模块:SQL 初级查询.SQL 高级查询以及数据库设计与开发.文章内容结构如下图所示: 本文主要使用三个 ...

  8. sql面试题sql语句_第二轮SQL面试问题

    sql面试题sql语句 In this article, we will talk about SQL interview questions and answers that can be aske ...

  9. oracle pl sql面试题,Oracle 面试题库—PL/SQL

    2015-11-21 06:30:02 阅读( 295 ) 1 PL/SQL代表 A  PROCEDURAL LANGUAGE/SQL B  PROGRAM LANGUAGE SQL C  POWER ...

  10. 算法面试必备-----数据库与SQL面试题

    算法面试必备-----数据库与SQL面试题 算法面试必备-----数据库与SQL面试题 1.数据库理论问题 问题:什么是数据库,数据库管理系统,数据库系统,数据库管理员? 问题:什么是元组,码,候选码 ...

最新文章

  1. 二叉搜索树的第 k 大节点(递归,反中序遍历 + 提前返回)
  2. Docker系列 一. CentOS上安装Docker
  3. 介绍Windows Server服务器角色、角色服务和功能
  4. LeetCode每日训练2—有序矩阵中第K小的元素(7.2)
  5. Linux redhat目录下用户管理
  6. 制作WEB在线编辑器-插入HTML标签
  7. javascript 比量str今天的日期是,参数diff
  8. Java中的装饰器设计模式
  9. 存储过程中定义sql语句_学习SQL:用户定义的存储过程
  10. How does RECORDLENGTH affect your exp speed?
  11. get和post方式请求数据,jsonp
  12. Android程序开发:简单电话拨号器
  13. c语言形式参数若为b 4,4月全国计算机等级二级C笔试考试题目
  14. 学好英语网html首页制作,首页英语
  15. 五、pcb文件初始设置
  16. 理解jquery的$.extend()、$.fn和$.fn.extend()
  17. 6个“纽扣”卖2600 索尼动捕设备要捕捉谁?
  18. html/css做一个简单的个人简历
  19. 周末北大学拳散记--搜狐畅游招聘
  20. 怎么将照片压缩变小一点?超实用的几种方法

热门文章

  1. 【Pix4d精品教程】垂直摄影空三加密生成DOM和DSM,并按10m间距提取高程点,生成等高线
  2. AllenNLP框架学习笔记(模型篇之保存与加载)
  3. 常用javascript编码规范
  4. IDA的新手入门指南
  5. 关于一些初级ACM竞赛题目的分析和题解(三)。
  6. 玩转接口测试工具fiddler 教程系列1
  7. 用java写一个博客网站
  8. 计算机仿真是北大核心期刊,计算机仿真 北大核心期刊统计源期刊 CSCD核心期刊...
  9. SCSI代码分析(3)SCSI设备的管理2
  10. 74HC595中文资料