Temporary table with in a stored procedure
Hi:
I am trying to create a SP with a temporary table, and getting a syntex error. Here is my code. Can someone help me on this ?
Thank you,
Dima
create or replace procedure ACCEPT."HIROC_IBC_CLAIMS"(policy_no cm_pm_interface.policy_no%type
,EXPOSURE_UNIT coverage.EXPOSURE_UNIT%type
as
begin
CREATE GLOBAL TEMPORARY TABLE HIROC_IBC_NUMBER_OF_BEDS
POLICY_NUMBER VARCHAR2(100),
NUMBER_OF_BEDS VARCHAR2(100)
insert into HIROC_IBC_NUMBER_OF_BEDS(policy_no
,EXPOSURE_UNIT
select POLICY_NO, SUM(EXPOSURE_UNIT)
From coverage C, cm_pm_interface CIN
WHERE C.COVERAGE_PK = CIN.COVERAGE_PK (+)
AND CIN.COVG_TYPE = 'COVGCLASS'
AND CIN.COVERAGE_CODE IN ('ACUTE')
GROUP BY POLICY_NO
end HIROC_IBC_CLAIMS;
/
At the end I want to get a out put similar to following SELECT script. But there are many tables involved to get the data based on the maximum data value, then some other case statements in the logic etc. I am doing in smaller steps in the query rather than creating a big query. I find it is very easy to follow and debug.
(Ex: UPDATE MONTH_CLAIMS A SET NUMBER_OF_BEDS = (NUMBER_OF_BEDS - 1)
WHERE TO_DATE(POLICY_EFFECTIVE_DATE, 'DD-MM-YYYY') < TO_DATE('01-01-2010', 'DD-MM-YYYY');
--Final data set
SELECT
'110' || As Company_Number || 1-3 '110'
TO_CHAR(ADD_MONTHS(LAST_DAY(SYSDATE),-1),'YYMM') ||-- As Entry_Date,--4-7 YYMM
'4' || As Statistical_Plan ||--8
TRANSACTION_TYPE_CODE || As Transaction_Type_Code,9
'' || As Branch_Code, this is a blank field 10-12
Policy_Number || As Policy_Number, 13-23
TO_CHAR(policy_Effective_Date, 'YYMM') || As Policy_Effective_Date, YYMM 24-27
'8601' || --As Retroactive_Date,
claimnumber || --As claimnumber,
TO_CHAR(Date_of_Loss, 'YYMMDD') || --As Date_of_Loss,
TO_CHAR(Notice_of_Occurrence_Date, 'YYMM') || --As Notice_of_Occurrence_Date,
'1' || --As Basis_of_Claim_Code,
TO_CHAR(report_date, 'YYMM') || --As Report_Date,
'999' || --As Loss_Control_Event_Code,
'980' || --As Premium_Location_Code,
'8061' || --As Industry_Classification_Code,
'3' || --As Line_Code,
'61' || --As Coverage_Policy_Form_Code,
'6' || --As Policy_Type_Code,
ExposureType || --As ExposureType,
Exposure_Base_Unit || --As Exposure_Base_Unit,
Number_Of_Beds || As Number_Of_Beds, 78-83
Policy_Limit || -- As Policy_Limit,
'100' || --As Precentage_Participation,
Expense_Code || --As Expense_Code,
ABS(TRANS_AMT) || --As Expense_Amount,
'1' || --type code
'0' --Unsigned deductible limit
from MONTH_CLAIMS
Similar Messages
-
Creating a table/view or temporary table from within a stored procedure
Hi Gurus,
Can someone tell me if it is possible to create a table (or view) from within a stored procedure.
PROBLEM:
In fact I need to create a report at back end (without using oracle developer forms or reports). This report requires creating several tables to hold temporary report data. If I create a sql*plus script for this, i works fine, because it can run DDL and other sql or pl/sql statements sequencialy. But this sql*plus script cannot be called from application. So, application needs an stored procedure to do this task and then application call that procedure. But within stored procedure, i am unable to create table (or run any ddl statement). Can somebody help me in this?
Thanks in Advance.Denis,
The problem with Nicholas' suggestion isrelated to the fact that now you have two components
(a table and a stored procedure)
I don't see any problem to have "two
components" here. After all, what about all others
tabes ? This is only one more, but I don't understand
why want manage less objects, that implies more code,
more maintenance, and more difficulties to debug.
Needless to say about performance...
Nicolas.The same reasons apply if you were forced to declare all PL/SQL variables publicly (outside the stored proc.) rather than privately (from inside the stored proc). Naming conflicts for one. If the name that you want to use for the GTT already exists, you need to find a new name. With the SQL Server type local/private declarations, you wouldn't have that problem.
I can see how performance would be the same or better using GTTs. If the number of records involved is low, this is likely negligable. -
Pass temporary table as parameter to a procedure from Java
Hi,
I have a PL/SQL procedure that has as input parameter a temporary table. For calling this procedure from PL/SQL there is no problem: I declare a variable having the type temporary table%ROWTYPE, I fill the table with data and then call the procedure. Now I have to call this procedure form Java and I do not know how can I declare a variable of type temporary table, fill it with data and then pass it to the procedure. I have seen and implemented passing arrays of strings or numbers to stored procedures but I have no clue how can I pass the temporary table. Anyone any clues?
Thank you,
FlorinHi Avi,
the table is defined like this:
CREATE GLOBAL TEMPORARY TABLE ticket_api (
ticket VARCHAR2(16),
party_id NUMBER,
date_from DATE,
date_to DATE )
ON COMMIT PRESERVE ROWS;
there is defined a type like this:
TYPE ticket_tabletype IS
TABLE OF ticket_api%ROWTYPE;
the procedure definition is like this:
PROCEDURE get_ticket_data (
p_tickets IN ticket_tabletype ,
x_action_plan OUT NOCOPY action_plan_tabletype );
the action_plan_tabletype is defined like this:
TYPE action_plan_tabletype IS
TABLE OF action_plan_cursor%ROWTYPE;
When calling the procedure from PL/SQL I use the following code:
DECLARE
inTickets ticket_tabletype := ticket_tabletype ();
outActionPlan action_plan_tabletype;
BEGIN
inTickets.EXTEND;
inTickets(1).ticket := 'ABCDEFG';
inTickets(1).party_id := 123456789;
inTickets(1).date_from := TO_DATE('01-JAN-05', 'DD-MON-YY');
inTickets(1).date_to := SYSDATE;
get_ticket_data(
p_tickets => inTickets,
x_action_plan => outActionPlan);
DBMS_OUTPUT.PUT_LINE('Actions: '||outActionPlan.COUNT);
END;
Thanks for your quick feedback,
Florin -
Find all tables used in a stored procedure
Hi,
I have a requirement where i have to find all the tables used in a stored procedures from different databases.
Ex: i have a stored procedure where i use few tables from MASTER database and some from STAGE database.When i have written a query to find all tables used in the stored procedure, i am getting only those database table where i run the query and procedure
exists.
I have stored procedure SP1 in Master database, but i use the tables from both master and stage.
When i run this, i am getting the tables only from Master database but not from stage. i hope my requirement is clear.
I am trying to find all the tables from all databases used by a stored proc.
;WITH stored_procedures AS (
SELECT
o.name AS proc_name, oo.name AS table_name,
ROW_NUMBER() OVER(partition by o.name,oo.name ORDER BY o.name,oo.name) AS row
FROM sysdepends d
INNER JOIN sysobjects o ON o.id=d.id
INNER JOIN sysobjects oo ON oo.id=d.depid
WHERE o.xtype = 'P')
SELECT proc_name, table_name FROM stored_procedures
WHERE row = 1
ORDER BY proc_name
Please adviceYour question is not entirely clear. You need to run the query on different databases.
You may find this blog post helpful
How to get information about all databases without a loop
Check the last script in that blog post and modify to your particular purpose.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
Query to get list of linked server tables referenced inside a stored procedure
Hi,
SQL Server 2005 sp4
I have a requirement to get list of linked server tables referenced insider a stored procedure
Ex:
Databases DB1 DB2
Tables: T1 T2
Use DB1
Go
Create proc P1
begin
select * from T1
select * from DB2.dbo.T2
end
I am looking for a query which can return a result with output as below. sp_depends is not helping here as it does not work for cross DB objects, any other thoughts.
Tables
T1,
DB2.dbo.T2On SQL 2005, you will have to do it manually.
On SQL 2008 or later, you could have used sys.sql_expression_dependencies.
Erland Sommarskog, SQL Server MVP, [email protected] -
How can I implement the equivilent of a temporary table with "on commit delete rows"?
hi,
I have triggers on several tables. During a transaction, I need to gather information from all of them, and once one of the triggers has all the information, it creates some data. I Can't rely on the order of the triggers.
In Oracle and DB2, I'm using temporary tables with "ON COMMIT DELETE ROWS" to gather the information - They fit perfectly to the situation since I don't want any information to be passed between different transactions.
In SQL Server, there are local temporary tables and global. Local temp tables don't work for me since apparently they get deleted at the end of the trigger. Global tables keep the data between transactions.
I could use global tables and add some field that identifies the transaction, and in each access to these tables join by this field, but didn't find how to get some unique identifier for the transaction. @@SPID is the session, and sys.dm_tran_current_transaction
is not accessible by the user I'm supposed to work with.
Also with global tables, I can't just wipe data when "operation is done" since at the triggers level I cannot identify when the operation was done, transaction was committed and no other triggers are expected to fire.
Any idea which construct I could use to acheive the above - passing information between different triggers in the same transaction, while keeping the data visible to the current transaction?
(I saw similar questions but didn't see an adequate answer, sorry if posting something that was already asked).
Thanks!This is the scenario: If changes (CRUD) happen to both TableA and TableB, then log some info to TableC. Logic looks something like this:
Create Trigger TableA_C After Insert on TableA {
If info in temp tables available from TableB
Write info to TableC
else
Write to temp tables info from TableA
Create Trigger TableB_C After Insert on TableB {
If info in temp tables available from TableA
Write info to TableC
else
Write to temp tables info from TableB
So each trigger needs info from the other table, and once everything is available, info to TableC is written. Info is only from the current transaction.
Order of the triggers is not defined. Also there's no gurantee that both triggers would fire - changes can happen only to TableA / B and in that case I don't want to write anything to TableC.
The part that gets and sets info to temp table is implemented as temp tables with "on commit delete rows" in DB2 / Oracle.
What do you think? As I've mentioned, I could use global temp tables with a field that would identify the transaction, but didn't find something like that in SQL Server. And, the lifespan of local temp tables is too short. -
How to find the columns and tables used in a stored procedure?
Hi,
Can someone suggest how to find the columns and tables used within a stored procedure?
Thanks
VBKFor example:
SQL> create or replace
2 procedure p1
3 is
4 cnt number;
5 begin
6 select count(*) into cnt from emp;
7 end;
8 /
Procedure created.
SQL> select referenced_owner,
2 referenced_name
3 from dba_dependencies
4 where owner = 'SCOTT'
5 and name = 'P1'
6 and referenced_type = 'TABLE'
7 /
REFERENCED_OWNER REFERENCED_NAME
SCOTT EMP
SQL> SY. -
Help with running a stored procedure
Hi, could anybody help me with debugging this stored procedure:
extraction_date in varchar2
as
begin
execute immediate '
declare
/* Output file handler */
fileHandler UTL_FILE.FILE_TYPE;
asset_id VARCHAR2(60) := '''';
cursor c_table is
SELECT "ASSET ID"
FROM REUT_MAIN_BOND
WHERE MATURITY > TO_DATE(' || extraction_date || ', "MM-DD-YYYY");
row c_table%ROWTYPE;
begin
fileHandler := UTL_FILE.FOPEN(''TEMP'', ''northfielddescupdate.in'', ''w'',32000);
for row in c_table
loop
asset_id := row.ASSET;
UTL_FILE.PUTF(fileHandler, ''asset_id'', ''\n'');
end loop;
UTL_FILE.FCLOSE(fileHandler);
end;';
commit;
end;
when I run it - SQL> exec create_in_file('08102004')
it gives me the following errors:
ERROR at line 1:
ORA-06550: line 8, column 11:
PL/SQL: ORA-06553: PLS-103: Encountered the symbol "CALL" when expecting one of
the following:
<an identifier> <a double-quoted delimited-identifier>
ORA-06553: PLS-112: end-of-line in quoted identifier
ORA-06550: line 7, column 2:
PL/SQL: SQL Statement ignored
ORA-06550: line 6, column 8:
PLS-00341: declaration of cursor 'C_TABLE' is incomplete or malformed
ORA-06550: line 10, column 5:
PL/SQL: Item ignored
ORA-06550: line 15, column 14:
PLS-00364: loop index variable 'ROW' use is invalid
ORA-06550: line 15, column 2:
PL/SQL: Statement ignored
ORA-06512: at "PETAR_NORTHFIELD.CREATE_IN_FILE", line 6
ORA-06512: at line 1
Thank you for your helpQ #1 (and possibly the only question) - why are you using NDS for this?
-
Alternative way to create temporary table with better performace?
Hi guys,
Do you happen to a better alternative way for creating a global temporary table with better performance?
I am creating a table and then using it in a big query but is taking a lot of time.
Thanks for any help you can provide.I am not very familiar with explains plans, but I believe it is ok.
The first query I had was repeating part of it in every subquery that is why I decided to create the temporary table. I have also tried using the WITH but it seems to take the same amount of time. I also thought of creating indexed but was told that it would work in this case.
I have another discussion named "SQL Query Having performance issues" in this discussion I have included the query just in case you want to look at it.
Thanks -
Using XI - RFC table and an Oracle stored procedure that returns a cursor.
I need to create an interface using XI between an RFC table and an Oracle stored procedure that returns a cursor. We are on oarcle 9.2 and SP12.
My stored procedure looks something like this:
CREATE OR REPLACE
PROCEDURE testproc_xi2 (p_recordset1 OUT SYS_REFCURSOR,
in_quoteid IN varchar2 )
AS
BEGIN
OPEN p_recordset1 FOR
SELECT q.quote_id,
q.modified_by,
q.quote_status,
q.total_cost
FROM quote q
WHERE q.quote_id = in_quoteid
AND q.total_cost > 0 ;
END testproc_xi2 ;
My RFC has table and one import parameter .
I wanted to know how to create the data type for the ref cursor? and also for the table type in the RFC?
CAN XI handle multi rows coming from a Stored procedure? Are there any other alternative methods if this is not supported?Any pointers to this would be helpful.
I have called a Oracle SP from an RFC before, but that interface had one input parameter going to the stored procedure from the RFC and about 6 o/p parameters coming from the Stored procedure. This works fine.
Thanks for the help.
MalaMala,
i dont think there is anything called an rfc table...RFC stands for remote function call. That in essence would imply you need a rfc to jdbc connection.
yes XI can handle multiple rows cooming from the the stored procedure if you have them mapped appropriately.
Now as to how to create the data type within xi , you need to know what fields are going to be returned and whether they are nested and then just create them as you would for an xml
for ex
<Details>
<FirstName>
<LastName>
</Details>
that in xi would be smthing like
Details type of data occurence
FirstName type of data occurence
LastName type of data occurence.
Hope that helps.
If it does dont forget the points..:-) -
How to Create a Temporary Table with SQL Server
I know you can create a temporary table in SQL Server 2000, but not quite sure how to do it in CFMX 7, i.e., does the SQL go inside a <CFQUERY dbtype="query"> tag?
I'm pulling the main set of records from an Oracle server (1st data source), but it does not contain employee names, only employee IDs. Since I need to show the employee name along with the Emp ID, I'm then pulling a list of "current" employee names from a SQL Server (2nd data source), which is the main database on our CF server.
I've got a QofQ that works fine, except it only matches EmpIDs that exist in both result sets. Employees who are no longer employed, don't match, and don't display. Since I can't do a LEFT OUTER JOIN with a QofQ, what I need to do is get the records from the Oracle server into the SQL Server. Preferably in a temporary table.
I was hoping if I could get those Oracle records written to a temp table on the main SQL Server, in same database as the Employee Name table, I could then write a normal <CFQUERY> that uses a LEFT OUTER JOIN.
I think I could probably write a Stored Procedure that would execute the SQL to create the temporary table, but am trying to avoid having to write the SP, and do it the simplest way.
This query will be a program that can be run hundreds of times per day, with a form that allows users to select date ranges, locations, and other options. That starts the queries, which creates the report. So I just need the temp table to exist only until all the SQL has run, and the <CFOUTPUT> has generated a report.
If the premise is right, I just need some help with the syntax for creating a SQL Server temp table, when you want to write records to it from an external data source. I'm trying the following, but getting an error:
<CFQUERY name="ITE_Temp" datasource="SkynetSQL">
CREATE TABLE #MyTemp
( INSERT INTO #MyTemp
ITE2.TrueFile char (7) NOT NULL,
ITE2.CountOfEmployee int NULL,
ITE2.DTL_SUBTOT decimal NULL,
ITE2.EMPTYPE char (3) NULL,
ITE2.ARPT_CD char (3) NULL
</CFQUERY>
So I actually created a permanent table on the SQL Server, and wrote the below SQL, which does work, and does write the records to table. I can then write another CFQUERY with a LEFT OUTER JOIN, and get all the records, including those that don't have matching employee name:
<CFQUERY datasource="SkynetSQL">
<CFLOOP index="i" from="1" to = "#ITE2.RecordCount#">
INSERT INTO ITE_Temp
(FullFile,
EmployeeCount,
DTL_Amount,
EmployeeType,
station)
VALUES ('#ITE2.TrueFile[i]#',
#ITE2.CountOfEmployee[i]#,
#ITE2.DTL_SUBTOT[i]#,
'#ITE2.EMPTYPE[i]#',
'#ITE2.ARPT_CD[i]#')
</CFLOOP>
</CFQUERY>
But, I hate to have to create a table and physically write to it. For one, it seems slower, and doing it in temp would be in memory, and probably much faster, correct? Is there some way to code the above, so that it does something similar, but in a TEMPORARY TABLE? If I can figure out how to do this, I can pull data from multiple data sources and servers, and using SQL Server temp tables, work with the data as if it was all on the same SQL Server, and do some cool reports.
Everything I've done for the past few years, has all been from data from a single source, whether SQL Server, or another server. Now I need to start writing reports where data can come from 3 or 4 different servers, and be able to do joins (inner and outer). Thanks for any advice/help. Much appreciated.
GaryWhile waiting to hear back, I was able to write the query results from an outside Oracle server, to a table on the local SQL Server, and do the LEFT OUTER JOIN required for the final query and report to work. That was with this syntax:
<CFQUERY name="AddTableRecords" datasource="MyTable">
TRUNCATE TABLE ITE_Temp
<CFOUTPUT query="ITE2">
INSERT INTO ITE_Temp
(FullFile,EmployeeCount,DTL_Amount,EmployeeType,station)
VALUES
('#TrueFile#', #CountOfEmployee#, #DTL_SUBTOT#, '#EMPTYPE#', '#ARPT_CD#')
</CFOUTPUT>
</CFQUERY>
However, I was not able to write to a temporary table AND read the results. I got the syntax to run to write the above results to a temporary table. But when I tried to read and output the results from the temp table, I got an error. Also, it wouldn't take the single "#" (local) only the global "##" table var, using this syntax. Note that if I didn't have the DROP TABLE in the beginning, the 2nd time you run this query, you get an error telling you the table already exists.
<CFQUERY name="ITE_Temp2" datasource="MyTable">
DROP TABLE ##MyTemp2
CREATE TABLE ##MyTemp2
FullFile char (7) NOT NULL,
EmployeeCount int NULL,
DTL_Amount decimal NULL,
EmployeeType char (3) NULL,
station char (3) NULL
<CFOUTPUT query="ITE2">
INSERT INTO ##MyTemp2 VALUES
'#ITE2.TrueFile#',
#ITE2.CountOfEmployee#,
#ITE2.DTL_SUBTOT#,
'#ITE2.EMPTYPE#',
'#ITE2.ARPT_CD#'
</CFOUTPUT>
</CFQUERY>
So even though the above works, I could use some help in reading/writing the output. I've tried several things similar to below, but they don't work. It't telling me ITE_Temp2 does not exist. It's not easy to find good examples of creating temporary tables in SQL Server.
<CFQUERY name="QueryTest2" datasource="SkynetSQL">
SELECT *
FROM ITE_Temp2
</CFQUERY>
<CFOUTPUT query="ITE_Temp2">
Output from Temp Table<br>
<p>FullFile: #FullFile#, EmployeeCount: #EmployeeCount#</p>
</CFOUTPUT>
Thanks for any help/advice.
Gary. -
Trouble with calling a stored procedure with VARCHAR parameter from trigger
Hi everybody,
today I ran across a problem with stored procedures and triggers that try to call them. Background info: I want to log changes in certain tables to another table in a trigger, so I can replicate the changes to another (non-Oracle) database in an asynchronous way. As an example I have the first data table "bak_s3_berufliste" and the table to store the changes in is "bak_s3_change_request".
DROP TABLE BAK_S3_BERUFLISTE;
CREATE TABLE bak_s3_berufliste (
id_bl NUMBER(27,0) NOT NULL,
berufsbez VARCHAR2(255),
CONSTRAINT PK_BAK_S3_BERUFLISTE PRIMARY KEY (id_bl) ENABLE);
DROP TABLE bak_s3_change_request;
CREATE TABLE bak_s3_change_request (
ID_CR NUMBER(27,0) NOT NULL,
TABELLE_NAME VARCHAR2(50) NOT NULL,
TABELLE_ID_ALT NUMBER(27,0),
TABELLE_ID_NEU NUMBER(27,0),
CONSTRAINT PK_BAK_S3_CHANGE_REQUEST PRIMARY KEY (ID_CR) ENABLE);
DROP SEQUENCE seq_bak_s3_change_request;
CREATE SEQUENCE seq_bak_s3_change_request;
For testing purposes I created the following stored procedure and trigger:
CREATE OR REPLACE PROCEDURE schreibe_cr (t_id_alt IN NUMBER, t_id_neu IN NUMBER) IS
BEGIN
INSERT INTO bak_s3_change_request(ID_CR, TABELLE_NAME, TABELLE_ID_ALT, TABELLE_ID_NEU)
VALUES (seq_bak_s3_change_request.NEXTVAL, t_name, t_id_alt, t_id_neu);
END;
CREATE OR REPLACE TRIGGER trg_bak_s3_berufliste
BEFORE INSERT OR UPDATE OR DELETE ON bak_s3_berufliste
FOR EACH ROW
call schreibe_cr(:old.id_bl,:new.id_bl)
*... and everything worked perfectly - except from the fact that I need to know which table had changed of course. So I added another parameter to the stored procedure:*
CREATE OR REPLACE PROCEDURE schreibe_cr (t_name IN VARCHAR2, t_id_alt IN NUMBER, t_id_neu IN NUMBER) IS
BEGIN
INSERT INTO bak_s3_change_request(ID_CR, TABELLE_NAME, TABELLE_ID_ALT, TABELLE_ID_NEU)
VALUES (seq_bak_s3_change_request.NEXTVAL, t_name, t_id_alt, t_id_neu);
END;
and tested it:
CALL schreibe_cr('Test',1,2);
*... successfully. So I also added the parameter to the trigger:*
CREATE OR REPLACE TRIGGER trg_bak_s3_berufliste
BEFORE INSERT OR UPDATE OR DELETE ON bak_s3_berufliste
FOR EACH ROW
call schreibe_cr('Tabellenname',1,2)
and what i get is:
Error starting at line 31 in command:
CREATE OR REPLACE TRIGGER trg_bak_s3_berufliste
BEFORE INSERT OR UPDATE OR DELETE ON bak_s3_berufliste
FOR EACH ROW
call schreibe_cr('Tabellenname',1,2)
When I try to insert something into that table I get the following error:
insert into bak_s3_berufliste (id_bl, berufsbez) values (seq_bak_s3_change_request.NEXTVAL, 'tueduelue');
Error report:
ORA-00911: Ungültiges Zeichen
00911. 00000 - "invalid character"
Cause: identifiers may not start with any ASCII character other than
letters and numbers. $#_ are also allowed after the first
character. Identifiers enclosed by doublequotes may contain
any character other than a doublequote. Alternative quotes
(q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
Reference Manual.
Action:
I tried everything that came to my mind, like using double-quotes (") instead of quotes (') in the trigger code or escaping the quotes (\'), but nothing worked. Can anybody help my and tell me what's wrong? After googling for hours I'm outta ideas :-(
Any ideas appreciated!
Thanks in advance,
JensWhy?
Are you looking for this?
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:01.61
satyaki>
satyaki>
satyaki>create table aud_dup_emp
2 as
3 select empno, ename
4 from dup_emp
5 where 1=2;
Table created.
Elapsed: 00:00:01.86
satyaki>
satyaki>select * from dup_emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
9999 SATYAKI SLS 7698 02-NOV-08 55000 3455 10
7777 SOURAV SLS 14-SEP-08 45000 3400 10
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 4450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 7000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
9999 SATYAKI SLS 7698 02-NOV-08 55000 3455 10
7777 SOURAV SLS 14-SEP-08 45000 3400 10
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
18 rows selected.
Elapsed: 00:00:00.10
satyaki>
satyaki>
satyaki>create or replace procedure ins_aud_dup(eno in number, enm in varchar2)
2 is
3 begin
4 insert into aud_dup_emp(empno,ename) values(eno,enm);
5 end;
6 /
Procedure created.
Elapsed: 00:00:03.36
satyaki>
satyaki>
satyaki>
satyaki>ed
Wrote file afiedt.buf
1 create or replace trigger trg_aud_dup
2 before insert on dup_emp
3 for each row
4 begin
5 ins_aud_dup(:old.empno,:new.ename);
6* end;
satyaki>/
Trigger created.
Elapsed: 00:00:01.47
satyaki>
satyaki>
satyaki>select * from aud_dup_emp;
no rows selected
Elapsed: 00:00:00.10
satyaki>
satyaki>
satyaki>insert into dup_emp(empno,ename,deptno) values(8855,'BILLY',40);
1 row created.
Elapsed: 00:00:00.19
satyaki>
satyaki>commit;
Commit complete.
Elapsed: 00:00:00.03
satyaki>
satyaki>
satyaki>select * from dup_emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
9999 SATYAKI SLS 7698 02-NOV-08 55000 3455 10
7777 SOURAV SLS 14-SEP-08 45000 3400 10
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 4450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 7000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
9999 SATYAKI SLS 7698 02-NOV-08 55000 3455 10
7777 SOURAV SLS 14-SEP-08 45000 3400 10
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
8855 BILLY 40
19 rows selected.
Elapsed: 00:00:00.20
satyaki>
satyaki>select * from aud_dup_emp;
EMPNO ENAME
BILLY
Elapsed: 00:00:00.09
satyaki>Regards.
Satyaki De. -
Passing Tables back from Java Stored Procedures
Thomas Kyte has written (in reference to
trying to pass an array back from a stored
function call):
You can do one of two things (and both require the use of
objects). You cannot use PLSQL table types as JDBC cannot bind to
this type -- we must use OBJECT Types.
[snip]
Another way is to use a result set and "select * from
plsql_function". It could look like this:
ops$tkyte@8i> create or replace type myTableType as table of
varchar2 (64);
2 /
Type created.
ops$tkyte@8i>
ops$tkyte@8i>
ops$tkyte@8i> create or replace
2 function demo_proc2( p_rows_to_make_up in number )
3 return myTableType
4 as
5 l_data myTableType := myTableType();
6 begin
7 for i in 1 .. p_rows_to_make_up
8 loop
9 l_data.extend;
10 l_data(i) := 'Made up row ' | | i;
11 end loop;
12 return l_data;
13 end;
14 /
Function created.
ops$tkyte@8i>
ops$tkyte@8i> select *
2 from the ( select cast( demo_proc2(5) as mytableType )
3 from dual );
COLUMN_VALUE
Made up row 1
Made up row 2
Made up row 3
Made up row 4 [Image]
Made up row 5
So, your JDBC program would just run the query to get the data.
If the function "demo_proc2" cannot be called from SQL for
whatever reason (eg: it calls an impure function in another piece
of code or it itself tries to modify the database via an insert
or whatever), you'll just make a package like:
ops$tkyte@8i> create or replace package my_pkg
2 as
3
4 procedure Make_up_the_data( p_rows_to_make_up in
number ); 5 function Get_The_Data return myTableType;
6 end;
7 /
Package created.
ops$tkyte@8i>
ops$tkyte@8i> create or replace package body my_pkg
2 as
3
4 g_data myTableType;
5
6 procedure Make_up_the_data( p_rows_to_make_up in number )
7 as
8 begin
9 g_data := myTableType();
10 for i in 1 .. p_rows_to_make_up
11 loop
12 g_data.extend;
13 g_data(i) := 'Made up row ' | | i;
14 end loop;
15 end;
16
17
18 function get_the_data return myTableType
19 is
20 begin
21 return g_data;
22 end;
23
24 end;
25 /
Package body created.
ops$tkyte@8i>
ops$tkyte@8i> exec my_pkg.make_up_the_data( 3 );
PL/SQL procedure successfully completed.
ops$tkyte@8i>
ops$tkyte@8i> select *
2 from the ( select cast( my_pkg.get_the_data as mytableType
) 3 from dual );
COLUMN_VALUE
Made up row 1
Made up row 2
Made up row 3
And you'll call the procedure followed by a query to get the
data...
I have tried this, and it works perfectly.
My question, is what does the wrapper look
like if the stored function is written
in java instead of PL/SQL? My experiments
with putting the function in java have been
dismal failures. (I supposed I should also
ask how the java stored procedure might
look also, as I suppose that could be where
I have been having a problem)
nullThanks for the response Avi, but I think I need to clarify my question. The articles referenced in your link tended to describe using PL/SQL ref cursors in Java stored procedures and also the desire to pass ref cursors from Java to PL/SQL programs. Unfortunately, what I am looking to do is the opposite.
We currently have several Java stored procedures that are accessed via select statements that have become a performance bottleneck in our system. Originally the business requirements were such that only a small number of rows were ever selected and passed into the Java stored procedures. Well, business requirements have changed and now thousands and potentially tens of thousands of rows can be passed in. We benchmarked Java stored procedures vs. PL/SQL stored procedures being accessed via a select statement and PL/SQL had far better performance and scaleable. So, our thought is by decouple the persistence logic into PL/SQL and keeping the business logic in Java stored procedures we can increase performance without having to do a major rewrite of the existing code. This leads to the current problem.
What we currently do is select into a Java stored procedure which has many database access calls. What we would like to do is select against a PL/SQL stored procedure to aggregate the data and then pass that data via a ref cursor (or whatever structure is acceptable) to a Java stored procedure. This would save us a significant amount of work since the current Java stored procedures would simple need to be changed to not make database calls since the data would be handed to them.
Is there a way to send a ref cursor from PL/SQL as an input parameter to a Java stored procedure? My call would potentially look like this:
SELECT java_stored_proc(pl/sql_stored_proc(col_id))
FROM table_of_5000_rows;
Sorry for the lengthy post. -
Pivot table that uses a Stored Procedure parameter and filters the data based on it
Hello, my 1st post. I am lost. Please help.
I am trying to create an Excel Pivot Table that has data that comes from an ODC but needs to be filtered based on a parameter from a Stored Procedure. This involves Project Server. I need to filter the results based on the RBS value of the logged
in user. My Stored Procedure can return the RBS as long as the ResourceNTAccount value is given. I cant figure out how to tie this all together.Hi,
Based on your description,I think this issue should be more related to Programming/coding, you can sumbit a new case to MSDN forum.
As I'm not quite formular with Project Server, all I can tell you is that it is easy to running a Stored Procedure within Excel, however, if you have to pass dynamic parameters you’ll have to turn to VBA.For detailed information,please refer
to:
http://blogs.office.com/2010/06/07/running-a-sql-stored-procedure-from-excel-no-vba/
Wind Zhang
TechNet Community Support -
Using temporary tables with a ref. cursor
I want to use a temporary table to populate certain data and then return a ref cursor fetching data from the temporary table.
1. Will this approach work ?
2. Do I need to drop the temporary table ? Can I drop the table as a last statement in the stored proc (remember a ref cursor based on this table is to be returned as a out parameter).
Please help.1. Will this approach work ?Sort of, just like it is possible to dig a trench with a spoon. It can be done, but why can't you just write a select that returns the data without storing intermediate versions of your processing somewhere.
2. Do I need to drop the temporary table ?No. and you shouldn't.
Can I drop the table as a last statement in the stored proc
(remember a ref cursor based on this table is to be returned as a out parameter).No.
If you really need to use a temporary table, it should be created one time when the application is installed, and should never be created in code.
Maybe you are looking for
-
So I went to my local best buy today and was all set to trade in my 360 for the "trade-in and trade up" promotion.. Then the person at customer service tells me that I was missing a controller to get the $150 credit.. I've read the promo terms and u
-
IMac speaker buzz... ?
Hi all, I apologize if this is a common issue; I've done some searching but haven't found anyone with my exact problem. I've got a fairly old (I believe at least ten years) pair of Bose Roommate II speakers and a brand new (arrived yesterday) aluminu
-
How can I block a particular program and not the whole channel?
I want to block a particular program. When I am trying to that, it blocks whole channel. How can I do that? Second Q is: can I have two parental control pins to block programs?
-
Maxify MB5320 How do I make a duplex document flippable ( reverse side upside down)
I have a 40 page docuiment, in landscape mode, that I duplex. The doc. will be placed in a binder and when the reader reads it he/she will flip the pages top to bottom. I wish to print the reverse side of each page upside-down so the reader will not
-
How to use Enhancement spot in program
Hi gurus, now i am working ecc 6.0, so how to use Enhancement spot in program, can anybody explain step by step. Rewarded with points. Thanks Naveen