Skip to main content

Posts

Reader's message

Dear readers, Apologies! I have been away so long since my last post.  Here you go! I will try to continue my blogging at least frequently if not everyday. Thank you! Enjoy learning!!!

4 Qs 4 Answers

1. How can I get recent 10 records out of 100 records? SELECT * FROM (Select * from employee order by rowid desc) WHERE ROWNUM < 11 2. When would you use inline view in sub query? You may use inline view when you want to cut short multi-join of tables. 3.  How to select the recently updated records from the table?   There is no provision you can use to find out the records from the table. You may use auditing tables with the help of Triggers. 4.  Display the number value in words? Use the date function to achieve the results. select to_char(to_date(999999,'j'),'jsp') from dual; But it is better you write your own translate function because it doesnt support beyond 999999.  Higher range might work in 64-bit OS.

Objects becoming INVALID !!!!

Consider you are working on a front-end change (.net packages or Java libraries) and you are compiling the objects. Say, the code you newly introduced makes call to DB packages which have not been touched. When rebuilding the front-end changes, you will see all the Called-packages becoming INVALID.  If this is the case, you need to check the REMOTE_DEPENDENCIES_MODE parameter's value. If it is TIMESTAMP, then change it to SIGNATURE to avoid such issues. You can do this in the following way if you have permission for Alter System . ALTER SYSTEM SET REMOTE_DEPENDENCIES_MODE = SIGNATURE; Happy learning!

PLSQL Programming Part 5 - CURSOR AND ITS ATTRIBUTES

/** What is a cursor? A cursor is a pointer that points a set of records for processing. Private SQL area is where cursor results are placed. Implicit cursors and Explicit cursors are two types of cursors. There are a number of ways a cursor can be declared and used based on the requirement. They are as follows: 1. Simple FOR loop cursor 2. Explicit declaration and invoking it ***/ clear screen set serveroutput on size 100000 declare --Cursor Declaration cursor cur_Customer_Data is Select * from cust_table; cur_Variable cur_Customer_Data%rowtype; -- Cursor variable to hold recordset var1 cust_table%rowtype; -- variable to hold data on FOR loop cursor begin dbms_output.put_line('-------------------------------------------------------------------'); dbms_output.put_line('FOR loop started at => '||to_char(sysdate,'hh:mi:ss')); dbms_output.put_line('-------------------------------------------------------------------'); for...

PLSQL Programming part 4 - SQL joins

/** Do the following exercises for learning SQL joins Pre-requisites: You must have CREATE privilege and some space allocated for you **/ create table temp1 ( cust_id number, cust_name varchar2(100), addr1 varchar2(40), addr2 varchar2(40), addr3 varchar2(40), addr4 varchar2(40), pincode varchar2(40), constraint cust_pk primary key ( cust_id ) ); / create table service_tbl ( cust_id number, service_no number, start_date date, end_date date, plan_type varchar2(10), foreign key (cust_id) references temp1(cust_id) ); / alter table temp1 rename to cust_table; Select * from cust_table; insert into cust_table values(100,'CUSTOMER 1','ADDRESS CODE 1','ADDRESS CODE 2','ADDRESS CODE 3','ADDRESS CODE 4',11111); insert into cust_table values(200,'CUSTOMER 2','ADDRESS CODE 1','ADDRESS CODE 2','ADDRESS CODE 3','ADDRESS CODE 4',11111); insert into cust_table values(300,'CUSTOMER 3...

PLSQL programming ( Learn by examples - Part 3 )

/** In this section , lets learn the following. How to use a for loop to process multiple records... **/ set serveroutput on size 100000 begin --Select objects of table type that are valid under the schema Susil for var in (Select * from all_objects where object_name not like '%$%' and object_name in ('EMPLOYEE','EMP') and status='VALID' and owner='SUSIL') loop if var.object_type='TABLE' then /* Dbms_metadata package provides us a function get_ddl to get the data definition on object. For your understanding , i have just chosen two tables in this example If you remove Object_name condition in the above SQL , it will print DDL definitions for all tables under the specified schema **/ dbms_output.put_line('====================================================================='); dbms_output.put_line('Table name =>'||var.objec...

PLSQL programming ( Learn by examples - Part 2 )

/*** Learn by examples: Write a PLSQL block to use Select , insert , delete , update statements in it Purpose : Use of DML statements in Oracle PLSQL SQL is the cursor placed in memory during DML operation in PLSQL block. rowcount is SQL's attribute to know how many rows affected of that particular DML query..... ***/ clear screen set serveroutput on DECLARE ENAME VARCHAR2(20); BEGIN SELECT EMP_NAME INTO ENAME FROM EMPLOYEE WHERE EMP_ID='E1'; --Syntax for Select statement in PLSQL is different. It has INTO clause to save values in variable DBMS_OUTPUT.PUT_LINE('EMP NAME '||ENAME); DBMS_OUTPUT.PUT_LINE('No of rows selected out of SELECT statement '||SQL%rowcount); delete from employee where dept_no >25; DBMS_OUTPUT.PUT_LINE('No of rows deleted out of DELETE statement '||SQL%rowcount); update employee set dept_no = 10 where dept_no DBMS_OUTPUT.PUT_...