Académique Documents
Professionnel Documents
Culture Documents
select
employee_number EMPNO,
full_name NAME
from per_people_f
order by
decode(:P2_ORDER_BY,'EMPNO',empno,null)
, decode(:P2_ORDER_BY,'NAME',name,null)
, decode(:P2_ORDER_BY,'EMPNO,FULL_NAME',empno,
name,null)
Posted by sravan at 7:03 PM No comments: Links to this post
Labels: SQL Scripts
Follow the simple steps below to send an sms using your cell phone through a pl/sql code.
2. We need to execute the above procedure so as to send SMS. The systax is as follows:
Note: In place of the '9886012345@ideacellular.net' you need to provide your mobile number if
your operator is Idea. You can refer the following list of mobile operator and the area of the
service to use them for sending messages.
return l_return;
end;
/
Twelve undecillion Three Hundred Forty-Five decillion Six Hundred Seventy-Eight nonillion
Nine Hundred One octillion Two Hundred Thirty-Four septillion Five Hundred Sixty-Seven
sextillion Eight Hundred Ninety quintillion One Hundred Twenty-Three quadrillion Four
Hundred Fifty-Six trillion Seven Hundred Eighty-Nine billion Twelve million Three Hundred
Forty-Five thousand Six Hundred Seventy-Eight
Posted by sravan at 6:53 PM No comments: Links to this post
Labels: SQL Scripts
ELSE
IF L_ASSIGNMENT_NUMBER IS NULL THEN
L_ERROR_MESSAGE := L_ERROR_MESSAGE||'NO SUCH EMPLOYEE EXISTS *';
END IF;
IF L_EFFECTIVE_DATE_VALID IS NULL THEN
L_ERROR_MESSAGE := L_ERROR_MESSAGE||'PLEASE PROVIDE CORRECT
EFFECTIVE DATE *';
END IF;
IF I.NEW_SALARY IS NULL THEN
L_ERROR_MESSAGE := L_ERROR_MESSAGE||'PLEASE PROVIDE CORRECT
SALARY *';
END IF;
IF L_APPROVED IS NULL THEN
L_ERROR_MESSAGE := L_ERROR_MESSAGE||'PLEASE PROVIDE CORRECT
APPROVED STATUS *';
END IF;
END PRC_EMPSAL_UPDATE;
/
Posted by sravan at 9:42 AM No comments: Links to this post
Labels: API'S, HRMS Queries, SQL Scripts
-- TO VALIDATE EFFECTIVE_DATE
IF I.EFFECTIVE_DATE >= L_EFFECTIVE_DATE THEN
L_EFFECTIVE_DATE_VALID := 1;
ELSE
L_EFFECTIVE_DATE_VALID := NULL;
END IF;
-- TO VALIDATE THE ORGANIZATION WHICH IS IN STAGING TABLE
BEGIN
SELECT ORGANIZATION_ID INTO L_ORGANIZATION_ID
FROM HR_ALL_ORGANIZATION_UNITS
WHERE NAME = I.NEW_ORGANIZATION;
DBMS_OUTPUT.PUT_LINE('L_ORGANIZATION_ID:'||L_ORGANIZATION_ID);
EXCEPTION
WHEN OTHERS THEN
ERROR_MESSAGE1:= ERROR_MESSAGE1||' '||SQLERRM||' *';
END;
DBMS_OUTPUT.PUT_LINE(L_EFFECTIVE_START_DATE);
IF L_EFFECTIVE_START_DATE IS NOT NULL THEN
UPDATE EMP_ORG_UPDATE_STG SET UPDATE_STATUS = 'S' WHERE ROWID =
I.ROWID;
COMMIT;
ELSE
UPDATE EMP_ORG_UPDATE_STG SET UPDATE_STATUS = 'E', ERROR_MESSAGE =
ERROR_MESSAGE1||' UNKNOWN ERROR FROM API *' WHERE ROWID = I.ROWID;
COMMIT;
END IF;
select user_id,listagg (login_id, ',') WITHIN GROUP (ORDER BY login_id) login_id from
(select user_id,login_id from fnd_logins
where SESSION_NUMBER < (200)
and user_id in (1179,1178)
) group by user_id
CURSORS
Cursor is a pointer to memory location which is called as context area which contains the information
necessary for processing, including the number of rows processed by the statement, a pointer to the parsed
representation of the statement, and the active set which is the set of rows returned by the query.
Cursor contains two parts
Header
Body
Header includes cursor name, any parameters and the type of data being loaded.
Body includes the select statement.
Ex:
Cursor c(dno in number) return dept%rowtype is select *from dept;
In the above
Header cursor c(dno in number) return dept%rowtype
Body select *from dept
CURSOR TYPES
Implicit (SQL)
Explicit
Parameterized cursors
REF cursors
Explicit Cursor: The set of rows returned by a query can consist of zero, one, or multiple rows, depending on
how many rows meet your search criteria. When a query returns multiple rows, you can explicitly define a
cursor to process the rows. You use three commands to control the cursor:
CURSOR STAGES
Open
Fetch
Close
Implicit Cursors: ORACLE implicitly opens a cursor to process each SQL statement not associated with an
explicitly declared cursor.PL/SQL lets you refer to the most recent implicit cursor as the SQL cursor. So,
although you cannot use the OPEN,
FETCH, and CLOSE statements to control an implicit cursor, you can still use cursor attributes to access
information about the most recently executed SQL statement.
CURSOR ATTRIBUTES
%found
%notfound
%rowcount
%isopen
%bulk_rowcount
%bulk_exceptions
CURSOR DECLERATION
Syntax:
Cursor is select statement;
Ex:
Cursor c is select *from dept;
CURSOR LOOPS
Simple loop
While loop
For loop
SIMPLE LOOP
Syntax:
Loop
Fetch into ;
Exit when % notfound;
;
End loop;
Ex:
PgSQL
1 <span style="color: #3366ff;"><em>DECLARE
2 cursor c is select * from student;
3 v_stud student%rowtype;
4 BEGIN
5 open c;
6 loop
7 fetch c into v_stud;
8 exit when c%notfound;
9 dbms_output.put_line('Name = ' || v_stud.name);
10 end loop;
11 close c;
12 END;</em></span>
Output:
Name = saketh
Name = srinu
Name = satish
Name = sudha
WHILE LOOP
Syntax:
While % found loop
Fetch nto ;
;
End loop;
Ex:
PgSQL
1 <span style="color: #3366ff;"><em>DECLARE
2 cursor c is select * from student;
3 v_stud student%rowtype;
4 BEGIN
5 open c;
6 fetch c into v_stud;
7 while c%found loop
8 fetch c into v_stud;
9 dbms_output.put_line('Name = ' || v_stud.name);
10 end loop;
11 close c;
12 END;</em></span>
Output:
Name = saketh
Name = srinu
Name = satish
Name = sudha
FOR LOOP
Syntax:
for in loop
;
End loop;
Ex:
PgSQL
1 <span style="color: #3366ff;"><em>DECLARE
2 cursor c is select * from student;
3 BEGIN
4 for v_stud in c loop
5 dbms_output.put_line('Name = ' || v_stud.name);
6 end loop;
7 END;</em></span>
Output:
Name = saketh
Name = srinu
Name = satish
Name = sudha
PARAMETARIZED CURSORS
This was used when you are going to use the cursor in more than one place with different values for the same
where clause.
Cursor parameters must be in mode.
Cursor parameters may have default values.
The scope of cursor parameter is within the select statement.
Ex:
PgSQL
1 <span style="color: #3366ff;"><em>DECLARE
2 cursor c(dno in number) is select * from dept where deptno = dno;
3 v_dept dept%rowtype;
4 BEGIN
5 open c(20);
6 loop
7 fetch c into v_dept;
8 exit when c%notfound;
9 dbms_output.put_line('Dname = ' || v_dept.dname || ' Loc = ' || v_dept.loc);
10 end loop;
11 close c;
12 END;
13 Output:
14 Dname = RESEARCH Loc = DALLAS</em></span>
CURSOR EXPRESSIONS
You can use cursor expressions in explicit cursors.
You can use cursor expressions in dynamic SQL.
You can use cursor expressions in REF cursor declarations and variables.
You cannot use cursor expressions in implicit cursors.
Oracle opens the nested cursor defined by a cursor expression implicitly as soon as it fetches the data
containing the cursor expression from the parent or outer cursor.
Nested cursor closes if you close explicitly.
Nested cursor closes whenever the outer or parent cursor is executed again or closed or canceled.
Nested cursor closes whenever an exception is raised while fetching data from a parent cursor.
Cursor expressions cannot be used when declaring a view.
Cursor expressions can be used as an argument to table function.
You cannot perform bind and execute operations on cursor expressions when using the cursor expressions in
dynamic SQL.
USING NESTED CURSORS OR CURSOR EXPRESSIONS
PgSQL
1 <span style="color: #3366ff;"><em>Ex:
2 DECLARE
3 cursor c is select ename,cursor(select dname from dept d where e.empno = d.deptno) from emp e;
4 type t is ref cursor;
5 c1 t;
6 c2 t;
7 v1 emp.ename%type;
8 v2 dept.dname%type;
9 BEGIN
10 open c;
11 loop
12 fetch c1 into v1;
13 exit when c1%notfound;
14 fetch c2 into v2;
15 exit when c2%notfound;
16 dbms_output.put_line('Ename = ' || v1 || ' Dname = ' || v2);
17 end loop;
18 end loop;
19 close c;
20 END;</em></span>
CURSOR CLAUSES
Return
For update
Where current of
Bulk collect
RETURN
Cursor c return dept%rowtype is select *from dept;
Or
Cursor c1 is select *from dept;
Cursor c return c1%rowtype is select *from dept;
Or
Type t is record(deptno dept.deptno%type, dname dept.dname%type);
Cursor c return t is select deptno, dname from dept;
FOR UPDATE AND WHERE CURRENT OF
Normally, a select operation will not take any locks on the rows being accessed. This will allow other sessions
connected to the database to change the data being selected. The result set is still consistent. At open time,
when the active set is determined, oracle takes a snapshot of the table. Any changes that have been committed
prior to this point are reflected in the active set. Any changes made after this point, even if they are committed,
are not reflected unless the cursor is reopened, which will evaluate the active set again.
However, if the FOR UPDATE caluse is pesent, exclusive row locks are taken on the rows in the active set
before the open returns. These locks prevent other sessions from changing the rows in the active set until the
transaction is committed or rolled back. If another session already has locks on the rows in the active set, then
SELECT FOR UPDATE operation will wait for these locks to be released by the other session. There is no
time-out for this waiting period. The SELECTFOR UPDATE will hang until the other session releases the
lock. To handle this situation, the NOWAIT clause is available.
Syntax:
Select from for update of column_name [wait n];
If the cursor is declared with the FOR UPDATE clause, the WHERE CURRENT OF clause can be used in an
update or delete statement.
Syntax:
Where current of cursor;
PgSQL
1 <span style="color: #3366ff;"><em>Ex:
2 DECLARE
3 cursor c is select * from dept for update of dname;
4 BEGIN
5 for v in c loop
6 update dept set dname = 'aa' where current of c;
7 commit;
8 end loop;
9 END;</em></span>
BULK COLLECT
This is used for array fetches
With this you can retrieve multiple rows of data with a single roundtrip.
This reduces the number of context switches between the pl/sql and sql engines.
Reduces the overhead of retrieving data.
You can use bulk collect in both dynamic and static sql.
You can use bulk collect in select, fetch into and returning into clauses.
SQL engine automatically initializes and extends the collections you reference in the bulk collect clause.
Bulk collect operation empties the collection referenced in the into clause before executing the query.
You can use the limit clause of bulk collect to restrict the no of rows retrieved.
You can fetch into multible collections with one column each.
Using the returning clause we can return data to the another collection.
BULK COLLECT IN FETCH
PgSQL
1 <span style="color: #3366ff;"><em>Ex:
2 DECLARE
3 Type t is table of dept%rowtype;
4 nt t;
5 Cursor c is select *from dept;
6 BEGIN
7 Open c;
8 Fetch c bulk collect into nt;
9 Close c;
10 For i in nt.first..nt.last loop
11 dbms_output.put_line('Dname = ' || nt(i).dname || ' Loc = ' ||
12 nt(i).loc);
13 end loop;
14 END;</em></span>
15 Output:
16 Dname = ACCOUNTING Loc = NEW YORK
17 Dname = RESEARCH Loc = DALLAS
18 Dname = SALES Loc = CHICAGO
19 Dname = OPERATIONS Loc = BOSTON