Create a View, function or stored procedure for query?
Hi All,
I like to know how I can create a view or function for the query below. If its going to be a function or stored procedure will I be able to union it with another view?
DECLARE
@BegDate DATE,
@EndDate DATE
SELECT
@BegDate = MIN(vl.VoidStartDate),
@EndDate = MAX(vl.LetDate)
FROM #VoidLoss vl
;WITH d(d) AS (
SELECT TOP (DATEDIFF(dd, @BegDate, @EndDate))
DATEADD(dd, ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) -1, @BegDate)
FROM sys.all_objects o
), cal AS (
SELECT
d.d,
MONTH(d.d) AS m,
YEAR(d.d) AS y
FROM d
SELECT
vl.History_IND,
vl.PropCode,
vl.VoidCategory,
vl.ControlGroup,
CASE WHEN vl.VoidStartDate < MIN(cal.d) THEN MIN(cal.d) ELSE vl.VoidStartDate END AS VoidStartDate,
CASE WHEN vl.LetDate > MAX(cal.d) THEN MAX(cal.d) ELSE vl.LetDate END AS LetDate,
vl.MarketRent,
DATENAME(mm, CAST('1900-' + CAST(cal.m AS VARCHAR(2)) + '-1' AS DATE)) AS [Month],
cal.y AS [Year],
COUNT(*) AS DaysVoid,
COUNT(*) * vl.MarketRent AS VoidLoss
FROM
#VoidLoss vl
JOIN cal
ON cal.d BETWEEN DATEADD(dd, 1, vl.VoidStartDate) AND vl.LetDate
GROUP BY
vl.History_IND,
vl.PropCode,
vl.VoidCategory,
vl.ControlGroup,
vl.VoidStartDate,
vl.LetDate,
vl.MarketRent,
cal.m,
cal.y
ORDER BY
vl.History_IND,
vl.PropCode,
vl.VoidStartDate
Thanks
A view or an inline-function is a single query, so this part does not fit in:
DECLARE
@BegDate DATE,
@EndDate DATE
SELECT
@BegDate = MIN(vl.VoidStartDate),
@EndDate = MAX(vl.LetDate)
FROM #VoidLoss vl
And you cannot have it multi-statement function either, since you cannot refer to temp tables in such a function. In any case, using a multi-statement function in a view definition or nest it in another function definition is likely to be a performance disaster.
The sole alternative that remains as long as you have the temp table is a stored procedure. You cannot use a stored procedure in a view or a function.
Erland Sommarskog, SQL Server MVP, [email protected]
Similar Messages
-
Privilege for creating a View from a Stored Procedure
Hi,
I need to create a view from a procedure. I could do it from an anonymous block whereas I am unable to do that from a Stored Procedure. Should I need a specific privilege for performing this operation? If so what would be the reason behind it? Will that privilege be given in production databases?
Code to replicate:
CREATE TABLE t11 AS SELECT * FROM DUAL;
CREATE OR REPLACE PROCEDURE p_etl_test_view
AS
BEGIN
EXECUTE IMMEDIATE 'CREATE OR REPLACE VIEW v_t11 AS SELECT * FROM t11';
END;
PROCEDURE P_ETL_TEST_VIEW compiled
Elapsed: 00:00:00.131
BEGIN
EXECUTE IMMEDIATE 'CREATE OR REPLACE VIEW v_t11 AS SELECT * FROM t11';
END;
anonymous block completed
Elapsed: 00:00:00.069
BEGIN
p_etl_test_view;
END;
Error starting at line 13 in command:
BEGIN
p_etl_test_view;
END;
Error report:
ORA-01031: insufficient privileges
ORA-06512: at "OCCSS_ENTMT_HK_DEV_01.P_ETL_TEST_VIEW", line 4
ORA-06512: at line 2
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to change the current username or password
without the appropriate privilege. This error also occurs if
attempting to install a database without the necessary operating
system privileges.
When Trusted Oracle is configure in DBMS MAC, this error may occur
if the user was granted the necessary privilege at a higher label
than the current login.
*Action: Ask the database administrator to perform the operation or grant
the required privileges.
For Trusted Oracle users getting this error although granted the
the appropriate privilege at a higher label, ask the database
administrator to regrant the privilege at the appropriate label.
Elapsed: 00:00:00.100
The privileges I am having:
SELECT *
FROM dba_sys_privs
WHERE grantee = 'OCCSS_ENTMT_HK_DEV_01'
OR grantee IN (SELECT granted_role
FROM dba_role_privs
where grantee = 'OCCSS_ENTMT_HK_DEV_01')
ORDER BY 1;
GRANTEE
PRIVILEGE
ADMIN_OPTION
EXP_FULL_DATABASE
ADMINISTER RESOURCE MANAGER
NO
EXP_FULL_DATABASE
ADMINISTER SQL MANAGEMENT OBJECT
NO
EXP_FULL_DATABASE
BACKUP ANY TABLE
NO
EXP_FULL_DATABASE
CREATE SESSION
NO
EXP_FULL_DATABASE
CREATE TABLE
NO
EXP_FULL_DATABASE
EXECUTE ANY PROCEDURE
NO
EXP_FULL_DATABASE
EXECUTE ANY TYPE
NO
EXP_FULL_DATABASE
READ ANY FILE GROUP
NO
EXP_FULL_DATABASE
RESUMABLE
NO
EXP_FULL_DATABASE
SELECT ANY SEQUENCE
NO
EXP_FULL_DATABASE
SELECT ANY TABLE
NO
OCCSS_ENTMT_HK_DEV_01
CREATE DATABASE LINK
NO
OCCSS_ENTMT_HK_DEV_01
CREATE TABLE
NO
OCCSS_ENTMT_HK_DEV_01
DEBUG CONNECT SESSION
NO
OCCSS_ENTMT_HK_DEV_01
SELECT ANY DICTIONARY
NO
SCB_SCHEMA_ROLE
ALTER SESSION
NO
SCB_SCHEMA_ROLE
CREATE CLUSTER
NO
SCB_SCHEMA_ROLE
CREATE DIMENSION
NO
SCB_SCHEMA_ROLE
CREATE INDEXTYPE
NO
SCB_SCHEMA_ROLE
CREATE JOB
NO
SCB_SCHEMA_ROLE
CREATE MATERIALIZED VIEW
NO
SCB_SCHEMA_ROLE
CREATE OPERATOR
NO
SCB_SCHEMA_ROLE
CREATE PROCEDURE
NO
SCB_SCHEMA_ROLE
CREATE SEQUENCE
NO
SCB_SCHEMA_ROLE
CREATE SESSION
NO
SCB_SCHEMA_ROLE
CREATE SYNONYM
NO
SCB_SCHEMA_ROLE
CREATE TABLE
NO
SCB_SCHEMA_ROLE
CREATE TRIGGER
NO
SCB_SCHEMA_ROLE
CREATE TYPE
NO
SCB_SCHEMA_ROLE
CREATE VIEW
NOBoopathyVasagam wrote:
Thank you for your answer. So should I issue the below statement? (Since I dont have dba privs i couldn't test this)
GRANT CREATE VIEW to P_ETL_TEST_VIEW;
I doubt that above will prevent the error from being thrown.
prior to running anonymous block again; just do as below
SET ROLE NONE;
doing so should result in same error being thrown when invoking
BEGIN
p_etl_test_view;
END; -
Trouble referencing return values of a Function in Stored Procedure
Hello all,
I have the following Function and Stored Procedure (simplified for this post). The error I am getting is in the SELECT, WHERE clause of the UPDATE command. My function is returning a sys_refcursor and I am trying to reference column names but keep getting the error
ORA-00904: "PUBLISHEDDOCVERSIONID": invalid identifier
What am I doing wrong?
Function
CREATE OR REPLACE FUNCTION &HKDB_Schema_Name..QueryKnowdeDocVersion(aKGID int)
RETURN sys_refcursor
IS
aCur sys_refcursor;
BEGIN
OPEN aCur FOR
SELECT pkd.KnowdeID as "PublishedKnowdeID", pkd.DocumentID as "PublishedDocID", pkd.VersionID as "PublishedDocVersionID"
FROM KnowdeDocument pkd
WHERE pkd.KGID = aKGID;
RETURN aCur;
END;Stored Procedure
UPDATE KnowdeDocument
SET DocumentID = (SELECT PublishedDocID FROM (SELECT QueryKnowdeDocVersion(aKGID, aPublishedKGID, aTextVersionID) FROM DUAL)
WHERE PublishedKnowdeID = KnowdeDocument.KnowdeID
AND PublishedDocID = KnowdeDocument.DocumentID
AND ((PublishedDocVersionID is NULL and KnowdeDocument.VersionID is NULL) OR (PublishedDocVersionID is not NULL AND
PublishedDocVersionID = KnowdeDocument.VersionID)))Regards,
TobyHi redeye,
Your select is from:
(select queryknowdedocversion(akgid
,apublishedkgid
,atextversionid)
from dual)This has no publisheddocversionid. Unfortunately I cannot figure out what you are trying to do with that ref_cursor.
Edit:
Or perhaps publisheddocversionid is a column in KnowdeDocument? Could this be case sensitive as well? (Bad idea to use quotations when naming things)
Regards
Peter
Edited by: Peter on Aug 24, 2009 3:39 AM -
Question: Are there any advantages for stored procedure for data block?
There are two ways to create data block:
1. query table or view or
2. stored procedure.
After 9i, AS has a PL/SQL compiler. Do we still see the advantage of using stored procedure, as claimed that it is faster due to the stored procedure always compiled?
Thank you in advance.
JimmyJimmy,
The "fast" side is not the only one benefit of stored procedures.
Of course, you can use the BULK COLLECT functionality which is not available into Forms.
But stored procedure is a good way to perform the following actions:
complex handeling of datas (insert, update or delete that generate severals actions on other tables).
externalization/centralisation of business rules.(separate the design and functionnal work).
more secutity, because you can prohibit manipulation of datas outside of the procedures.
You can change the rules without modify the forms.
etc.
Francois -
Missing Stored Procedure for SQL Server
Hello,
I'm trying to create the standard TestStand 4 schema for SQL Server. I get the following error when I run multiple numeric test cases:
An error occurred calling 'LogResults' in 'ITSDBLog' of 'zNI TestStand Database Logging'
An error occurred executing a statement.
Schema: SQL Server Stored Proc (NI).
Statement: MEAS_NUMERICLIMIT.
Could not find stored procedure 'InsertStepMeasNumericLimit'.
Description: Could not find stored procedure 'InsertStepMeasNumericLimit'.
Number: -2147217900
NativeError: 2812
SQLState: 42000
Reported by: Microsoft OLE DB Provider for SQL Server
Source: TSDBLog
-2147217900; User-defined error code.
Step 'Log Results to Database' of sequence 'Log To Database' in 'Database.seq'
My process for creating the database is to create a .sql file from the TestStand database configuration window. I have selected SQL Server Stored Procedure. I then build the database by running the script in the Execute SQL window of the Database viewer. I don't get any errors when creating the database or the stored procedures. I have noticed that a stored procedure, called InsertMeasNumericLimit does exist. When I rename this procedure to InsertStepMeasNumericLimit, the sequence with the multiple numeric executes without error, and my data is in the database.
Now to my questions>
1. Am I doing something wrong in my procedure to create the database schema, that would cause this?
2. Have the NI schemas or DB calls in TS been changed since 3.5 and validated?
3. Has anyone else run across this problem, and what others can I expect to encounter with the SQL server stored procedure schema?
Thanks in advance for the help,
BCEbce,
1. What you are doing is correct. There is a bug with the SQL Server Stored Procedure. Apparently
2. The schemas hasn't changed since 3.5? Were you able to go through the same process in TS 3.5 without running into this error?
3. It looks like you have found the way to solve this problem. There are a few other step types that have similar error. Specifically the IVI steps. Before the bug is fixed, you can use validate to determines whether the statement and column information for the selected schema matches the tables and columns in the database. Alternatively, you may look at the file below to find out the correct spelling of the stored procedures.
<TestStand 4.0>\Components\NI\Models\TestStandModels\Database\SQL Server Create Stored Proc Result Tables.sql
Regards,
Song Du
Systems Software
National Instruments R&D -
Stored Procedure for Accounts Receivable
Hi. First off, apologies in advance if I have put this question into the wrong topic. Secondly, I first saw SAP 3 weeks ago when I stared my new job and have had no training so please bear with me if some of what I ask doesn't make much sense.
OK, the issue is this. In SAP B1, there is a built in Report called "Customer Receivables Aging" which allows you to see Customer Receivable Accounts by age (e.g 0-30, 31-60, 61-90, 90+) and so on. The problem with the built in report is that it doesn't show all the fields I want - it only shows the Customer Name, balance, and then the aging balances. I want to be able to see things like the customer's contact details, etc. I know this makes no sense because the whole point of the report is to be able to drill down into the different rows, but this report needs to be issued in printed form, hence the need for the extra fields.
Since I can't seen any way from within SAP to change the fields returned by this report, I thought I'd have a stab at writing my own SQL to select out the same data along with the extra fields I wanted. That's when the problems began...try as I might, I cannot get my figures to tally with the SAP Report.
They are almost correct, but not quite. I am sure that I am missing a selection or some other element of the logic that B1 uses to create the built in report.
If you want, I can post the SQL I'm using....I'm not an SQL guru by any means, but I do know my way around it; the biggest problem I have is that I cannot find any documentation as to the 4 letter tables that SAP uses and their relationships except on the most basic level (e.g ORIN is Open Return Invoice [maybe])
Then I thought maybe it might be possible to edit that report section in B1 using the SDK. That would be a better solution as I would not have to 'reinvent the wheel', I can just SELECT an extra field or three to include in the report.
So my question is
->Does anyone have a stored procedure for SQL Server that can replicate correctly the SAP B1 "Customer Receivable Aging", even just the process SAP uses to gather this data would be good.
OR
is it possible to edit this report in SAP to put in the extra fields I want.
Or, am I totally barking up the wrong tree? Thanks in advance, I know this is a long post.Hi Stephen,
There should be a print layout attached to the on-screen report. This can be altered to show the additional fields you want without resorting to SDK or SQL development.
When you have the Customer Receivables Ageing report open on screen, choose Tools-Print Layout Designer or click on the Print Layout Designer icon on the toolbar. When prompted, choose the layout you wish to edit and you'll be taken to the layout design. In the layout, you can add additional fields and should be able to add most business partner fields. As the report is set to portrait by default, I recommend changing it to landscape so you have lots more space to add the extra fields you want. This report writer is fairly intuitive, if a little basic.
You will need to save this new report design, set it to be the default layout and then when you select to print the Customer Receivables Ageing report (ie Print Preview or Print) you will see the new report.
Hope this helps,
Owen -
Stored Procedure For Web Service in Visual Composer 7.1
Hello,
I want to use stored procedure for Webservice in Visual Composer 7.1
I can find this Web service but not supported. ( ex) prcreleased_test - Not supported )
Log.
Message: Error in connection - Can' t execute Web service.
Date: 2008-07-01
Time: 16:41:43:906
Category: com.sap.tc.webdynpro.progmodel.generation.DelegatingComponent
Location: com.sap.tc.webdynpro.progmodel.generation.DelegatingComponent.processExecution:
Application: sap.com/test~kmshim_wf_impl
Thread: HTTP Worker [1]
Data Source: j2ee\cluster\server0\log\defaultTrace_00.trc
Correlator ID: 240496500000034715
Argument Objects:
Arguments:
DSR Component: n.a.
DSR Transaction: cb4b3560473711dd9fb4001e4f3b8fcb
Log2
Message: Stopped further execution since the interpreter is unusable
Date: 2008-07-01
Time: 16:41:43:906
Category: com.sap.tc.webdynpro.progmodel.generation.DelegatingComponent
Location: com.sap.tc.webdynpro.progmodel.generation.DelegatingComponent.XGLInterpreter
Application: sap.com/test~kmshim_wf_impl
Thread: HTTP Worker [1]
Data Source: j2ee\cluster\server0\log\defaultTrace_00.trc
Correlator ID: 240496500000034715
Argument Objects:
Arguments:
DSR Component: n.a.
DSR Transaction: cb4b3560473711dd9fb4001e4f3b8fcb '
Help me^^ plz..Hi Tanna.
Thanks for your reply^^
I create webservice that access my stored procedure.
But not supported.
http://dmp.humaxdigital.com/HumaxCmdwService/Service1.asmx?wsdl
There are two service. (Hello World - Test, prcrelease_test - Stored Procedure )
'Hello World' is supported but prcrelease_test is not supported. I can't drag to storyboard.
Our company's DB is MSSQL2005.
please help me^^ -
Stored Procedure for Crystal Reports
Hi All,
I developed this test stored procedure to see wheather we could a stored procedure for crystal reports. It compiled without any problem, but when I run it, it gives me error message. Here is the stored Procedure..
CREATE OR REPLACE PROCEDURE WOLD1SIM.TEST_PROCEDURE(
TEST_CURSOR IN OUT TEST_PACKAGE.TEST_TYPE,
TEST_PARAMETER IN TEST_TABLE.ID%TYPE)
AS
BEGIN
OPEN TEST_CURSOR FOR
SELECT *
FROM TEST_TABLE
WHERE TEST_TABLE.ID = TEST_PARAMETER;
END TEST_PROCEDURE;
And
This is the error message..
ERROR at line 2:
ORA-06550: line 2, column 1:
PLS-00201: identifier 'TEST_PROC' must be declared
ORA-06550: line 2, column 1:
PL/SQL: Statement ignored
I have created the package sucessfully.
I was wondering If any one of you can advice me where I am making the mistake.
Thank youCREATE OR REPLACE PROCEDURE WOLD1SIM.TEST_PROCEDURE(TEST_CURSOR IN OUT TEST_PACKAGE.TEST_TYPE,
TEST_PARAMETER IN TEST_TABLE.ID%TYPE)
...you have 2 parameters in your procedure WOLD1SIM.TEST_PROCEDURE(). you should also use two parameters when you execute the procedure. -
Stored Procedure for restrict to close documents
Hi,
I want to create a Stored Procedure for restrict to close sales orders for some users, because in Standard Authorizations you have one option to restrict to close, but I need that some users can close quotations and also this users can´t close sales orders. I have this query :
F @object_type='17' AND (@transaction_type='a' or @transaction_type='U' )
BEGIN
IF EXISTS (
SELECT T0.DOCENTRY FROM adoc T0 WHERE T0.[ObjType] = '17'
AND T0.[UserSign] = '1' AND T0.[DocStatus] = 'C' AND
T0.DOCENTRY= @list_of_cols_val_tab_del )
BEGIN
SELECT @Error = 1, @error_message = 'You are not permitted to close Sales Orders'
END
END
But It doesn´t work. I need help!!!
ThanksHi Jose,
You have to correct your transaction type parameters. When you perform close or cancel operations on document; the trasnsaction notification receives parameters u201CCu201D for Cancel and u201CLu201D for Close. So instead of checking add u201CAu201D or update u201CUu201D; you have to modify your transaction type filters for cancel u201CCu201D or close u201CLu201D. It will go like belowu2026
IF @object_type='17' AND (@transaction_type='C' or @transaction_type='L')
Please try above and let me know the results.
Thanks & Regards,
Nitin
Manager, SAP Business One
Greytrix
It's time to think outside the box.
Email: sap at greytrix.com | Web: www.greytrix.com
u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026
Development Partners for SAP B1 -
I created a stored procedure for send data from a source bd to the bd destination with a link between BD
But it will not work
CREATE OR REPLACE PROCEDURE archivage ( source IN VARCHAR2, destination IN VARCHAR2)
BEGIN
/ * - Prepare a cursor to select from the bd_source: * /
source_cursor: = dbms_sql.open_cursor;
DBMS_SQL.PARSE (source_cursor,
'SELECT table_name FROM dba_tables' | | source,DBMS_SQL.NATIVE);
LOOP i in source_cursor
/* Or i use this !!!!
SELECT object_name FROM dba_objects WHERE owner = 'SCOTT' AND object_type = 'TABLE'*/
DBMS_SQL.DEFINE_COLUMN (source_cursor, i);
end loop
ignorer: DBMS_SQL.EXECUTE = (source_cursor);
/ * - Prepare a cursor to insert into the destination db: * /
destination_cursor: = DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE (destination_cursor,
'INSERT INTO' | | destination | | DBMS_SQL.NATIVE);
/ * - Fetch a row from the source table and insert it into the destination table: * /
loop
if DBMS_SQL.FETCH_ROWS (source_cursor)> 0 ALORS
- Obtenir des valeurs de colonne de la ligne
DBMS_SQL.COLUMN_VALUE (source_cursor,i);
DBMS_SQL.BIND_VARIABLE (destination_cursor,i);
ignorer: DBMS_SQL.EXECUTE = (destination_cursor);
ELSE
EXIT;
End If;
END LOOP;
/*-Close cursor */
COMMIT;
DBMS_SQL.CLOSE_CURSOR (source_cursor);
DBMS_SQL.CLOSE_CURSOR (destination_cursor);
EXCEPTION
WHEN OTHERS, THEN
if
DBMS_SQL.IS_OPEN (source_cursor)then
DBMS_SQL.CLOSE_CURSOR (source_cursor);
End If;
if DBMS_SQL.IS_OPEN (destination_cursor) then
DBMS_SQL.CLOSE_CURSOR (destination_cursor);
End If;
RAISE;
END;find 10 differences ... :(
CREATE OR REPLACE PROCEDURE archivage (source IN VARCHAR2,
destination IN VARCHAR2)
IS
source_cursor INTEGER;
destination_cursor INTEGER;
ignorer INTEGER;
BEGIN
/* - Prepare a cursor to select from the bd_source: */
source_cursor := DBMS_SQL.open_cursor;
DBMS_SQL.
PARSE (source_cursor,
'SELECT table_name FROM dba_tables' || source,
DBMS_SQL.NATIVE);
FOR i IN source_cursor
LOOP
/* Or i use this !!!!
SELECT object_name FROM dba_objects WHERE owner = 'SCOTT' AND object_type = 'TABLE'*/
DBMS_SQL.DEFINE_COLUMN (source_cursor, i);
END LOOP;
ignorer := DBMS_SQL.EXECUTE (source_cursor);
/* - Prepare a cursor to insert into the destination db: */
destination_cursor := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.
PARSE (destination_cursor,
'INSERT INTO ' || destination,
DBMS_SQL.NATIVE);
/* - Fetch a row from the source table and insert it into the destination table: */
LOOP
IF DBMS_SQL.FETCH_ROWS (source_cursor) > 0
THEN
--ALORS
-- Obtenir des valeurs de colonne de la ligne
DBMS_SQL.COLUMN_VALUE (source_cursor, i);
DBMS_SQL.BIND_VARIABLE (destination_cursor, i);
ignorer := DBMS_SQL.EXECUTE (destination_cursor);
ELSE
EXIT;
END IF;
END LOOP;
/*-Close cursor */
COMMIT;
DBMS_SQL.CLOSE_CURSOR (source_cursor);
DBMS_SQL.CLOSE_CURSOR (destination_cursor);
EXCEPTION
WHEN OTHERS
THEN
IF DBMS_SQL.IS_OPEN (source_cursor)
THEN
DBMS_SQL.CLOSE_CURSOR (source_cursor);
END IF;
IF DBMS_SQL.IS_OPEN (destination_cursor)
THEN
DBMS_SQL.CLOSE_CURSOR (destination_cursor);
END IF;
RAISE;
END;
/ -
Stored Procedure for Batch Number Format and Block Duplicate Batch Number
Hi Experts !
I am new one in forum asking question.. I want Stored procedure for Batch Number Format. I want fix one Batch number format in Stored Procedure.
Example :
My Batch number format Like BATCH00001 - It should be first five digit is text format and next five is Numeric.
IF create Goods receipt PO or Goods receipt stage I create batch number like BATCH 00001 or any other number means don't add that document and also duplicated batch number also does not allowed. please give me the solutions. I am sorry for my bad english .Dear Nagarajan K.
Thanks for your replay ..
IF @transaction_type IN ('A','U') AND (@object_type = '106' )
BEGIN
set @item = LEFT( @list_of_cols_val_tab_del, CHARINDEX(CHAR(9), @list_of_cols_val_tab_del,1) - 1)
set @batch = substring(@list_of_cols_val_tab_del, len(@item)+1, (CHARINDEX(CHAR(9), @list_of_cols_val_tab_del,len(@item)+2)) - (len(@item)+1))
--set @base =( select basetype from ibt1 where batchnum = ltrim(rtrim(replace(@batch,char(9),''))))
set @count = (select count(*) from oibt quantity > 0 and where batchnum = ltrim(rtrim(replace(@batch,char(9),''))))
if @count > 1
begin
set @error = 1
set @error_message = 'Please enter different Batch Code for batch ''' + @batch + ''' for item ' + @item
select @error, @error_message
END
END
I used above Stored Procedure. here we can use one batch number for different item but i want to block one batch we should use one item and one time only after than we never use that batch number for same item and another item.
After that I want format for Batch, we should follow unique Batch number for all items. -
Stored procedure for disabling all foreign key constraints ?
hi all,
I need a stored procedure for disabling / enable all constraints in that database schema.
Create or replace procedure enable_disable_proc(status varchar2(3),schema_name varchar2(20))
---> where 'status' parameter condition should be ( YES for enable) (NO for disable)
---> 'schema_name' is a parameter where ,only this schema should be affected with this procedure..
Thanks in Advance..Hi,
Try this code
/* Formatted on 2009/07/16 08:15 (Formatter Plus v4.8.8) */
CREATE PROCEDURE enab_disab_proc (
enforce IN VARCHAR2,
current_schema IN VARCHAR2
IS
v_alter_table_sql VARCHAR2 (2000);
BEGIN
FOR rec_con IN (SELECT table_name, constraint_name
FROM user_constraints
WHERE owner = current_schema)
LOOP
IF (enforce = 'NO')
THEN
v_alter_table_sql :=
' alter table '
|| current_schema
|| '.'
|| rec_con.table_name
|| ' disable constraint '
|| rec_con.constraint_name;
ELSE
v_alter_table_sql :=
' alter table '
|| current_schema
|| '.'
|| rec_con.table_name
|| ' enable constraint '
|| rec_con.constraint_name;
END IF;
EXECUTE IMMEDIATE v_alter_table_sql;
END LOOP;
END;Edited by: Salim Chelabi on 2009-07-16 05:15 -
Using VIEW inside a stored procedure
Hi,
So I have a View designed in one file that validates someone who is authorized.
Then I have a stored procedure to display authorized stationeries created before a given date. Its takes a parameter @CreatedOn.
How can I use VIEW in my stored procedure so I can display all the authorized which are set 1 before a given date?
My VIEW:
ALTER VIEW vw_AuthorizedStationeries AS
SELECT Authorized
FROM dbo.Stationeries
WHERE Authorized = 1
And my stored procedure:
CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)ASBEGINSELECTFROMENDGO
Thanks!Try something like below, You need to replace CreatedDate column with appropriate date column in your table.
1. Alter the view to get the required date:
ALTER VIEW vw_AuthorizedStationeries AS
SELECT Authorized, CreatedDate
FROM dbo.Stationeries
WHERE Authorized = 1
2. Alter SP:
CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)
AS
BEGIN
SELECT Authorized
FROM vw_AuthorizedStationeries
WHERE CreatedDate <= @CreatedOn
END
GO
OR
You can pull required information directly from your table:
CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)
AS
BEGIN
SELECT Authorized
FROM dbo.Stationeries
WHERE CreatedDate <= @CreatedOn and Authorized = 1
END
GO
If this post answers your query, please click "Mark As Answer" or "Vote as Helpful". -
Using a stored procedure for a sender jdbc adapter
Hi all,
The requirement is to use a stored procedure, for extracting data from a oracle database.
Is it possible to do this.
If yes, what should be the source structure in this case.
Please help with the exact soln.
Thanks!!
YounusHi,
Did you check the blog pointed by Aamir?
/people/jegathees.waran/blog/2007/03/02/oracle-table-functions-and-jdbc-sender-adapter
You will need to use Oracle Functions instead of Oracle Stored Procedures. Read thru the blog and the note pointed in the blog . Think it is quite a good example.
Regards
Bhavesh -
Utilizing a java stored procedure for web services
Hello,
I am a newbie in web services and I want to learn web services by utilizing a simple procedure and making use as a web service.
I have a java stored procedure deployed in Oracle 8i database, which I am using for sending emails. I am invoking the java stored procedure in my JSP and Java classes by making a database connection and calling the procedure.
I am planning to make this a web service so that I could call this from any of my application.
Could someone give an insight how to make this a web service, albeit the utility is not very complex and my knowledge about web services is limited, I thought I could start by doing a simple program.
Any help is highly appreciated.
Thanks
PonicHi Tanna.
Thanks for your reply^^
I create webservice that access my stored procedure.
But not supported.
http://dmp.humaxdigital.com/HumaxCmdwService/Service1.asmx?wsdl
There are two service. (Hello World - Test, prcrelease_test - Stored Procedure )
'Hello World' is supported but prcrelease_test is not supported. I can't drag to storyboard.
Our company's DB is MSSQL2005.
please help me^^
Maybe you are looking for
-
How to Edit Comment Tag in DW CS3?
I would like to customize the HTML comment tag for my own preferences. I know how to edit the colors and font under Preferences, but I would like to change the whole tag and add some more spaces and dashes. How do I edit this in DW CS3? Thanks..
-
Hello everyone, I'm sure that this problem has been addressed before but searching did not bring an answer. Is there an answer? When I run my iPod Touch 5g with iOS 6.0 using my AppleTV, with latest software, I cannot see an Airplay icon anywhere whe
-
Modification in WAD (BI70)
hi experts, i use wad to show my report, i want to change the value in a field to another text, for example, the table is: field1 field2 field3 a1 1 b1 a2 0 b2 a3 1 b3 i want to change it to display field1
-
Is there a way to have stack numbers show up in filmstrip mode?
I use filmstrip mode more than grid mode because I like the larger image. However, stack numbers don't show up (for me) in film strip mode. When I view stacks in Bridge, the number is very prevalent and easily seen in filmstrip mode. Am I missing a
-
hi, i was trying to download the OBIEE 11g Sample from this link : http://www.oracle.com/technetwork/middleware/bi-foundation/obiee-samples-167534.html but cannot download it. is it down or something? anybody who can point me to the correct location