Oracle Definition Variables Summary

Source: Internet
Author: User

First, when you run the Scott password hint error in cmd, you can change this, and Scott's unlock command is:

To log on as a system user:
Cmd
Sqlplus System/tigertiger
Alter user Scott identified by "Tiger" account unlock;

-Learn the structure of blocks
--Learning to define variables (understanding data types) and assigning values
--Understanding: Types of various PL/SQL blocks

--the structure of the block
--Case: According to work number, output employee name
SELECT * from EMP;

--Block!
DECLARE
V_empno number (4);
V_ename VARCHAR2 (10);
BEGIN
V_empno: = & Please enter the work number;
--You must put the query result into a variable
SELECT ename to v_ename from EMP WHERE empno=v_empno;
Dbms_output.put_line (V_ename);
END;

--exception
DECLARE
V_empno number (4);
V_ename VARCHAR2 (10);
BEGIN
V_empno: = & Please enter the work number;
--You must put the query result into a variable
SELECT ename to v_ename from EMP WHERE empno=v_empno;
Dbms_output.put_line (V_ename);

EXCEPTION
When OTHERS Then
Dbms_output.put_line (' Doing something wrong, boss! ‘);
END;

--Summary
DECLARE
--Variable area (not at begin.) defined in end)
BEGIN
--Business code area
Excetipn
--anomaly capture area
END;


--Defining variables (Understanding data types)
--2: Save a value = simple variable; save multiple values = Compound variable

--Simple Variable type: char,varchar2,number,date (also column type), Boolean, table. Field%type
--Compound variable: Table%rowtype,record
DECLARE
V_empno number (4);
V_ename VARCHAR2 (10);
V_job Emp.job%type; --If the field type changes, the script does not need to change
BEGIN
V_empno: = 7566;
SELECT ename,job to v_ename,v_job from EMP WHERE empno=v_empno;
Dbms_output.put_line (V_ename);
IF (v_job= ' MANAGER ') then
Dbms_output.put_line (' manager, have you had dinner? ‘);
END IF;
END;


--You need to put multiple variables in a Record object, ditto
DECLARE
V_empno number (4);
My_row Emp%rowtype;
BEGIN
V_empno: = 7566;
SELECT * into My_row from emp WHERE empno=v_empno;
Dbms_output.put_line (my_row.ename| | ', ' | | My_row.sal);
END;

--Sometimes you don't need an entire column, only a few columns. Now with the record
DECLARE
--Custom Composite type My_emp
TYPE My_emp_type is RECORD (
Yg_name Emp.ename%type,
Yg_sal Emp.sal%type
);
My_row My_emp_type; --Variable name data type
BEGIN
SELECT ename,sal to My_row from EMP WHERE empno=7788;
Dbms_output.put_line (my_row.yg_name| | ', ' | | My_row.yg_sal);
END;

--Extension: Oracle does not have a Boolean type?
--thinking: Sex true= male, false= female. Disadvantages? Gender = confidentiality. So Oracle builds with char (1) instead, 1 = male 2= female 3 = confidential 4 = Shemale

The various collection types of--oracle, corresponding to the Java array.
--Reference variable: Explain the stored procedure later.

--binding variable (executed in command window, binding variable used:)
sql> var name varchar2 (10)
sql> execute:name: = ' Hello ';
PL/SQL procedure successfully completed
Name
---------
Hello

sql> Print name;
Name
---------
Hello

Oracle Definition Variables Summary

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.