# Package Specification Without a Body in Oracle

## How to Create Package Specification Without a Body in Oracle

In this article, I am going to discuss How to Create Package Specification Without a Body in Oracle with Examples. Please read our previous article where we discussed How to Create Packages in Oracle with Examples. Now, we will try to learn how to create package specifications without a body. We use this method when we want to define global variables. Let’s look at a sample example and see how this works.

```create or replace package global_Measurement
is
c_mile_to_km   constant number:=1.6093;
c_kilo_to_mile constant number:=0.6214;
end;
```

From the above example, we can see that we have defined two variables c_mile_to_km and c_kilo_to_mile. When we say ‘c_’ this indicates a constant variable. So, the variable c_mile_to_km is used to convert mile to kilometer. The constant number is 1.6093. So, if we want to convert mile to km, we have to multiply with 1.6093.

Similarly, we have the variable c_kilo_to_mile which converts kilometer to mile. In order to convert kilometre to mile we have to use the constant number 0.6214. So, in this example, we use only package without package body. This is only a package specification. We can use global variables like this. Let’s go ahead and compile this package. So, the package is now successfully compiled. We can invoke the package by using execute.

execute dbms_output.put_line(’60 mile:=’||60* global_Measurement.c_mile_to_km||’ KM’ );

Let’s try to execute this statement and see the conversion. We can see the 60 miles are converted to 96.558 Km. Let’s now check the other conversion.

execute dbms_output.put_line(‘100 KM:=’||100* global_Measurement.c_kilo_to_mile||’ Mile’ ); So, this conversion is also working fine. We have learned that we can use packages without a package body in order to define global variables. Let’s do some other trick. Let’s create a function to read values from this package.

```create or replace function get_mile_to_km
( p_value number )
return number
is
begin
return p_value* global_Measurement.c_mile_to_km;
end;
```

We have created a function named get_mile_to_km which takes a parameter as input and multiple the value of the parameter with the constant value of the global_measurement package and c_mile_to_km constant value. This function will return the value of the constant number multiplied by the p_value. Let’s go ahead and compile this function. So, the function is compiled successfully. We can use this function in the select statement and try to get the kilometer conversion.

select get_mile_to_km(100) from dual; We can see the output of 100 miles is converted to 160.93 km. The last step is can define a procedure or a function inside PL/SQL block, but this will be used only in this block.

```declare
function get_sysdate
return date
is
begin
return sysdate;
end;
begin
dbms_output.put_line(get_sysdate);
end;
```

This PL/SQL block will take sysdate as input and return the date as output. We have functions to describe the sysdate but we trying to show that we can declare the function inside the PL/SQL block. We can call this function as the local function and this is limited to only this block. Let’s go ahead and execute this block. So, this function is displaying the system date. So, we can create the package specification without the package body.

In the next article, I am going to discuss Package Components in Oracle with Examples. Here, in this article, I try to explain How to Create Package Specifications Without a Body in Oracle with Examples. I hope you enjoy this How to Create Package Specification without Body in Oracle article.
{"ft_lang_label":"__label__en","ft_lang_prob":0.80494374,"math_prob":0.8229699,"size":3658,"snap":"2023-40-2023-50","text_gpt3_token_len":829,"char_repetition_ratio":0.13711001,"word_repetition_ratio":0.048275862,"special_character_ratio":0.22607982,"punctuation_ratio":0.12696148,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97628266,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12],"im_url_duplicate_count":[null,1,null,1,null,1,null,1,null,1,null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-29T04:04:33Z\",\"WARC-Record-ID\":\"<urn:uuid:4ae3cf31-ccdd-45bd-adde-335708149328>\",\"Content-Length\":\"163078\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7d7fb16a-925f-4ead-b69a-e7ed7a2c07be>\",\"WARC-Concurrent-To\":\"<urn:uuid:55d79aec-a668-4177-82fe-c886e5645d8d>\",\"WARC-IP-Address\":\"3.210.81.252\",\"WARC-Target-URI\":\"https://dotnettutorials.net/lesson/package-specification-without-body-in-oracle/\",\"WARC-Payload-Digest\":\"sha1:HA3VUUQG324ATX5G5YSYB53F2EFKO32L\",\"WARC-Block-Digest\":\"sha1:X2JOHVANXROULDN4IYQ7LAQZCTUOLKMS\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510481.79_warc_CC-MAIN-20230929022639-20230929052639-00726.warc.gz\"}"}