Oracle PL/SQL Programming Fifth Edition, chapter III Language Basics

Source: Internet
Author: User
Tags sqlplus

Recently saw a lot of things, also practiced some, I found this thing seems to be a bit into the bottleneck of the feeling, this bottleneck, I think is because the time is too short,

There are not enough exercises, and there are a lot of things that have been done at random. And recently in learning Python, some things are a little confusing, I decided to new

Go through the book and learn every example.


PL/SQL blocks are anonymous or named, and are actually named for those processes, functions, packages, triggers, object types, and so on. The first example in the book is this one.


Insert.sql
CREATE OR REPLACE PROCEDURE get_happy (emp_id_in in number) AUTHID Current_useris l_hiredate DATE;    BEGIN l_hiredate: = SYSDATE-2; INSERT into employees (employee_id, hire_date) VALUES (emp_id_in, l_hiredate); EXCEPTION when Dup_val_on_index and then Dbms_output. Put_Line (' cannot insert. '); end;/

The example in the book is actually a bit of a pit, I look like the data in the table when the database is installed, and then I press it to write, using the HR account login,

The creation of the problem, and later found that it is not at all, and that the error Dup_val_on_index, his book is also wrong.


Here is an anonymous block

Date.sql
DECLARE l_date date;    BEGIN l_date: = SYSDATE-5; Dbms_output. Put_Line (l_date); end;/

I still don't know how to call that process, although I tried it before, but I didn't remember it.

I'm going to try to write a call on my own, I write a process for printing time, and then call it in an anonymous block.

Get_date.sql
CREATE OR REPLACE PROCEDURE get_date (num_in in number) AUTHID Current_useris l_date date;    BEGIN l_date: = sysdate-num_in; Dbms_output. Put_Line (l_date); end;/

Then anonymous blocks are called

Date.sql
BEGIN Get_date (10); end;/

The implementation of the call, the successful output, if your display is successful but no output, it should be not open the output that function.

I am using Sqlplus to run these. sql files, @ xxx.sql

and enter set serverout on in Sqlplus; Use this command to turn on the output function.





Oracle PL/SQL Programming Fifth Edition, chapter III Language Basics

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.