1 / 15

Practice 3

Practice 3. Ms. Reham Alhaweal rhaweal@gmail.com. 1) Identify valid and invalid identifier names :. 1) Identify valid and invalid identifier names:. 2) Identify valid and invalid variable declaration and initialization :.

isolde
Télécharger la présentation

Practice 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Practice 3 Ms. RehamAlhaweal rhaweal@gmail.com

  2. 1) Identify valid and invalid identifier names:

  3. 1) Identify valid and invalid identifier names:

  4. 2) Identify valid and invalid variable declaration and initialization:

  5. 2) Identify valid and invalid variable declaration and initialization:

  6. Examine the following anonymous block and choose the appropriate statement. (Note: the ServerOutput already sets ON)

  7. The block executes successfully and print “Mohammed.” • The block returns an error because the fname variable is used without initializing. • The block executes successfully and print “null Mohammed.” • The block returns an error because you cannot use the DEFAULT keyword to initialize a variable of type VARCHAR2. • The block returns an error because the v_fname variable is not declared. • The block executes successfully and print “Mohammed.” • The block returns an error because the fname variable is used without initializing. • The block executes successfully and print “null Mohammed.”

  8. Create and execute a simple anonymous block: • That outputs:“Hello World.” • Add a declarative section to this PL/SQL block. In the declarative section, declare the following variables: • Variable v_today of type DATE. Initialize today with SYSDATE. • Variable v_tomorrow of type today. Use %TYPE attribute to declare thisvariable. • In the executable section, initialize the tomorrow variable with an expression, which calculates tomorrow’s date (add one to the value in today). Print the value of today and tomorrow after printing “Hello World.” . Also print your name. • Execute and save this script as lab_02_04.sql

  9. SET SERVEROUTPUT DECLARE v_today DATE:=SYSDATE; v_tomorrowv_today%TYPE; BEGIN v_tomorrow := v_today+1; DBMS_OUTPUT.PUT_LINE('Hello World ..' || CHR(10)||'Today is:'||v_today||CHR(10)||'Tomorrow will be : ' || v_tomorrow|| CHR(10) ||’My name is : YOUR NAME'); END; /

  10. Edit the lab_02_04.sql script • Add code to create two bind variables. Create bind variables b_basic_percent and b_pf_percent of type NUMBER. • In the executable section of the PL/SQL block, assign the values 45 and 12 to b_basic_percent and b_pf_percent, respectively. • Terminate the PL/SQL block with “/” and display the value of the bind variables by using the PRINT command. • Execute and save your script file as lab_02_05.sql

  11. SET SERVEROUTPUT ON SET AUTOPRINT ON VARIABLE b_basic_percent NUMBER; VARIABLE b_pf_percent NUMBER; DECLARE v_today DATE:=SYSDATE; v_tomorrowv_today%TYPE; BEGIN v_tomorrow := v_today+1; DBMS_OUTPUT.PUT_LINE('Hello World '||CHR(10)|| 'Today is: '|| v_today|| CHR(10)||'Tomorrow will be : '||v_tomorrow||CHR(10)|| 'My name is : YOU NAME'); :b_basic_percent := 45; :b_pf_percent := 12; END; /

  12. Using Product Sales database, create and execute an anonymous block that allow user to inter a product ID and print a product name of a it.

  13. SET SERVEROUTPUT ON SET VERIFY OFF DECLARE PRODUCTID NUMBER (10) := &PRODUCTID; P_NAME PRODUCTS.PRODUCT_NAME%TYPE; BEGIN SELECT PRODUCT_NAME INTO P_NAME FROM PRODUCTS WHERE PRODUCT_ID = PRODUCTID; DBMS_OUTPUT.PUT_LINE(CHR(10) ||'Product name is : ' || P_NAME); END; /

More Related