Can I create a Stored Procedure That access data from tables of another servers?
I'm developing a procedure and within it I'm trying to access another server and make a select into a table that belongs to this another server. When I compile this procedure I have this error message: " PLS-00904: insufficient privilege to access object BC.CADPAP", where BC.CADPAP is the problematic table.
How can I use more than one connection into an Oracle Stored Procedure?
How I can access tables of a server from a Stored Procedure since the moment I'm already connected with another server?
Can I create a Stored Procedure That access data from tables of another servers?
You need to have a Database Link between two servers. Then you could do execute that statement without any problem. Try to create a database link with the help of
CREATE DATABASE LINK command. Refer Document for further details
Similar Messages
-
How to create a stored procedure that accepts an array of args from Java?
I am to be creating a stored procedure that accepts an array of arguments from Java. How to create this? thanks
SamNot a PL/SQL question really, but a Java one. The client call is done via ThinJDBC/OCI to PL/SQL, This call must be valid and match the parameters and data types of the PL/SQL procedure.
E.g. Let's say I define the following array (collection) structure in Oracle:
SQL> create or replace type TStrings as table of varchar2(4000);
Then I use this as dynamic array input for a PL/SQL proc:
create or replace procedure foo( string_array IN TStrings )...
The client making the call to PL/SQL needs to ensure that it passes a proper TStrings array structure.. The Oracle Call Interface (OCI) supports this on the client side - allowing the client to construct an OCI variable that can be passed as a TStrings data type to SQL. Unsure just what JDBC supports in this regard.
An alternative method, and a bit of a dirty hack, is to construct the array dynamically - but as this does not use bind variables, it is not a great idea.
E.g. the client does the call as follows: begin
foo( TStrings( 'Tom', 'Dick', 'Harry' ) );
end;Where the TStrings constructor is created by the client by stringing together variables to create a dynamic SQL statement. A bind var call would look like this instead (and scale much better on the Oracle server side):begin
foo( :MYSTRINGS );
end;I'm pretty sure these concepts are covered in the Oracle Java Developer manuals... -
Hi guys, I'm trying to create a Stored procedure that will automatically add all 3 After triggers when executed on any given database, can someone please explain and give an example on how do I go about doing this ? I'd also like it to raise any errors
that may come across, thanks in advance.Lets start with the question why do you need the triggers at all. Since SQL Server 2005 we can use an OUTPUT clause.
This code can be re-written in SQL Server 2005 using the OUTPUT clause like below:
create table itest ( i int identity not null primary key, j int not null unique )
create table #new ( i int not null, j int not null)
insert into itest (j)
output inserted.i, inserted.j into #new
select o.object_id from sys.objects as o
select * from #new
drop table #new, itest;
go
Now from this example, you can see the integration of OUTPUT clause with existing DML syntax.
Another common scenario is auditing of data in a table using triggers. In this case, the trigger uses information from the inserted and updated tables to add rows into the audit tables. The example below shows code that uses OUTPUT clause in UPDATE and DELETE
statements to insert rows into an audit table.
create table t ( i int not null );
create table t_audit ( old_i int not null, new_i int null );
insert into t (i) values( 1 );
insert into t (i) values( 2 );
update t
set i = i + 1
output deleted.i, inserted.i into t_audit
where i = 1;
delete from t
output deleted.i, NULL into t_audit
where i = 2;
select * from t;
select * from t_audit;
drop table t, t_audit;
go
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Pointbase : How can I create a stored procedure with Pointbase database?
Hello,
Excuse me for my english, I'm not anglophone. I try to create a stored procedure.
This is my file SampleExternalMethods.java :
import java.sql.*; //import com.pointbase.jdbc.jdbcInOutDoubleWrapper; public class SampleExternalMethods { // A connection object to allow database callback static Connection conn = null; static Statement l_stmt; static Statement m_stmt; static CallableStatement m_callStmt = null; static ResultSet l_rs = null; public static void main(String[] args) { try { String url = "jdbc:pointbase:server://localhost/pointbaseDB"; String username = "PBPUBLIC"; String password = "PBPUBLIC"; conn = DriverManager.getConnection(url, username, password); doCreateProcedure(); doInvokeProcedure(); } catch (SQLException e) { e.printStackTrace(); } finally { if (m_stmt != null) { try { m_stmt.close(); } catch (Exception e) { e.printStackTrace(); } } if (m_callStmt != null) { try { m_callStmt.close(); } catch (Exception e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (Exception e) { e.printStackTrace(); } } } } public static void getCountry(String Iso_Code) { try { // Query the database for the country iso code l_stmt = conn.createStatement(); l_rs = l_stmt.executeQuery( "SELECT * FROM countries" + " WHERE country_iso_code ='" + Iso_Code + "'"); //Affichage du résultat de la requête l_rs.next(); System.out.print(l_rs.getString(1) + " - "); System.out.print(l_rs.getString(2) + " - "); System.out.println(l_rs.getString(3)); // Close the result set l_rs.close(); } catch (SQLException e) { e.printStackTrace(); } finally { if (l_rs != null) { try { l_rs.close(); } catch (Exception e) { e.printStackTrace(); } } if (l_stmt != null) { try { l_stmt.close(); } catch (Exception e) { e.printStackTrace(); } } } } public static void doCreateProcedure() throws SQLException { // SQL statement to create a stored procedure String SQL_CREATE_PROC = "CREATE PROCEDURE getCountry(IN P1 VARCHAR(30))" + " LANGUAGE JAVA" + " SPECIFIC getCountry" + " NO SQL" + " EXTERNAL NAME \"SampleExternalMethods::getCountry\"" + " PARAMETER STYLE SQL"; // Create a SQL statement m_stmt = conn.createStatement(); // Execute the SQL m_stmt.executeUpdate(SQL_CREATE_PROC); // Close the statement //m_stmt.close(); } public static void doInvokeProcedure() throws SQLException { // Create SQL to invoke stored procedures String SQL_USE_PROC = "{ call getCountry(?) }"; // Create a callable statement with three binding parameters m_callStmt = conn.prepareCall(SQL_USE_PROC); m_callStmt.setString(1, "CA"); m_callStmt.executeQuery(); // Close the callable statement //m_callStmt.close(); } }
Afterwards, I have read this note in a Pointbase document:
To invoke the dateConvert external Java method from a stored function, you must use the
CREATE FUNCTION statement. The dateConvert external Java method is called from the
class, SampleExternalMethods.
In order for the database to access this external Java method, the class SampleExternalMethods
must be included in the database CLASSPATH. For PointBase Embedded - Server Option, it
must be in the Server CLASSPATH, but not in the Client CLASSPATH.
If PointBase Server is run with the Java Security Manager, in the java policy file grant
’com.pointbase.sp.spPermission’ to the class that implements the external Java method.
An "spPermission" consists of a class name with no action. The class name is a name of a class
that could be used in creating a Stored Procedure in PointBase. The naming convention follows
the hierarchical property naming convention and that is supported by
"java.security.BasicPermission". An asterisk may appear by itself, or if immediately preceded
by ".", may appear at the end of the name, to signify a wildcard match. The name cannot
contain any white spaces.
I'm not sure, but I suppose that I must include the class SampleExternalMethods in a .jar file.
The database CLASSPATH could be : C:\Sun\AppServer\pointbase\lib\
These my files in this database CLASSPATH:
pbclient.jar
pbembedded.jar
pbtools.jar
pbupgrade.jar
I have tryed to include the class SampleExternalMethods in pbclient.jar and pbembedded.jar with this command:
jar -uf pbembedded.jar SampleExternalMethods
Afterwards I do that,
1) Start Pointbase
2) Configuration of classpath
set classpath=C:\Sun\AppServer\pointbase\lib\pbclient.jar
set classpath=%classpath%;D:\J2EE\Ch07Code\Ch07_06
I precise that my file SampleExternalMethods is into D:\J2EE\Ch07Code\Ch07_06\Ch07.
Then, I run the program:
D:\J2EE\Ch07Code\Ch07_06>java -Djdbc.drivers=com.pointbase.jdbc.jdbcUniversalDriver Ch07.SampleExternalMethods
But I have an error message:
Exception in thread "main" java.lang.NoClassDefFoundError: Ch07.SampleExternalMethods (wrong name: SampleExternalMethods)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.DefineClass(ClassLoader.java:539)
The problem, I suppose, comes from that the class SampleExternalMethods
must be included in the database CLASSPATH, but there is a pbserver.jar with pointbase normally, but I didn't find it. That's why I use pbembedded.jar or pbclient.jar in order to include the class SampleExternalMethods. May be I must start from C:\Sun\AppServer\pointbase\lib\ instead of D:\J2EE\Ch07Code\Ch07_06\Ch07?
Please, can somebody helps me?
Thank you in advance.
cagou!jschell wrote:
And I doubt you can recurse like that for embedded java. You must have a class that does the functionality and another class that creates the proc.
>And I doubt you can recurse like that for embedded java. You must have a class that does the functionality and another class that creates the proc.
>
And I doubt you can recurse like that for embedded java. You must have a class that does the functionality and another class that creates the proc.
Thank you for your response, I have done two classes:
SampleExternalMethods.java:
package Ch07;
import java.sql.*;*
*public class SampleExternalMethods*
*public static void getCountry(String Iso_Code)*
*// A connection object to allow database callback*
*Connection l_conn = null;*
*Statement l_stmt = null;*
*ResultSet l_rs = null;*
*try*
*String url = "jdbc:pointbase:server://localhost/pointbaseDB";*
*String username = "PBPUBLIC";*
*String password = "PBPUBLIC";*
*l_conn = DriverManager.getConnection(url, username, password);*
*// Query the database for the country iso code*
*l_stmt = l_conn.createStatement();*
*l_rs = l_stmt.executeQuery( "SELECT* FROM PBPUBLIC.COUNTRIES"
+" WHERE country_iso_code ='"+ Iso_Code +"'");+
+//Affichage du résultat de la requête+
+l_rs.next();+
+System.out.print(l_rs.getString(1)+ " - ");
System.out.print(l_rs.getString(2) +" - ");+
+System.out.println(l_rs.getString(3));+
+// Close the result set+
+l_rs.close();+
+} catch (SQLException e) {+
+e.printStackTrace();+
+} finally {+
+if (l_rs != null) {+
+try {+
+l_rs.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+if (l_stmt != null) {+
+try {+
+l_stmt.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+if (l_conn != null) {+
+try {+
+l_conn.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+}+
+}+
+}+
CreateMethods.java:
+package Ch07;+
+import java.sql.*;+
+public class CreateMethods+
+{+
+// A connection object to allow database callback+
+static Connection m_conn = null;+
+static Statement m_stmt;+
+static CallableStatement m_callStmt = null;+
+public static void main(String[] args)+
+{+
+try+
+{+
+String url = "jdbc:pointbase:server://localhost/pointbaseDB";+
+String username = "PBPUBLIC";+
+String password = "PBPUBLIC";+
+m_conn = DriverManager.getConnection(url, username, password);+
+doCreateProcedure();+
+doInvokeProcedure();+
+} catch (SQLException e) {+
+e.printStackTrace();+
+} finally {+
+if (m_stmt != null) {+
+try {+
+m_stmt.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+if (m_callStmt != null) {+
+try {+
+m_callStmt.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+if (m_conn != null) {+
+try {+
+m_conn.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+}+
+}+
+public static void doCreateProcedure() throws SQLException {+
+// SQL statement to create a stored procedure+
+String SQL_CREATE_PROC = "CREATE PROCEDURE PBPUBLIC.getCountry(IN P1 VARCHAR(30))"+
" LANGUAGE JAVA"
+" SPECIFIC getCountry"+
" NO SQL"
+" EXTERNAL NAME \"SampleExternalMethods::getCountry\""+
" PARAMETER STYLE SQL";
// Create a SQL statement
m_stmt = m_conn.createStatement();
// Execute the SQL
m_stmt.executeUpdate(SQL_CREATE_PROC);
// Close the statement
//m_stmt.close();
public static void doInvokeProcedure() throws SQLException {
// Create SQL to invoke stored procedures
String SQL_USE_PROC = "{ call getCountry(?) }";
// Create a callable statement with three binding parameters
m_callStmt = m_conn.prepareCall(SQL_USE_PROC);
m_callStmt.setString(2, "CA");
m_callStmt.executeQuery();
// Close the callable statement
//m_callStmt.close();
}But I have the same error message that previously.
I have read this note and I suppose that the problem is linked:
If PointBase Server is run with the Java Security Manager, in the java policy file grant
*com.pointbase.sp.spPermission to the class that implements the external Java method.*
An "spPermission" consists of a class name with no action. The class name is a name of a class
that could be used in creating a Stored Procedure in PointBase. The naming convention follows
the hierarchical property naming convention and that is supported by
*"java.security.BasicPermission". An asterisk may appear by itself, or if immediately preceded*
by ".", may appear at the end of the name, to signify a wildcard match. The name cannot
contain any white spaces.
Can you explain me what I must to do in order to solve this problem of spPermission.
Thanks. -
Create a stored procedure to convert a temp table to current table
I have a current table in oracle called motor_assist2 with columns:
NAME
ADDRESS
PHONE
CITY
STATE
ZIP
FRIENDLINESS
SERVICE
WAIT_TIME
CONT_SERVICE
COMMENTS
DATETIME
TECHNICIAN1_RADIO
TECHNICIAN1_NAME
LOCATION
COUNTY_NAME
COUNTY_ABBR
MAV_TROOP
TECHNICIAN2_RADIO
TECHNICIAN2_NAME
ID
BEG_DATE
END_DATE
MONTH
YEAR
I have another table(motor_assist9) in excel with similiar columns that i want to insert that data into my current table(motor_assist2) using a stored procedure but am not sure how to do it. Can anybody help me? Thanks
Deannaso this is my procedure:
create or replace procedure "PREVIOUS_MA_DATA"
is
BEGIN
FOR var IN 1 ..3289 LOOP
insert into MAV.MOTOR_ASSIST2
(NAME,ADDRESS,PHONE,CITY,STATE,ZIP,
FRIENDLINESS,SERVICE,WAIT_TIME,
CONT_SERVICE,COMMENTS,DAY,CLOCK,TECHNICIAN1_RADIO,
TECHNICIAN1_NAME,LOCATION,COUNTY_NAME,COUNTY_ABBR,
MAV_TROOP,TECHNICIAN2_RADIO,TECHNICIAN2_NAME,FY,
BEG_DATE,END_DATE,MONTH,YEAR,to_date(DAY||' '||CLOCK,'dd-mon-rr hh12:mi:ss')DATETIME
from temp;
END LOOP;
END;
when i try to compile it, it gives me the errors:
Compilation failed,line 10 (13:20:46)
PL/SQL: ORA-00917: missing commaCompilation failed,line 8 (13:20:46)
PL/SQL: SQL Statement ignored
Where am i missing a comma??? -
Can I call a stored procedure which has DMLs from a function ??
Hello all,
Here is my req. I Want to use a function which in turn executes a procedure to populate a table. This procedure inserts data into a table .
How can I make it work.?
thanks,
DnakkaHi,
Here is an example procedure and a function.
The procedure:
CREATE OR REPLACE PROCEDURE proc1 AS
BEGIN
INSERT INTO tab1 VALUES(1, 'some string value');
COMMIT;
END;
The function which calls proc1:
CREATE OR REPLACE FUNCTION func1 RETURN VARCHAR2 AS
BEGIN
proc1;
RETURN 'done';
END;
Hope that helps.
Savitha. -
Can we query a stored procedure results as an SQL Table ?
Hi,
Can we query a results from the results of a stored procedure returning a result set either as cursors or as PL/SQL Table like what we do like this
select * from <tablename>
select * from (select * from tablename) alias. instead of this, can we do like this
select * from (results of stored procedure) alias.
Please Provide any Help.I agree. Pipelined Table Functions are the way to go.
Docs at http://tahiti.oracle.com
Working demos in Morgan's Library at www.psoug.org under Pipelined Table Functions. -
Query OR Stored Proc to get data from Tables from All Schemas in the d/base
Hello Experts, (I appologize if i am not using the right way to ask questions)
I have a database, and it has around 400 schemas in it. I have designed a query which will fetch the data from three different table's from Schema1.
But it will be a tedious process of entering the 400 schemas names and pulling the information.
I would like to know as to what would be the best possible way to;
1) Look for all the schemas in the database
2) Look for those specific tables in the schema, which has the data in the tables.
3) If the tables are not present, than Ignore that schema and proceed further.
4) Load the data into a table
Any help, would appreciate it.
Thanks!
The query that i am using is as follows;
-- Query to select all the Schemas from the database
select username from all_users
order by username;
-- Sample Query to see if Tables exsist in the schema
SELECT DISTINCT OWNER, OBJECT_NAME
FROM ALL_OBJECTS
WHERE OBJECT_TYPE = 'TABLE'
AND OBJECT_NAME IN ('ENROLLMENT', 'PRDCT', 'L_P_L')
AND OWNER in ('Schema_1', 'Schema_2', Schema_3', Schema_4',Schema_5', Schema_6')
ORDER BY OWNER;
--Query to get the data from the tables in a Schema
select 'Schema_1@DATABASE_NAME' AS SCHEMA,
(SELECT MAX(LOAD_DT) FROM Schema_1.LOAD_STATUS) AS MAX_LOAD,
L_PROD_LINE.PROD_LINE,
COUNT(DISTINCT ENROLLMENT.MEM_NBR) AS MEMBERSHIP
FROM
Schema_1.ENROLLMENT,
Schema_1.PRDCT,
Schema_1.L_P_L
WHERE
ENROLLMENT.PRODUCT_ID = PRDCT.PRODUCT_ID AND
PRODUCT.PROD_LINE_ID = L_P_L.ID
GROUP BY
L_P_L.PROD_LINE;Hi,
999355 wrote:
Hello Experts, (I appologize if i am not using the right way to ask questions)See the froum FAQ {message:id=9360002}
I have a database, and it has around 400 schemas in it. I have designed a query which will fetch the data from three different table's from Schema1.
But it will be a tedious process of entering the 400 schemas names and pulling the information.
I would like to know as to what would be the best possible way to;
1) Look for all the schemas in the database
2) Look for those specific tables in the schema, which has the data in the tables.
3) If the tables are not present, than Ignore that schema and proceed further.
4) Load the data into a table
Any help, would appreciate it.
Thanks!
The query that i am using is as follows;
-- Query to select all the Schemas from the database
select username from all_users
order by username;
-- Sample Query to see if Tables exsist in the schema
SELECT DISTINCT OWNER, OBJECT_NAME
FROM ALL_OBJECTS
WHERE OBJECT_TYPE = 'TABLE'
AND OBJECT_NAME IN ('ENROLLMENT', 'PRDCT', 'L_P_L')
AND OWNER in ('Schema_1', 'Schema_2', Schema_3', Schema_4',Schema_5', Schema_6')
ORDER BY OWNER; Do you want to give a list of possible schemas (like the 6 above), or do you want to consider all schemas, however many and whatever they are called?
You can get the right information for ALL_OBJECTS, but, since you known all the objects of interest are tables, ALL_TABLES will be faster and simpler.
--Query to get the data from the tables in a Schema
select 'Schema_1@DATABASE_NAME' AS SCHEMA,
(SELECT MAX(LOAD_DT) FROM Schema_1.LOAD_STATUS) AS MAX_LOAD,
L_PROD_LINE.PROD_LINE,
COUNT(DISTINCT ENROLLMENT.MEM_NBR) AS MEMBERSHIP
FROM
Schema_1.ENROLLMENT,
Schema_1.PRDCT,
Schema_1.L_P_L
WHERE
ENROLLMENT.PRODUCT_ID = PRDCT.PRODUCT_ID AND
PRODUCT.PROD_LINE_ID = L_P_L.ID
GROUP BY
L_P_L.PROD_LINE;I take it that the tables in question are ENROLLMENT, PRDCT and L_P_L; they won't have different names in different schemas.
You can start this way:
BEGIN
FOR c IN (
SELECT owner
FROM all_tables
WHERE table_name IN ( 'ENROLLMENT'
, 'PRDCT'
, 'L_P_L'
GROUP BY owner
HAVING COUNT (*) = 3
LOOP
... -- Now get the results for tables in the c.owner schema
END LOOP;
END;
/This will find the schemas that have all 3 of those tables.
Inside the loop, write another dynamic query. All that will change is the value of c.owner
Sorry, I'm running out of time now. I hope this helps. -
How do i create an ssis package that transforms data from a text file?
I have a text file with data that in the following format; i want this data in columns with the appropriate heading. Any ideas??
Name – Tony
Married – 2 children (Girl:3, Boy:1)
AddressLine1: 10 Sunnhill Ave
AddressLine2: Streatham
AddressLine3: London
PostCode: SW18 7NN
Name – Sarah
Married – 2 children (Girl:3, Boy:1)
AddressLine1: 10 High St
AddressLine2: Streatham
AddressLine3: London
PostCode: TW18 7NN
Name – Tom
Married – 2 children (Girl:3, Boy:1)
AddressLine1: 10 Bridge Ave
AddressLine2: Hammersmith
AddressLine3: London
PostCode: TF20 8HN
sukaiI don't see how you're going to pivot that using SSIS. I happen to know VBA pretty well, and I'll give you this Macro, which should do what you want.
Sub CombineRows()
lastRow = Range("A" & Rows.Count).End(xlUp).Row
'set rowcount to row where you want 1st entry
RowCount = 1
NewRow = RowCount
Start = False
Do While RowCount <= lastRow
If Start = False Then
If Range("A" & RowCount) <> "" Then
Start = True
StartRow = RowCount
End If
Else
If Range("A" & (RowCount + 1)) = "" Then
ColCount = 1
For MoveRow = StartRow To RowCount
Cells(NewRow, ColCount) = Cells(MoveRow, "A")
ColCount = ColCount + 1
Next MoveRow
NewRow = NewRow + 1
Start = False
End If
End If
RowCount = RowCount + 1
Loop
Rows(NewRow & ":" & lastRow).Delete
End Sub
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it. -
Accessing data from Table control
Hi,
I created a table control using report program and i am trying to enter data in the table control which i want to update in the DB table. How can i get the data entered in table control to the report program, so that i can update the DB table.
Please help me finding out which variable will hold the data entered in table control(dynamically).hi gautham,
1. While designing set the table control as input field.
2. In ur program create an internal table, with the same structure as your table control.
3. Whenever an entry is made in the table control, modify your internal table.
4. While saving use the internal table data to update the custom table.
If internal table name is same in both screen painter(table control) and in the program then the values will automatically come into the internal table in the program with out programming.
Otherwise we have programtically transfer the values.
In the PAI event using move or move-corresponding statement.
Check the program *RSDEMO02*
check the links
http://help.sap.com/saphelp_nw04/helpdata/EN/9f/dbac9f35c111d1829f0000e829fbfe/content.htm
Yogesh N -
Accessing data from tables P2050, P2051 and P2052
Hello all,
I am trying to access the data stored in P2050, P2051, and P2052. I cannot access this data directly. Is there a way to get this data through another tables??
Thanks
SLHI!
You have to trace the transaction, which fills these structures.
Use the transaction ST05 to sqltrace them.
1. Turn on SQL trace in ST05
2. Switch to an another modus with alt-tab, enter into the transaction
3. Navigate until you will see the required data on the screen
4. Go back to ST05 with alt-tab, deactivate trace, and show results. You'll see all read tables here.
Regards
Tamá -
Stored Procedure that creates a trigger on new tables
I am trying to create a stored procedure that creates a trigger on new tables whenever the table is created. The procedure should receive the new project table's name, and then create a dml trigger on that procedure. When the procedure
is run, I get an error "Incorrect syntax near keyword 'TRIGGER.'" This is how my Stored Procedure looks in SQL Management Studio. Any suggestions?
USE [RIDB_DynamicDesign]
GO
/****** Object: StoredProcedure [dbo].[sp_CreateTriggerMarkLatest] Script Date: 11/08/2014 16:43:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_CreateTriggerMarkLatest] @ProjectTable nvarchar(128), @ItExists int OUTPUT
AS
DECLARE @SQL nvarchar(4000)
DECLARE @MarkLatest nvarchar(30)
DECLARE @LatTrue bit
DECLARE @LatFalse bit
SET @LatTrue = 'True'
SET @LatFalse = 'False'
SET @SQL = 'CREATE TRIGGER tr_MarkLatest ON ' + @ProjectTable + ' AFTER INSERT
AS
UPDATE ' + @ProjectTable + ' SET Latest = @LatFalse
UPDATE ' + @ProjectTable + ' SET Latest = @LatTrue WHERE
ID IN (SELECT ID FROM ' + @ProjectTable + ' p WHERE
NOT EXISTS (SELECT 1 FROM ' + @ProjectTable + ' WHERE
Name = p.Name AND Vers = p.Vers
AND Date > p.Date))'
EXEC sp_executesql @SQL, N'@ProjectTable nvarchar(128), @LatTrue bit, @LatFalse bit',
@ProjectTable, @LatTrue, @LatFalse
GinaFirst you have to debug the dynamic SQL string with a PRINT statement. I see some problems:
CREATE PROCEDURE [dbo].[uspCreateTriggerMarkLatest] @ProjectTable nvarchar(128), @ItExists int OUTPUT
AS BEGIN
DECLARE @SQL nvarchar(4000)
DECLARE @MarkLatest nvarchar(30)
DECLARE @LatTrue bit
DECLARE @LatFalse bit
SET @LatTrue = 'True'
SET @LatFalse = 'False'
SET @SQL = 'CREATE TRIGGER tr_MarkLatest ON ' + @ProjectTable + ' AFTER INSERT
AS
UPDATE ' + @ProjectTable + ' SET Latest = @LatFalse
UPDATE ' + @ProjectTable + ' SET Latest = @LatTrue WHERE
ID IN (SELECT ID FROM ' + @ProjectTable + ' p WHERE
NOT EXISTS (SELECT 1 FROM ' + @ProjectTable + ' WHERE
Name = p.Name AND Vers = p.Vers
AND Date > p.Date))'
PRINT @SQL;
-- EXEC sp_executesql @SQL, N'@ProjectTable nvarchar(128), @LatTrue bit, @LatFalse bit', @ProjectTable, @LatTrue, @LatFalse
END
GO
DECLARE @ItExists int, @ProjectTable nvarchar(128) = N'TestTrigger';
EXEC [dbo].[uspCreateTriggerMarkLatest] @ProjectTable, @ItExists OUTPUT
CREATE TRIGGER tr_MarkLatest ON TestTrigger AFTER INSERT
AS
UPDATE TestTrigger SET Latest = @LatFalse
UPDATE TestTrigger SET Latest = @LatTrue WHERE
ID IN (SELECT ID FROM TestTrigger p WHERE
NOT EXISTS (SELECT 1 FROM TestTrigger WHERE
Name = p.Name AND Vers = p.Vers
AND Date > p.Date))
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014 -
How to create a stored procedure and use it in Crystal reports
Hi All,
Can anyone explain me how to create a stored procedure and use that stored procedure in Crystal reports. As I have few doubts in this process, It would be great if you can explain me with a small stored proc example.
Thanks in advance.If you are using MSSQL SERVER then try creating a stored procedure like this
create proc Name
select * from Table
by executing this in sql query analyzer will create a stored procedure that returns all the data from Table
here is the syntax to create SP
Syntax
CREATE PROC [ EDURE ] procedure_name [ ; number ]
[ { @parameter data_type }
[ VARYING ] [ = default ] [ OUTPUT ]
] [ ,...n ]
[ WITH
{ RECOMPILE | ENCRYPTION | RECOMPILE , ENCRYPTION } ]
[ FOR REPLICATION ]
AS sql_statement [ ...n ]
Now Create new report and create new connection to your database and select stored procedure and add it to the report that shows all the columns and you can place the required fields in the report and refresh the report.
Regards,
Raghavendra
Edited by: Raghavendra Gadhamsetty on Jun 11, 2009 1:45 AM -
Issue with a stored procedure that uses a sys refcursor to output dataset..
Hi All:
I create a stored procedure that uses an in out sys ref cursor:
create or replace procedure FIRE_SALES_100_CALLS_REPORT
( p_cursor in out sys_refcursor)
IS
BEGIN
--Insert into the temp table the records for the rep sales
EXECUTE IMMEDIATE '
INSERT INTO TMP_SALES_CNT_BY_USER
TOTALPRODUCTSSOLD,
NUMBEROFCALLS,
SALESPER100CALLS,
SERVICEORDERNUM,
PRODUCT,
LOGIN,
FST_NAME,
LAST_NAME,
NAME,
POSITIONHELD,
CURRENTPARPARTYID,
QUERY_DATE,
CREATED_BY
SELECT e.TotalProductsSold,
e.NumberOfCalls,
((e.TotalProductsSold/e.NumberOfCalls)*100) AS SalesPer100Calls,
e.ServiceOrderNum,
e.Product,
e.login,
e.fst_name,
e.last_name,
e.name,
e.PositionHeld,
e.CurrentParPartyID,
e.query_date,
e.created_by
FROM (
SELECT COUNT(o.order_num) over ( partition by u.login
order by u.login) AS TotalProductsSold,
SUM(NVL(x.n_inbound,1) + NVL(x.n_outbound,1)) over (partition by u.login
order by u.login) AS NumberOfCalls,
o.order_num AS ServiceOrderNum,
pi.name as Product,
u.login,
c.fst_name,
c.last_name,
postn.name,
c.pr_held_postn_id as PositionHeld,
p.par_party_id as CurrentParPartyID,
NVL(x.query_date,NVL(o.last_upd, null)) AS query_date,
o.created_by
FROM firestg.SEB_S_order o
INNER join firestg.seb_s_order_item oi ON o.row_id = oi.order_id
INNER join firestg.seb_s_prod_int pi ON oi.prod_id = pi.row_id
INNER join firestg.SEB_s_contact c on c.Row_Id = o.created_by
INNER join firestg.SEB_s_user u on u.row_id = o.created_By
INNER join firestg.SEB_s_party p on p.row_id = c.pr_held_postn_id
INNER join firestg.SEB_s_postn postn on postn.row_id = c.pr_held_postn_id
LEFT OUTER JOIN (
SELECT taw.QUERY_DATE,
vaw.n_inbound,
vaw.n_outbound,
oaw.object_name, oaw.object_id
FROM GEN_T_AGENT_WEEK taw
INNER JOIN GEN_V_AGENT_WEEK vaw ON taw.time_key = vaw.time_key
INNER JOIN GEN_O_AGENT_WEEK oaw ON oaw.object_id = vaw.object_id) x
ON u.cti_acd_userid = x.object_name
WHERE NVL(x.query_date,NVL(o.last_upd, null)) BETWEEN (TRUNC (next_day (sysdate, ''SUN''))-14)
AND (TRUNC (next_day (sysdate, ''SUN''))-8)
AND o.status_cd IN (''Complete''))e';
--Lookup the first level to see if there is a higher level person
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET (ParPartyID_1ST, LOGIN_1ST,FST_NAME_1ST,LST_NAME_1ST,TITLE_1ST) =
(SELECT pa.par_party_id,
U.Login,
C.FST_NAME,
C.Last_Name,
p.name
FROM firestg.seb_s_postn p
inner join firestg.seb_s_user U on u.Row_Id = p.pr_emp_id
inner join firestg.seb_s_contact c on c.Row_Id = p.pr_emp_id
INNER join firestg.SEB_s_party pa on pa.row_id = c.pr_held_postn_id
WHERE p.row_id = a.currentparpartyid)
WHERE CurrentParPartyID IS NOT NULL';
--Lookup the second level to see if there is a higher level person
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET (ParPartyID_2ND, LOGIN_2ND,FST_NAME_2ND,LST_NAME_2ND,TITLE_2ND) =
(SELECT pa.par_party_id,
U.Login,
C.FST_NAME,
C.Last_Name,
p.name
FROM firestg.seb_s_postn p
inner join firestg.seb_s_user U on u.Row_Id = p.pr_emp_id
inner join firestg.seb_s_contact c on c.Row_Id = p.pr_emp_id
INNER join firestg.SEB_s_party pa on pa.row_id = c.pr_held_postn_id
WHERE p.row_id = a.ParPartyID_1ST)
WHERE a.ParPartyID_1ST IS NOT NULL';
--Lookup the third level to see if there is a higher level person
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET (ParPartyID_3RD, LOGIN_3RD,FST_NAME_3RD,LST_NAME_3RD,TITLE_3RD) =
(SELECT pa.par_party_id,
U.Login,
C.FST_NAME,
C.Last_Name,
p.name
FROM firestg.seb_s_postn p
inner join firestg.seb_s_user U on u.Row_Id = p.pr_emp_id
inner join firestg.seb_s_contact c on c.Row_Id = p.pr_emp_id
INNER join firestg.SEB_s_party pa on pa.row_id = c.pr_held_postn_id
WHERE p.row_id = a.ParPartyID_2ND)
WHERE a.ParPartyID_2ND IS NOT NULL';
--Lookup the fourth level to see if there is a higher level person
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET (ParPartyID_4TH, LOGIN_4TH,FST_NAME_4TH,LST_NAME_4TH,TITLE_4TH) =
(SELECT pa.par_party_id,
U.Login,
C.FST_NAME,
C.Last_Name,
p.name
FROM firestg.seb_s_postn p
inner join firestg.seb_s_user U on u.Row_Id = p.pr_emp_id
inner join firestg.seb_s_contact c on c.Row_Id = p.pr_emp_id
INNER join firestg.SEB_s_party pa on pa.row_id = c.pr_held_postn_id
WHERE p.row_id = a.ParPartyID_3RD)
WHERE a.ParPartyID_3RD IS NOT NULL';
--Lookup the fifth level to see if there is a higher level person
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET (ParPartyID_5TH, LOGIN_5TH,FST_NAME_5TH,LST_NAME_5TH,TITLE_5TH) =
(SELECT pa.par_party_id,
U.Login,
C.FST_NAME,
C.Last_Name,
p.name
FROM firestg.seb_s_postn p
inner join firestg.seb_s_user U on u.Row_Id = p.pr_emp_id
inner join firestg.seb_s_contact c on c.Row_Id = p.pr_emp_id
INNER join firestg.SEB_s_party pa on pa.row_id = c.pr_held_postn_id
WHERE p.row_id = a.ParPartyID_4TH)
WHERE a.ParPartyID_4TH IS NOT NULL';
-- If there was no 1st place then the rep is a VP
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET a.vp = a.last_name || '', '' || a.fst_name,
a.vp_login = a.login
WHERE a.login_1st IS NULL';
--If there is no second place then the rep has a VP and is a Director
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET a.vp = a.lst_name_1st || '', '' || a.fst_name_1st,
a.vp_login = a.login_1st,
a.director = a.last_name || '', '' || a.fst_name,
a.director_login = a.login
WHERE a.login_1st IS NOT NULL
AND a.login_2ND IS NULL';
--IF there is no third place then the rep has a VP, Director & is a Manager
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET a.vp = a.lst_name_2ND || '', '' || a.fst_name_2ND,
a.vp_login = a.login_2ND,
a.director = a.lst_name_1st || '', '' || a.fst_name_1st,
a.director_login = a.login_1st,
a.manager = a.last_name || '', '' || a.fst_name,
a.manager_login = a.login
WHERE a.login_1st IS NOT NULL
AND a.login_2ND IS NOT NULL
AND a.login_3rd IS NULL';
--If there is no fourth place then the rep has a VP, Dir, Manager, and is a Supervisor
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET a.vp = a.lst_name_3RD || '', '' || a.fst_name_3RD,
a.vp_login = a.login_3RD,
a.director = a.lst_name_2ND || '', '' || a.fst_name_2ND,
a.director_login = a.login_2ND,
a.manager = a.lst_name_1st || '', '' || a.fst_name_1st,
a.manager_login = a.login_1st,
a.supervisor = a.last_name || '', '' || a.fst_name,
a.supervisor_login = a.login
WHERE a.login_1st IS NOT NULL
AND a.login_2ND IS NOT NULL
AND a.login_3rd IS NOT NULL
AND a.login_4th IS NULL';
--If there is no fifth plance then the rep has a VP, Dir, Mgr, Supervisor, and is a Team Lead
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET a.vp = a.lst_name_4TH || '', '' || a.fst_name_4TH,
a.vp_login = a.login_4TH,
a.director = a.lst_name_3RD || '', '' || a.fst_name_3RD,
a.director_login = a.login_3RD,
a.manager = a.lst_name_2ND || '', '' || a.fst_name_2ND,
a.manager_login = a.login_2ND,
a.supervisor = a.lst_name_1st || '', '' || a.fst_name_1st,
a.supervisor_login = a.login_1st,
a.teamlead = a.last_name || '', '' || a.fst_name,
a.teamlead_login = a.login
WHERE a.login_1st IS NOT NULL
AND a.login_2ND IS NOT NULL
AND a.login_3rd IS NOT NULL
AND a.login_4th IS NOT NULL
AND a.login_5th IS NULL';
--If there is a fifth place then the rep has a VP, Dir, Mgr, Supervisor, Team Lead and is a rep
EXECUTE IMMEDIATE '
UPDATE TMP_SALES_CNT_BY_USER a
SET a.vp = a.lst_name_5TH || '', '' || a.fst_name_5TH,
a.vp_login = a.login_5TH,
a.director = a.lst_name_4TH || '', '' || a.fst_name_4TH,
a.director_login = a.login_4TH,
a.manager = a.lst_name_3RD || '', '' || a.fst_name_3RD,
a.manager_login = a.login_3RD,
a.supervisor = a.lst_name_2ND || '', '' || a.fst_name_2ND,
a.supervisor_login = a.login_2ND,
a.teamlead = a.lst_name_1st || '', '' || a.fst_name_1st,
a.teamlead_login = a.login_1st
WHERE a.login_1st IS NOT NULL
AND a.login_2ND IS NOT NULL
AND a.login_3rd IS NOT NULL
AND a.login_4th IS NOT NULL
AND a.login_5th IS NOT NULL';
open p_cursor for
SELECT tsc.vp,
tsc.director,
tsc.manager,
tsc.supervisor,
tsc.teamlead,
(tsc.last_name || ', ' || tsc.fst_name) AS Rep,
tsc.product,
tsc.totalproductssold,
tsc.numberofcalls,
tsc.salesper100calls
FROM TMP_SALES_CNT_BY_USER tsc;
END FIRE_SALES_100_CALLS_REPORT;
The table I use is a Global temp table.
This runs just fine in oracle but when I try to build a data foundation in Business Objects I get the error that says you cannot insert/update/delete in a READ ONLY Transaction.
I really need some advice on what to do since I really dont have access to a scheduled script and table that would store my data ahead of time.Well, AFAIK, BO is a reporting tool, so it si read-only by nature. I do not know if it possible to "tell" BO table is GTT and it is OK to write to it. You need to post this in BO forum.
SY. -
How to wrap a stored procedure that outputs PL/SQL records for JDBC?
Hello everybody,
Is there an example for wrapping a stored procedure that outputs PL/SQL records and/or PL/SQL tables of records, so that it can be called from JDBC?
Since this is not possible with the Oracle JDBC driver, Oracle recommends "To wrap a stored procedure that uses PL/SQL tables, break the data into components or perhaps use Oracle collection types." (http://download-west.oracle.com/docs/cd/B12037_01/java.101/b10979/ref.htm#sthref2123)
Many thanks for any help,
Cheers, ChristophHi Christoph,
Have you tried using JPublisher, or -more easily- JDeveloper (Go to your database connection in the "Connections" pane, open the "Packages" node, right click to "Generate Java...").
These approaches (at minimum, use of jpub) will generate required PL/SQL wrapper code, including SQL Type declarations. Once these are installed in the database, you can invoke the wrapper procedures directly from Java.
-- Ekkehard
Maybe you are looking for
-
Cost center after settlement in FAGLL03 REPORT
we have process of material issue thru maintennce order. after issuing material FI entry is on respective gl and maintence order in report fagll03 we can see this combination and then after settlement of cost of order on cost center we are not able t
-
No one has been able to help me with my Creative Zen...and when I say this I MEAN it. I think the problem is that I may have erased a driver or something because my computer doesn't recognize my player no matter how many times I install and uninstall
-
hello experts,,,, anyone who could help find the codes to be dragged in crystal reports about the customer receivable lapses.....as highlighted in my attchment ...please
-
PowerBuilder 12.5.2 EBF
Is there a location for the current EBF files? I'm running PM 12.5.2 Build 5583
-
Regarding PO release strategies
Hi Guys, During implementation, I came across one senario where some input are required. I am having certain release strategies already configured in SAP, based on, - PO Type - PO Net Value - Plant Now I am suppose to add one more criteria, for relea