Stored procedure in package return multiple columns from multiple tables
Hi ,
Can a single stored procedure return multiple column values from different tables.
example:
tabA: col2, tabB:col3,tabC:col4 etc.
one more question:
if a stored procedure like to return 10 columns for a particular record from a single table do i need to define a TYPE statement for each colum like
TYPE col1 is TABLE of varchar
TYPE col2 is TABLE of varchar
here i want to return only one row, not many rows.
thanks
You can try one procedure with OUT or IN/OUT parameters that collect the values from one or more sql statements.
CREATE OR REPLACE PROCEDURE P1
(P_COD IN TABLE.COD%TYPE,
P_DESC1 OUT TABLE1.DESC1%TYPE,
P_DESC2 OUT TABLE2.DESC2%TYPE)
IS
BEGIN
SELECT table1.DESC1, table2.DESC2
INTO P_DESC1, P_DESC2
FROM TABLE1, table2 WHERE
table1.COD = P_COD and
table1.cod = table2.cod ;
END P1;
JP
Similar Messages
-
Count(*) , group by with multiple columns from multiple tables involved
Hi all,
I am relatively new to SQL.
Currently I have these few requirements, to display quite a number of fields from 3 tables for display of report.
In my query I need to:
1.) count(*)
2.) select quite a number of fields from table 1,2,3
However when count(*) is used, grouped by has to be used to.
How do I actually use group by with so many columns to be selected?
I have actually used the query below, but the count(*) returns 1, the correct output should be 3 instead.
select count(*), table1.col1, table1.col2, table1.col3, table2.col3, table2.col4, table2.col6, table3.col1, table3.col4, table3.col5
from table1, table2, table3
where
<conditions>........................
group by table1.col1, table1.col2, table1.col3, table2.col3, table2.col4, table2.col6, table3.col1, table3.col4, table3.col5
I know this group by statement looks very unrefined. How can I select multiple fields from different tables, and yet get the count(*) correctly?
Thank you so much for your time.Hmm yes it actually does return count as 1 for each row. But there are 3 rows returned. E.g.
ctr table1.col1 table1.col2 ..........
1 value1 value1
1 value2 value3
1 value3 value4
If I put the count(*) outside, it returns 3 , the correct output
ctr
3
select count(*) from
select table1.col1, table1.col2, table1.col3, table2.col3, table2.col4, table2.col6, table3.col1, table3.col4, table3.col5
from table1, table2, table3
where
<conditions>
group by table1.col1, table1.col2, table1.col3, table2.col3, table2.col4, table2.col6, table3.col1, table3.col4, table3.col5
Thus I was wondering if it was the group by of multiple colns that resulted in the count stucked at value 1. -
How to update multiple columns from different tables using cursor.
Hi,
i have two tables test1 and test2. i want to udpate the column(DEPT_DSCR) of both the tables TEST1 and TEST2 using select for update and current of...using cursor.
I have a code written as follows :
DECLARE
v_mydept1 TEST1.DEPT_CD%TYPE;
v_mydept2 TEST2.DEPT_CD%TYPE;
CURSOR C1 IS SELECT TEST1.DEPT_CD,TEST2.DEPT_CD FROM TEST1,TEST2 WHERE TEST1.DEPT_CD = TEST2.DEPT_CD AND TEST1.DEPT_CD = 'AA' FOR UPDATE OF TEST1.DEPT_DSCR,TEST2.DEPT_DSCR;
BEGIN
OPEN C1;
LOOP
FETCH C1 INTO v_mydept1,v_mydept2;
EXIT WHEN C1%NOTFOUND;
UPDATE TEST2 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
END LOOP;
COMMIT;
END;
The above code when run says that it runs successfully. But it does not updates the desired columns[DEPT_DSCR].
It only works when we want to update single or multiple columns of same table...i.e. by providing these columns after "FOR UPDATE OF"
I am not sure what is the exact problem when we want to update multiple columns of different tables.
Can anyone help me on this ?oops my mistake.....typo mistake...it should have been as follows --
UPDATE TEST1 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
Now here is the upated PL/SQL code where we are trying to update columns of different tables --
DECLARE
v_mydept1 TEST1.DEPT_CD%TYPE;
v_mydept2 TEST2.DEPT_CD%TYPE;
CURSOR C1 IS SELECT TEST1.DEPT_CD,TEST2.DEPT_CD FROM TEST1,TEST2 WHERE TEST1.DEPT_CD = TEST2.DEPT_CD AND TEST1.DEPT_CD = 'AA' FOR UPDATE OF TEST1.DEPT_DSCR,TEST2.DEPT_DSCR;
BEGIN
OPEN C1;
LOOP
FETCH C1 INTO v_mydept1,v_mydept2;
EXIT WHEN C1%NOTFOUND;
UPDATE TEST1 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
END LOOP;
COMMIT;
END;
Please let us know why it is not updating by using using CURRENT OF -
Stored procedure to update particular key column with increment of +1
Hi,
This is my table
EMPID,NAME
1 SSS
2 AAA
I NEED STORED PROCEDURE TO UPDATE EMPID WITH INCREMENT OF +1.BASED ON
MAX(EMPID).fOr example if i execute stored procedure once it will update empid 2 as 3,
if i run same procedure again it will take increment +1 then emp id should be 4 like that i want output.
Any one please help me on this scenario...937506 wrote:
Hi All,
I have two tables,one is date dimension table,one is fact table.
when we load data through informatica (source as csv file),then key will be populated in fact table based on lookup on
date dimension table.it will create corresponding date key in fact table.
My scenario:we load data in to fact table with etl with "n" number of records only once at a time.
But next time onwords we will update that datekey in fact table through stored procedure.stored procedure
will take only max(date_key) from fact table then update that key as like +1(logic n+1)
If i run stored procedure nextday it will update that record with increment +1.
we wil schedule this storedprocedure to run daily once.For this i need stored procedure..
I think you will clear now................
thxSo, are you saying you want to keep the same data you loaded "yesterday" but update the date_key so it appears as if it was from today?
Still seems strange: why aren't you loading today's data?
Also, you are assuming that the date_key in the date dimension table increments with no gaps: if it was sequence generated, that might not be true. -
Return multiple columns from an analytic function with a window
Hello,
Is it possible to obtain multiple columns from an analytic function with a window?
I have a table with 4 columns, an id, a test id, a date, and the result of a test. I'm using an analytic function to obtain, for each row, the current test value, and the maximum test value in the next 2 days like so:
select
id,
test_id,
date,
result,
MAX ( result ) over ( partition BY id, test_id order by date RANGE BETWEEN CURRENT ROW AND INTERVAL '2' DAY FOLLOWING ) AS max_result_next_two_day
from table
This is working fine, but I would like to also obtain the date when the max result occurs. I can see that this would be possible using a self join, but I'd like to know if there is a better way? I cannot use the FIRST_VALUE aggregate function and order by result, because the window function needs to be ordered by the date.
It would be a great help if you could provide any pointers/suggestions.
Thanks,
Dan
http://danieljamesscott.orgAssuming RESULT is a positive integer that has a maximum width of, say 10,
and assuming date has no time-component:
select
id
,test_id
,date
,result
,to_number(substr(max_result_with_date,1,10)) as max_result_next_two_day
,to_date(substr(max_result_with_date,11),'YYYYMMDD') as date_where_max_result_occurs
from (select
id
,test_id
,date
,result
,MAX(lpad(to_char(result),10,'0')||to_char(date,'YYYYMMDD'))
over (partition BY id, test_id
order by date
RANGE BETWEEN CURRENT ROW AND INTERVAL '2' DAY FOLLOWING )
AS max_result_with_date
from table) -
Help....on stored procedure (or package)
Hi,
I have any problem to create stored procedure in Oracle, Can you help me?
I have to create a stored procedure (or package) in order to reserve the free rooms to the students in the period comprised between the DATE_START and DATE_END.
Table of the present rooms in building BL1 (RM): SEX 1 = M - SEX 2 = F SEX = 0 (ROOM WITHOUT SEX)
BL_ID.....FL_ID.......RM_ID.........SEX......RM_STD.....RM_CAT
BL1.........1..........101..............1........S........ROOM
BL1.........1..........102..............0........D........ROOM
BL1.........1..........103..............2........T........ROOM
BL1.........2..........201..............2........S........ROOM
BL1.........2..........202..............1........D........ROOM
BL1.........2..........203..............1........T........ROOM
BL1.........3..........301..............2........S........APARTMENT
BL1.........3..........302..............2........D........APARTMENT
BL1.........3..........303..............1........T........APARTMENT
BL1.........3..........304..............1........D........APARTMENT
BL1.........3..........305..............0........D........APARTMENT
Table of the students (EM):
EM_ID...........BL_ID.......FL_ID........RM_ID........COD_STUD
SABRINA..........BL1..........1............102.........524505
TAKEM............BL1..........1............103.........569673
SERAFINO.........BL1..........1............103.........589920
STELLA...........BL1..........1............102.........574659
CHIARA...........BL1..........1............101.........587845
VIDAL............BL1..........1............102.........602877
ROSARIA..........BL1..........2............202.........517070
LUCA.............BL1..........2............201.........602743
DANIELA..........BL1..........2............203.........602865
ANNAMARIA........BL1..........3............305.........588721
LUIGI............BL1..........3............304.........546517
Type of rooms (RM_STD):
RM_STD.......STD_EM........DESCRIPTION
D.............4..............DOUBLE
T.............6..............TRIPLE
S.............2..............SINGLE
Tables of the reservations carried out from the students (RMPCT):
EM_ID......BL_ID........FL_ID......RM_ID......DATE_START.......DATE_END.......COD_STUD
CHIARA......BL1.........1..........101.......11/02/2004.......12/02/2004.......587845
CHIARA......BL1.........1..........101.......03/02/2005.......16/02/2005.......587845
SERAFINO....BL1.........1..........102.......12/02/2004.......19/02/2004.......589920
VIDAL.......BL1.........1..........102.......16/02/2004.......01/03/2004.......602877
SERAFINO....BL1.........1..........103.......01/02/2004.......15/02/2004.......589920
TAKEM.......BL1.........1..........103.......04/02/2005.......10/02/2005.......569673
LUCA........BL1.........2..........201.......03/02/2005.......23/02/2005.......602743
ROSARIA.....BL1.........2..........202.......03/02/2005.......16/02/2005.......517070
DANIELA.....BL1.........2..........203.......03/02/2005.......04/02/2005.......602865
LUIGI.......BL1.........3..........301.......03/02/2005.......23/02/2005.......546517
VALERIA.....BL1.........3..........302.......12/02/2004.......16/02/2004.......515348
CHIARA......BL1.........3..........302.......05/02/2004.......15/02/2004.......587845
CHIARA......BL1.........3..........304.......10/02/2004.......12/02/2004.......587845
CHIARA......BL1.........3..........305.......20/01/2004.......04/02/2004.......587845
ANNAMARIA...BL1.........3..........305.......03/02/2005.......16/02/2005.......588721
INPUT PARAMETERS:
CREATE OR REPLACE Procedure RESERVE_ROOMS (stud_name varchar2,
cod_stud varchar2,
bl_in varchar2,
fl_in varchar2,
rm_in in varchar2,
sex_in varchar2,
date_start_in varchar2,
date_end_in varchar2)
CONDITIONS:
verify if there are students in table EM:
select count (1)
into v_appo
from em
where em_id = stud_name
and cod_stud = cod_stud;
if v_appo = 0 then
insert new student:
insert into em (em_id,cod_sud,sex)
values (stud_name,cod_stud,sex_in);
Now I must verify the free rooms in the period comprised between the DATE_START_IN and DATE_END_IN.
I tried this query: (seem correct...have you any idea?)
select bl_id,fl_id,rm_id,RM_STD
from rm
where (bl_id,fl_id,rm_id,RM_STD) not in (select a.bl_id,a.fl_id,a.rm_id,A.RM_STD
from rm a, rmpct b
where a.bl_id=b.bl_id
and a.fl_id=b.fl_id
and a.rm_id=b.rm_id
AND((b.date_start <= TO_DATE(date_start_in, 'dd-mm-YYYY')
AND b.date_end >= TO_DATE(date_end_in, 'dd-mm-YYYY'))
OR ( b.date_end <= TO_DATE(date_end_in, 'dd-mm-YYYY'))
AND b.date_end >= TO_DATE(date_start_in, 'dd-mm-YYYY')
OR ( b.date_start >= TO_DATE(date_start_in, 'dd-mm-YYYY')
and b.date_start <= TO_DATE(date_end_in, 'dd-mm-YYYY')
AND b.date_end >= TO_DATE(date_end_in, 'dd-mm-YYYY'))))
with this query I get all free rooms in period date_start_in - date_end_in, but I must,also,verify if there are double or triple rooms (reserved) with minus of 2 (double) or minus of 3 (triple) students. If there are I can reserved these rooms.
I tried to verify with these steps:
CREATE OR REPLACE VIEW COUNT_EM ( BL_ID,
FL_ID, RM_ID, NUMBER_EM ) AS
(SELECT rm.bl_id, rm.fl_id, rm.rm_id, COUNT(*) as numero_em
FROM em, rm
WHERE em.bl_id(+) = rm.bl_id
AND em.fl_id(+) = rm.fl_id
AND em.rm_id(+) = rm.rm_id
and rm.rm_std in ('S', 'D', 'T')
group by rm.bl_id, rm.fl_id, rm.rm_id)
CREATE OR REPLACE VIEW COUNT_RMPCT ( BL_ID,
FL_ID, RM_ID, STD_EM, NUMBER_RMPCT
) AS
SELECT rm.bl_id, rm.fl_id, rm.rm_id, rmstd.std_em, COUNT(*) as numero_rmpct
FROM rm, rmpct,rmstd
WHERE rmpct.bl_id(+) = rm.bl_id
AND rmpct.fl_id(+) = rm.fl_id
AND rmpct.rm_id(+) = rm.rm_id
and rm.rm_std=rmstd.rm_std
and rm.rm_std in ('S', 'D', 'T')
AND((rmpct.date_start <= TO_DATE(date_start_in', 'dd-mm-YYYY')
AND rmpct.date_end >= TO_DATE(date_end_in, 'dd-mm-YYYY'))
OR ( rmpct.date_end <= TO_DATE(date_end_in, 'dd-mm-YYYY'))
AND rmpct.date_end >= TO_DATE(date_start_in, 'dd-mm-YYYY')
OR ( rmpct.date_start >= TO_DATE(date_start_in, 'dd-mm-YYYY')
and rmpct.date_start <= TO_DATE(date_end_in, 'dd-mm-YYYY')
AND rmpct.date_end >= TO_DATE(date_end_in, 'dd-mm-YYYY')))
group by rm.bl_id, rm.fl_id, rm.rm_id, rmstd.std_em
AND FINALLY:
select a.bl_id, a.fl_id, a.rm_id, a.NUMBER_RMPCT, B.NUMBER_EM, a.std_em, (a.std_em - (a.NUMBER_RMPCT+B.NUMBER_EM)) RM_FREE
from COUNT_RMPCT a, COUNT_EM b
where a.bl_id=b.bl_id
and a.fl_id=b.fl_id
and a.rm_id=b.rm_id
if RM_FREE > 0 THEN there are free rooms (D or T) between those occupied in that period.
Now If the room (bl_in,fl_in,rm_in) is free I can reserve inserting it in the table RMPCT:
INSERT INTO rmpct (bl_id, fl_id, rm_id,em_id,cod_stud,date_start, date_end)
values(bl_in,fl_in,rm_in,stud_name,cod_stud,date_start_in,date_end_in);
If I haven't rm_in (can be null) I must reserve the first free room (random).
after these controls: I update table of the students:
UPDATE em
Set bl_id = BL_IN,fl_id= FL_IN,rm_id=rm_in
where em_id=stud_name
and cod_stud=cod_stud;
Finally I must make a control on the sex of the room, because there are rooms that have sex=0
if RM.SEX <> 0 then
null
else
if rm_cat = 'ROOM' then
UPDATE rm
set sex = sex_in
where bl_id = in
and fl_id = in
and rm_id = in;
if rm_cat = 'APARTMENT' then (update on all rooms)
UPDATE rm
set sex = sex_in
where bl_id = in
and fl_id = in;
IF v_appo > 0 then
Same controls except: insert into em (em_id,cod_sud,sex)
values (stud_name,cod_stud,sex_in);
How I can insert in one stored procedure (or package) all these instructions and controls?
Thanks in advance!In the following demonstation, I have changed the names of some of your variables, in order to standardize them. I have prefaced input parameters with p_ and local variables with v_ and followed them with the name of the column that they are associated with when appropriate. This avoids conflicts with any column names and makes the code easier to read and follow. I have also used table_name.column_name%type to specify the data type associated with the variables instead of using varchar2. That way, if the data type of the columns changes, the code does not have to be updated. This is standard practice.
In your first insert statement, you have attempted to insert sex into the em table, but there is no sex column in the em table data that you displayed, so I removed the sex.
Instead of using a complicated mess of views and such to check whether there is a room available and then assign it, I have used just one select statement to select an available room and used an exception clause that handles a no_data_found exception to deal with when there is no room available.
I have greatly simplified your checking of dates within that select statement.
You were on the right track with the outer joins and grouping and checking for single, double, or triple rooms. Instead of count, I have used sum and nvl2, so that only the occupied rooms are counted and the rows generated by the outer join are zeroes.
I have used the nvl function to allow for null values in the input parameters, so that any room can be selected. I used dbms_random.random to ensure that the rows are ordered randomly, but you can leave that out if it is really not that critical that the result be truly random and any row will do. I have used rownum=1 in an outer query to select just one row.
When you select from a table in pl/sql, you have to select into something. You cannot just issue a select statement, then use an if statement to compare some value in the select statement. For example, you cannot use "if rm.sex ..." you have to select rm.sex into a variable, like v_sex, then use "if v_sex ...". So, I have selected the result of the select statement into local variables, then used those variables for comparisons. I have also used those variables for inserting and updating the appropriate tables, rather than just using the original input parameters, since some of them may have been null.
In the example below, I have demonstrated how the procedure rejects an unavailable room, accepts a specific available room, and randomly assigns a room.
-- procedure:
scott@ORA92> CREATE OR REPLACE PROCEDURE reserve_rooms
2 -- input parameters:
3 (p_em_id IN em.em_id%TYPE,
4 p_cod_stud IN em.cod_stud%TYPE,
5 p_bl_id IN rm.bl_id%TYPE,
6 p_fl_id IN rm.fl_id%TYPE,
7 p_rm_id IN rm.rm_id%TYPE,
8 p_sex IN rm.sex%TYPE,
9 p_date_start IN VARCHAR2,
10 p_date_end IN VARCHAR2)
11 AS
12 -- local variables:
13 v_appo INTEGER;
14 v_bl_id rm.bl_id%TYPE;
15 v_fl_id rm.fl_id%TYPE;
16 v_rm_id rm.rm_id%TYPE;
17 v_rm_cat rm.rm_cat%TYPE;
18 v_sex rm.sex%TYPE;
19 BEGIN
20 -- verify if the student is in table em:
21 SELECT COUNT (*)
22 INTO v_appo
23 FROM em
24 WHERE em_id = p_em_id
25 AND cod_stud = p_cod_stud;
26 -- if the student is not in table em, then insert new student:
27 IF v_appo = 0 THEN
28 INSERT INTO em (em_id, cod_stud)
29 VALUES (p_em_id, p_cod_stud);
30 END IF;
31 BEGIN
32 -- find available room:
33 SELECT bl_id, fl_id, rm_id, sex, rm_cat
34 INTO v_bl_id, v_fl_id, v_rm_id, v_sex, v_rm_cat
35 FROM (SELECT rm.bl_id, rm.fl_id, rm.rm_id, rm.sex, rm.rm_cat
36 FROM rmpct, rm
37 WHERE rm.bl_id = rmpct.bl_id (+)
38 AND rm.fl_id = rmpct.fl_id (+)
39 AND rm.rm_id = rmpct.rm_id (+)
40 AND rm.bl_id = NVL (p_bl_id, rm.bl_id)
41 AND rm.fl_id = NVL (p_fl_id, rm.fl_id)
42 AND rm.rm_id = NVL (p_rm_id, rm.rm_id)
43 AND (rm.sex = p_sex OR rm.sex = 0)
44 AND rmpct.date_start (+) <= TO_DATE (p_date_end, 'DD-MM-YYYY')
45 AND rmpct.date_end (+) >= TO_DATE (p_date_start, 'DD-MM-YYYY')
46 GROUP BY rm.bl_id, rm.fl_id, rm.rm_id, rm.sex, rm.rm_cat, rm.rm_std
47 HAVING SUM (NVL2 (rmpct.rm_id (+), 1, 0))
48 < DECODE (rm_std, 'S', 1, 'D', 2, 'T', 3)
49 ORDER BY DBMS_RANDOM.RANDOM)
50 WHERE ROWNUM = 1;
51 -- reserve room:
52 INSERT INTO rmpct (bl_id, fl_id, rm_id, em_id, cod_stud, date_start, date_end)
53 VALUES (v_bl_id, v_fl_id, v_rm_id, p_em_id, p_cod_stud,
54 TO_DATE (p_date_start, 'DD-MM-YYYY'),
55 TO_DATE (p_date_end, 'DD-MM-YYYY'));
56 -- update students:
57 UPDATE em
58 SET bl_id = v_bl_id, fl_id = v_fl_id, rm_id = v_rm_id
59 WHERE em_id = p_em_id
60 AND cod_stud = p_cod_stud;
61 -- update sex of room or apartment floor:
62 IF v_sex = 0 THEN
63 IF v_rm_cat = 'ROOM' THEN
64 UPDATE rm
65 SET sex = p_sex
66 WHERE bl_id = v_bl_id
67 AND fl_id = v_fl_id
68 AND rm_id = v_rm_id;
69 ELSIF v_rm_cat = 'APARTMENT' THEN
70 UPDATE rm
71 SET sex = p_sex
72 WHERE bl_id = v_bl_id
73 AND fl_id = v_fl_id;
74 END IF;
75 END IF;
76 EXCEPTION
77 -- if no room is available:
78 WHEN NO_DATA_FOUND THEN
79 RAISE_APPLICATION_ERROR (-20001, 'Sorry, there is no such room available.');
80 END;
81 END reserve_rooms;
82 /
Procedure created.
scott@ORA92> SHOW ERRORS
No errors.
-- rejects unavailable room of wrong sex:
scott@ORA92> EXECUTE reserve_rooms ('BARBARA', 654321, 'BL1', 1, 101, 2, '04-02-2005', '10-02-2005')
BEGIN reserve_rooms ('BARBARA', 654321, 'BL1', 1, 101, 2, '04-02-2005', '10-02-2005'); END;
ERROR at line 1:
ORA-20001: Sorry, there is no such room available.
ORA-06512: at "SCOTT.RESERVE_ROOMS", line 79
ORA-06512: at line 1
-- accepts available room of same sex:
scott@ORA92> EXECUTE reserve_rooms ('BARBARA', 654321, 'BL1', 1, 103, 2, '04-02-2005', '10-02-2005')
PL/SQL procedure successfully completed.
-- assigns random available room of same or no sex:
scott@ORA92> EXECUTE reserve_rooms ('BARBARA', 654321, NULL, NULL, NULL, 2, '11-02-2005', '23-02-2005')
PL/SQL procedure successfully completed.
-- results:
scott@ORA92> -- one and only one row added to em table:
scott@ORA92> SELECT * FROM em WHERE em_id = 'BARBARA'
2 /
EM_ID BL_I FL_ID RM_ID COD_STUD
BARBARA BL1 1 102 654321
scott@ORA92> -- rooms reserved and other people who have reserved same room
scott@ORA92> -- (there are 3 who reserved a double room, but only 2 at a time):
scott@ORA92> SELECT *
2 FROM rmpct
3 WHERE (bl_id, fl_id, rm_id) IN
4 (SELECT bl_id, fl_id, rm_id
5 FROM rmpct
6 where em_id = 'BARBARA')
7 /
EM_ID BL_ FL_ID RM_ID DATE_STAR DATE_END COD_STUD
BARBARA BL1 1 102 11-FEB-05 23-FEB-05 654321
SERAFINO BL1 1 102 12-FEB-04 19-FEB-04 589920
VIDAL BL1 1 102 16-FEB-04 01-MAR-04 602877
SERAFINO BL1 1 103 01-FEB-04 15-FEB-04 589920
TAKEM BL1 1 103 04-FEB-05 10-FEB-05 569673
BARBARA BL1 1 103 04-FEB-05 10-FEB-05 654321
6 rows selected.
scott@ORA92> -- rooms reserved are all correct sex
scott@ORA92> -- (note that room 102 was updated from 0 to 2):
scott@ORA92> SELECT *
2 FROM rm
3 WHERE (bl_id, fl_id, rm_id) IN
4 (SELECT bl_id, fl_id, rm_id
5 FROM rmpct
6 where em_id = 'BARBARA')
7 /
BL_ FL_ID RM_ID SEX R RM_CAT
BL1 1 102 2 D ROOM
BL1 1 103 2 T ROOM
scott@ORA92> -
Java Stored Procedure via Function Give 0RA 600 from SQL Workshop and App
Hi,
Anyone experienced stored procedures or functions failing when called from APEX app or SQL Workshop ( ora 600 ) yet they work fine when called from SQLPlus?
Sqlplus connected as my apex workspace schema owner:
select net_services.test_db_connection_via_ldap(
'APEXPRD1', 'test1', 'test1', null ) as result from dual;
RESULT
The database connection attempt was SUCCESSFUL
From Apex Sql Worshop:
select net_services.test_db_connection_via_ldap(
'APEXPRD1', 'test1', 'test1', null ) as result from dual;
ORA-00600: internal error code, arguments: [16371], [0x434B08150], [0], [], [], [], [], [], [], [], [], []
NOTE: Same result when run in response to button push on page in application.
Apex Version: 3.2.1.00.10
Oracle Version: 11.1.0.7.0
NOTE: I am using the embedded plsql gateway; was going to try NOT using it to see if it was shared server related (seemed to be from trc files)
Any ideas?
Since the code works from sqlplus, I know that it's good: Here some snippets
-- ========================================================================================
public class NetServices extends Object {
public static String doTestDbConnectionViaLdap
String piDbConnUrl,
String piUserName,
String piUserPassword
String vResult = null;
try
Connection conn = null;
OracleDataSource ods = new OracleDataSource();
ods.setUser( piUserName );
ods.setPassword( piUserPassword );
ods.setURL( piDbConnUrl );
conn = ods.getConnection();
conn.close();
vResult = "The database connection attempt was SUCCESSFUL";
} catch ( SQLException e )
int vErrCode = e.getErrorCode();
String vErrMsg = e.toString();
if ( vErrCode == 1017 ) {
vResult = "The database connection attempt FAILED! Incorrect Username or Password";
} else if ( vErrCode == 17433 ) { // Null Username or Password
vResult = "The database connection attempt FAILED! You must provide both a Username and a Password";
} else if ( vErrCode == 17002 ) {
vResult = "The database connection attempt FAILED! Net Service Name was Not Found";
} else if ( vErrCode == 17067 ) { // NULL Net Service Name
vResult = "The database connection attempt FAILED! You must provide a Net Service Name";
} else {
vResult = "The database connection attempt FAILED! Error " + vErrCode;
return vResult;
} // method: doTestDbConnectionViaLdap
-- ========================================================================================
function do_test_db_connection_via_ldap
pi_db_conn_url IN VARCHAR2,
pi_user_name IN VARCHAR2,
pi_user_password IN VARCHAR2
return VARCHAR2
is -- PRIVATE to the net_services package
language java -- NOTE: See cr_java_class_NetServices.sql for actual java implementation
name 'NetServices.doTestDbConnectionViaLdap
( java.lang.String, java.lang.String, java.lang.String ) return java.lang.String ';
-- ========================================================================================
function test_db_connection_via_ldap
pi_net_service_name IN VARCHAR2,
pi_user_name IN VARCHAR2,
pi_user_password IN VARCHAR2,
pi_search_base IN VARCHAR2
return VARCHAR2
is -- PUBLIC procedure
v_url VARCHAR2(256);
begin
g_err_source := 'NET_SERVICES.test_db_connection_via_ldap';
g_err_action := 'build_jdbc_conn_url_using_oid';
/* NOTE: We don't want to assert the parameters because we don't want to raise
an exception;
-- Get the jdbc connection url that uses oid info
v_url := build_jdbc_conn_url_using_oid( pi_net_service_name, pi_search_base );
return( do_test_db_connection_via_ldap( v_url, pi_user_name, pi_user_password ) );
end test_db_connection_via_ldap;
-- ========================================================================================
Thanks in advance for your consideration.
TroyTroy:
You could be right in your guess that the error is related to MTS. Search Metalink for '16371'. Why not switch your APEX app to use OHS and test whether the error persists. ?
varad -
Hello,
I want to create stored procedure which will give output rows from "values that are passed as one parameter (comma seperated) to store procedure".
Suppose ,
Parameter value : person 1,person2,person3
table structure :
Project Name | officers 1 | officers 2
here, officers 1 or officers 2 may contain names of multiple people.
expected OUTPUT : distinct list(rows) of projects where person 1 or person 2 or person 3 is either officer1 or officer 2.
please explain or provide solution in detail
- ThanksHi Visakh,
Thanks for reply.
But the solution you provided giving me right output only if officer 1 or officer 2 contains single value , not with comma seperated value.
Your solution is working fine for following scenario :
Project
Officers 1
Officers 2
p1
of11
off21
p2
of12
off22
with parameter : of11,off22 : it will give expected output
And its not working in case of :
Project
Officers 1
Officers 2
p1
of11,of12
off21,off23
p2
of12,of13
off22,off24
with parameter : of11,off22 : it will not give any row in output
I need patten matching not exact match :)
ok
if thats the case use this modified logic
CREATE PROC GetProjectDetails
@PersonList varchar(5000)
AS
SELECT p.*
FROM ProjectTable p
INNER JOIN dbo.ParseValues(@PersonList,',')f
ON ',' + p.[officers 1] + ',' LIKE '%,' + f.val + ',%'
OR ',' + p.[officers 2] + ',' LIKE '%,' + f.val + ',%'
GO
Keep in mind that what you've done is a wrong design approach
You should not be storing multiples values like this as comma separated list in a single column. Learn about normalization . This is in violation of 1st Normal Form
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
SOAP TO JDBC scenario: calling stored procedure which will return the value
Hi
I have Soap To Jdbc scenario in which I am going to call the Stored Procedure at target side which will be executed and it is going to return the result set .
Result contains following values.
return code as ( 0 Or 1) and also specific exception message if its return code as 1.
Could you suggest me the way by which I can handled this return code and send it back to the Sap PI system then the same thing is directed the to SMTP server for sending mail to consern person.
Regards
KumarThe OUT parameters of stored procedure will be returned as response. Where exactly are you facing the proble? Here is a complete walkthourgh
/people/luis.melgar/blog/2008/05/13/synchronous-soap-to-jdbc--end-to-end-walkthrough
In your case, you don't want response at sender. Instead you want to mail it. For this you may use BPM to design your scenario with following steps
Receive (to receive data from sender)
Send Sync (to stored procedure and get response)
Send Async (to mail receiver)
Regards,
Prateek -
Oracle stored Procedure and Packages in CR4E
Hi,
I want to use Stored Procedure in CR4E. I don't know how to use Stored Procedures and packages in Crystal Reports for Eclipse. In the data source explorer I can only see the Tables, Views and Stored Procedures but not packages from my Schema and when I can only drag & drop the Tables and Views into the Field Explorer, I can't drag & Drop the Stored Procedures.
I managed to attached the stored procedure from CR studio. I opened the report in CR4E and I can see the stored procedure and can preview the data. When I try to run the report and override the datasource, it throws oracle error saying "ORA-01008: Not all variables bound". When I tried to use the option
DBOptions._doNotVerifyDB
while replacing connection I get the this error
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
at java.lang.Boolean.compareTo(Boolean.java:26)
at com.crystaldecisions.sdk.occa.report.lib.ClonableMap.hasContent(ClonableMap.java:112)
at com.crystaldecisions.client.helper.CloneUtil.hasContent(CloneUtil.java:135)
at com.crystaldecisions.sdk.occa.report.data.ConnectionInfo.hasContent(SourceFile:151)
at com.crystaldecisions.client.helper.CloneUtil.hasContent(CloneUtil.java:135)
at com.crystaldecisions.sdk.occa.report.data.Table.hasContent(SourceFile:286)
at com.crystaldecisions.sdk.occa.report.data.Procedure.hasContent(SourceFile:212)
at com.crystaldecisions.sdk.occa.report.lib.ArrayListMerger.haveMatchingContent(ArrayListMerger.java:232)
at com.crystaldecisions.sdk.occa.report.lib.ArrayListMerger.mergePass(ArrayListMerger.java:138)
at com.crystaldecisions.sdk.occa.report.lib.ArrayListMerger.merge(ArrayListMerger.java:86)
at com.crystaldecisions.sdk.occa.report.lib.ControllableList.copyTo(ControllableList.java:68)
at com.crystaldecisions.sdk.occa.report.data.Database.copyTo(SourceFile:105)
at com.crystaldecisions.sdk.occa.report.lib.ControllableHelper.copyToPreservingReferences(ControllableHelper.java:153)
at com.crystaldecisions.sdk.occa.report.application.ReportClientDocument.a(SourceFile:2556)
at com.crystaldecisions.sdk.occa.report.application.b9.onDataSourceChanging(SourceFile:315)
at com.crystaldecisions.sdk.occa.report.application.DatabaseController.a(SourceFile:971)
at com.crystaldecisions.sdk.occa.report.application.DatabaseController.a(SourceFile:4078)
at com.crystaldecisions.sdk.occa.report.application.bv.new(SourceFile:121)
at com.crystaldecisions.sdk.occa.report.application.bv.int(SourceFile:91)
at com.crystaldecisions.proxy.remoteagent.UndoUnitBase.performDo(SourceFile:151)
at com.crystaldecisions.proxy.remoteagent.UndoUnitBase.a(SourceFile:106)
at com.crystaldecisions.sdk.occa.report.application.DatabaseController.a(SourceFile:2159)
at com.crystaldecisions.sdk.occa.report.application.DatabaseController.mapFields(SourceFile:4061)
at com.crystaldecisions.sdk.occa.report.application.DatabaseController.a(SourceFile:3914)
at com.crystaldecisions.sdk.occa.report.application.DatabaseController.replaceConnection(SourceFile:3880)
at
Please advice if Stored procedures and packages are supported in CR4E ?Hi, Jack76,
According to the [CR4E Release Notes|http://help.sap.com/businessobject/product_guides/cr4E/en/cr4e_relnotes_en.pdf] (available from the [CR4E Download page|http://www.businessobjects.com/campaigns/forms/downloads/crystal/eclipse/datasave.asp]), stored procedures are supported, as long as they don't use parameters that need null values.
I don't see any references to packages.
Bryan -
Calling of stored procedure in package
Hi,
I have one stored procedure A. And one package of name P1.
I have execute previlage of package but not having any previlge of stored procedure.
and In package P1 stored procedure A is called. then this packege is work or it will genrate an Error?Oracle users - userA, userB
Stored procedure - procedure1
Package - package1
Who is owner of procedure1 and package1?
Which privileges of userA/userB on procedure1 and package1? -
Including column from fact table reduces number of rows returned
Hello
I am facing this issue where in a report I select 5 columns from a fact table. Out of these five columns one of the column is "Amount" for which the aggregation rule is defined as Sum in RPD.
When I include these five column and filter results based on some criterion , I get all the rows (three rows) that satisfy the criterion. No I add a sixth column to my report and suddenly I only see one row returned by my report. Addition of this sixth column does not affect the criterion as the criterion is not based on this column. But this sixth column is a calculated column.
I tried different things but because the report was just getting columns from one table (fact) and suddenly inclusion of one column leads to reduction in number of rows , I was unable to find any reason why would that happen.
So I thought that some one in community may know that in what scenario this happens.
ThanksAre there any repeated values? I'm wondering if what you're seeing is actually suppression of repetition in the results. Edit the analysis, go to the criteria tab, click column properties, go to the Column Format tab, and change the setting for value suppression from 'Suppress" to "Repeat". Repeat for each of your 6 columns and check the outcome.
Otherwise, I would try testing with other calculations and also bring in some columns from dimension tables to see how this affects the result. You should be able to come up with a case-by-case scenario to work out exactly what causes the rows to be suppressed which will get us one step to closer to working out why the rows get suppressed.
Thanks,
George -
Administering Stored Procedures and Packages
I've read about WRAP utility but I don't know exactly what's it about. Here you are what ýI've read:ý
The code used to create the procedure ,package ,or function is available in the dictionary ýviews DBA_Source ,All_Source,and user_source except when you create them with the ýWRAP utility .the WRAP utility generates encrypted code, which only the Oracle server ýcan interpret .ý
does any one have any idea .
Thanks in advanceGenerally, one uses the WRAP utility when
- You are delivering code to a third party
- You want to ensure that the third party isn't able to decompile your code.
If you built a CRM application with stored procedures and packages and you started selling that commercially, for example, you would use the WRAP utility to ensure that competitors couldn't reverse engineer your code and see how you did things.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Update data provider queryspecification wiith columns from multiple tables
Hi
I have scenario like I need updated a queryspecificaiton with columns from multiple tables
1. Ex:
<bOQuery name="Query">
<resultObjects identifier="DS0.DO1" name="A$Application_ID"/>
<resultObjects identifier="DS0.DO2" name="A$Column_Name"/>
A$Application_ID is from Table A and A$Column_Name from table B
The query is not adding to dataprovier when I am trying to updated from REST API.
Please help me.
Thanks
KalyanHave a look at the Business Intelligence platform RESTful Web Service Developer Guide, section 3.4.7 (p. 197) - Report structure: getting and updating the structure (specifications) of a report, may be a good place to start(?). Also see KBA 1952419 - How to update the properties of a web intelligence report using RESTful web service SDK .
- Ludek
Senior Support Engineer AGS Product Support, Global Support Center Canada
Follow us on Twitter -
Merge statement - update multiple columns from a single sub-select
Is it possible to write in 10gR2, a MERGE statement, with UPDATE for multiple columns from a single sub_select?
like this:
MERGE INTO tableA
using ( select * from temp) tmp
on( tableA. col1 = tmp.col1)
when matched then
update set ( tableA.col5,
tableA.col6,
tableA.col7) = ( select sum(col2), sum(col3), sum(col5)
from tableX
where tableX.col1 = tableA.col1...)Hi,
The USING clause is not a sub-query, so it can't reference columns from tables that are not in it.
Include tableA in the USING clause if you really need to refer to it there. (It's not obvious that you do.)
As always, it helps if you post:
(1) The version of Oracle (and any other relevant software) you're using
(2) A little sample data (just enough to show what the problem is) from all the relevant tables
(3) The results you want from that data (In the case of a DML statement, such as MERGE, this will be the state of the tables when everything is finished.)
(4) Your best attempt so far (formatted)
(5) The full error message (if any), including line number
Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
If you can present your problem using commonly available tables (for example, tables in scott schema, or views in the data dictionary), then you can omit (2).
Formatted tabular output is okay for (3).
Maybe you are looking for
-
Open Net/Gross Amount Balance - A/R Invoice
Hello experts, First time caller, long time listener here. Simplified Scenario: We have a Sales Order for $1500 on which the Customer paid a 100% down payment of $1500. We processed this payment (made via Check) using Payment Means directly on the Sa
-
Looking for an app that will allow my iphone3 to recieve VHF radio
looking for an app that will allow my iphone3 to recieve VHF radio thank you Fabergebrut
-
Uninstall Photoshop CS5.1 not working - Error 6
Hi. As my Photoshop is giving me an an ERROR 6, I tried the Uninstall icon within the folder ADOBE PS CS5.1 and it also gives an ERROR 6. I can't really follow the online solutions that i have found. I am on an imac 2012 and have just upgraded to Yos
-
UIView Animation Problem with different Controllers
Hello! I have a problem regarding the UIView animation and therefore, I have three questions: 1. is it possible to flip from view old to view new whereby each of the views have their own controller? 2. Can I only flip views sharing the same controlle
-
Bridge CC does not have Nikon .NEF file association to set
When I open preferences and go to File Association settings, the extention for Nikon Raw .NEF is not there. It's a pain having to right click the thumbnail everytime I want to open it Photoshop CC. I do have Photoshop CS6 and it defaults to that in