Referencing tables in procedures
If I run the following, I get no compile errors, and I get the output I'd expect:
1 declare
2 cursor c1 is select ename, deptno from scott.emp;
3 iCount number;
4 begin
5 icount:=0;
6 for out_rec in c1
7 loop
8 icount:=icount+1;
9 dbms_output.put_line(to_char(icount));
10 end loop;
11* end;
When I try to convert this to a procedure, and create it in a schema other than the SCOTT schema, I get compile errors:
1 create or replace procedure facet.chuck_test
2 authid current_user
3 as
4 cursor c1 is select ename, deptno from scott.emp;
5 iCount number;
6 begin
7 icount:=0;
8 for out_rec in c1
9 loop
10 icount:=icount+1;
11 dbms_output.put_line(to_char(icount));
12 end loop;
13* end;
14 /
Warning: Procedure created with compilation errors.
SQL> show errors
Errors for PROCEDURE FACET.CHUCK_TEST:
LINE/COL ERROR
4/14 PL/SQL: SQL Statement ignored
4/46 PL/SQL: ORA-00942: table or view does not exist
Why would this happen, and is there a way around it?
Thanks,
Chuck
Ahhh, I see. It's not the creator of the procedure, but the ultimate owner which requires the rights to the tables mentioned in the procedure.
So someone with CREATE ANY PROCEDURE rights does not need explicit rights to the underlying tables necessarily, just the schema owner in which the procedure will reside.
Thanks very much,
Chuck
Similar Messages
-
Tsql cascade Veiw referencing tables
Hi,
I want to create a recursive stroed proc which allows to return the list of referencing tables ( even in a cascade Views)
for example
GO
CREATE VIEW [dbo].[V2]
AS
select * from [dbo].[V1]
GO
CREATE VIEW [dbo].[V1]
AS
select * from dwh.TestTable1
UNION ALL
select * from dwh.TestTable2
GO
exec dbo.UspGetRefTables (V2)
result : dwh.TestTable1 / dwh.TestTable2
can you help me plzPreviously I had same requirement like this to find the dependent objects... So i have create this stored procedure after long struggle... Hope this will helps you. Just Pass Parameter as your view name... it will display the dependent
objects...
/****** Object: StoredProcedure [dbo].[P_GET_DEPENDENT_OBJECTS] Script Date: 07/18/2014 02:49:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_GET_DEPENDENT_OBJECTS]
@objName VARCHAR(255)
AS
BEGIN
CREATE TABLE #tmpDependency
row_id INT IDENTITY(1,1) NOT NULL,
referenced_database_name VARCHAR(500),
referenced_schema_name VARCHAR(500),
referenced_entity_name VARCHAR(500)
;WITH cte
AS
SELECT referenced_database_name, referenced_schema_name, referenced_entity_name FROM sys.sql_expression_dependencies
WHERE referencing_id = OBJECT_ID(@objName)
UNION ALL
SELECT dp.referenced_database_name, dp.referenced_schema_name, dp.referenced_entity_name
FROM sys.sql_expression_dependencies dp
INNER JOIN cte ON referencing_id = OBJECT_ID(cte.referenced_entity_name)
INSERT INTO #tmpDependency
SELECT DISTINCT * FROM cte
DECLARE @TotalRows INT
DECLARE @Counter INT = 1
SELECT @TotalRows = MAX(row_id) FROM #tmpDependency
DECLARE @fullObjName VARCHAR(1000)
DECLARE @DBName VARCHAR(500)
DECLARE @sql VARCHAR(max)
WHILE @Counter <=@TotalRows
BEGIN
SELECT @fullObjName = referenced_database_name + '.' + referenced_schema_name + '.' + referenced_entity_name,
@DBName = referenced_database_name
FROM #tmpDependency WHERE row_id = @Counter
IF @DBName IS NOT NULL AND @fullObjName IS NOT NULL
BEGIN
SET @sql='
WITH cte
AS
SELECT '''+ @DBName +''' referenced_database_name, referenced_schema_name, referenced_entity_name
FROM [' + @DBName + '].sys.sql_expression_dependencies
WHERE referencing_id = OBJECT_ID('''+ @fullObjName +''')
UNION ALL
SELECT '''+ @DBName +''' referenced_database_name, dp.referenced_schema_name, dp.referenced_entity_name
FROM [' + @DBName + '].sys.sql_expression_dependencies dp
INNER JOIN cte ON referencing_id = OBJECT_ID(''['+ @DBName +'].dbo.''+cte.referenced_entity_name)
INSERT INTO #tmpDependency
SELECT DISTINCT * FROM cte
EXEC (@sql)
--PRINT @sql
END
SET @Counter+=1
END
SELECT row_id, referenced_database_name, referenced_schema_name, referenced_entity_name
FROM #tmpDependency
DROP TABLE #tmpDependency
END
GO
Venkat G -
How to update the data in sqlserver table using procedure in biztalkserver
Hi,
Please can any one answer this below question
how to update the data in sqlserver table using procedure in biztalkserver
while am using executescalar,typedprocedure getting some warning
Warning:The adapter failed to transmit message going to send port "SendtoSql1" with URL "mssql://nal126//MU_Stage2?". It will be retransmitted after the retry interval specified for this Send Port. Details
Please send me asap....
Thanks...Hi Messip,
A detailed error would have helped us to answer you more appropriately but
You can follow the post which has step by step instructions, to understand how to use Stored Procedure:
http://tech-findings.blogspot.in/2013/07/insert-records-in-sql-server-using-wcf.html
Maheshkumar
S Tiwari|User
Page|Blog|BizTalk
2013: Inserting RawXML (Whole Incoming XML Message) in SQL database -
Best practice: self referencing table
Hallo,
I want to load a self referencing table to my enterprise area in the dwh. I am not sure how to do this. What if a record references to another record which is inserted later in the same etl process? There is now way to sort, because it is possible that record a references to record b and record b references to record a. Disabling the fk constraint is not a good idea, because this doesn't prevent that invalid references will be loaded? I am thinking of building two mappings, one without the self referencing column and the other only with it, but that would cause approx. twice as much running time. Any other solutions?
Regards,
TorstenMind sharing the solution? Would be interested to hear your solution (high level).
Jean-Pierre -
I have a txt file which has all the sqltext in it separated by semi colon .Then I try to run a query one by one like this-
var conn = new SqlCeConnection(ConnectionString);
conn.Open();
var cmdArray = Regex.Split(sqlText, ";");
var cmd = new SqlCeCommand(null, conn);
foreach (var text in cmdArray)
cmd.CommandText = text;
if (!text.Equals(string.Empty))
cmd.ExecuteNonQuery();
else
break;
conn.Close();
I get the error {"The referenced table must have a primary or candidate key. [ FK Name = ForeignKeyB_Details ]"}
here is part of my txt file-
CREATE TABLE A
PrimaryId nvarchar(10) NOT NULL REFERENCES C(PrimaryId),
UserId nvarchar(20) NOT NULL,
FirstName nvarchar(30) NOT NULL,
MiddleInitial nvarchar(1) NULL,
LastName nvarchar(30) NOT NULL,
MobileNumber nvarchar(20) NULL,
PhoneNumber nvarchar(10) NOT NULL,
PhoneExtension nvarchar(6) NULL,
FaxNumber nvarchar(20) NULL,
EmailAddress nvarchar(50) NOT NULL,
CONSTRAINT PrimaryKeyA PRIMARY KEY(PrimaryId, UserId)
CREATE TABLE B(
MarketId int NOT NULL references E(MarketId),
UserId nvarchar(20) NOT NULL,
UserFirstName nvarchar(30) NOT NULL,
UserMiddleInitial nvarchar(1) NOT NULL,
UserLastName nvarchar(30) NOT NULL,
PhoneNbr nvarchar(10) NOT NULL,
Extension nvarchar(6) NOT NULL,
FaxNbr nvarchar(20) NOT NULL,
Email nvarchar(50) NOT NULL,
ShortName nvarchar(10) NOT NULL,
PublicIdFlag nvarchar(6) NOT NULL references D(publicId),
CONSTRAINT PrimaryKeyB PRIMARY KEY( MarketId, UserId)
ALTER TABLE B ADD CONSTRAINT ForeignKeyB_Details FOREIGN KEY(UserId, UserFirstName, UserMiddleInitial, UserLastName, PhoneNbr, Extension, FaxNbr, Email) REFERENCES A(UserId, FirstName, MiddleInitial, LastName, PhoneNumber, PhoneExtension, FaxNumber, EmailAddress);Hi,
Foreign key columns are frequently used in join criteria when the data from related tables is combined in queries by matching the column or columns in the FOREIGN KEY constraint of one table with the primary or unique key column or columns in the other table.
For more information about the foreign key constraint, please refer to this link:
http://msdn.microsoft.com/en-us/library/ms175464.aspx
Here is a similar thread for your reference:
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/5a71948b-dfb1-46a5-8688-ccab9317e959/error-message-the-referenced-table-must-have-a-primary-or-candidate-key-fk-name-fktblatblb-?forum=sqlce
Thanks.
Tracy Cai
TechNet Community Support -
XSD from Database table/view/procedure
Hi all,
Does anyone know of a tool or framework which enables generation of XSD's out of a Database table/view/procedure?Hi Naval,
It depends on whether you created a BOL model for your Z-table or not. If you don't have a BOL model, then all you can do is use a value node. In that case, you need to add attribute that you want to show in the value node, read the values from the z-table and add them to the node. You can create method(s) in view implementation class to read values from database table and fill the context node. From where these methods should then be called will depend on your requirement.
Regards,
Shiromani -
List of unused tables and procedures
Hi,
I am in the task of clean up of tables.
I need to find the list unused tables and procedures.
Is there any way where i can find when was the last time the table queried?
Also, Can you please give sql query to find the list of unused tables and procedures.
Appreciate your response.
Thanks...There is not a definitive way to complete this task. This becomes especially complicated if you have SQL / PL/SQL embedded in your applications external to the database. You could start looking at DBA_DEPENDENCIES, and that will at least give you a start to identifying objects that might not be used in the database.
Another possibility is implementing auditing on suspected objects to see if there is any activity. You'll need to determine though if you have any business processes that have a long cycle (quarter, annually, etc) to ensure you aren't dropping an object that is actually used. -
Self Referencing Tables...
I have a self-referencing table (a Topic can be a response to another Topic) and read one of Frank Nimphius' blogs on this subject, posted on the ADF board for advise. As a result I created the read-only ViewObject to set up this tree relationship and set it to be exposed to the App Module.
Do I need to do more to it than that for JHeadstart to generate the right page defs? Any advise on setting this up cleanly? My user interface must present a page in which users can post new Topics, view topics in a heirarchy (response thread, like in this forum) and respond to Topics or responses. A response is a Topic that references another (parent) Topic. I have to believe this has been done before a million times but am not sure myself how to do it.
Thanks!Steve,
I've read the section and am getting this error:
(oracle.jbo.SQLStmtException) JBO-27122: SQL error during statement preparation. Statement: SELECT Topic.SUBJECT, Topic.ROW_ID, Status.STATUS_CHOICE, Status.ROW_ID AS ROW_ID11, Topic.CREATED_BY, Topic.CREATION_DATE, Response.SUBJECT AS SUBJECT1, Response.CREATION_DATE AS CREATION_DATE1, Response.ROW_ID AS ROW_ID12, Response.CREATED_BY AS CREATED_BY1 FROM TOPIC Topic, RESPONSE Response, STATUS Status WHERE (Topic.ROW_ID = Response.MASTER_ID (+)) AND (Topic.TOPIC_STATUS_ID = Status.ROW_ID) CONNECT BY PRIOR Topic.ROW_ID = Response.MASTER_ID (+) OR Response.ROW_ID = Response.MASTER_ID (+) ORDER BY SUBJECT,CREATION_DATE1
----- LEVEL 1: DETAIL 0 -----
(java.sql.SQLException) ORA-01436: CONNECT BY loop in user data
I have a table called Topic with a Pk called ROW_ID and another table called Response with a Pk called ROW_ID and an Fk called MASTER_ID. A Topic can have many Responses and a Response can also have many Responses. The parent ID could point to either a Topic or a Response. There's no limit on how many levels this can continue. There's a Status table also from which I want to show the text value of the Status for the Topic row (not the Status ROW_ID)
I have a View Object including entities: Topic, Response & Status
I tried the SQL query as:
(Topic.ROW_ID = Response.MASTER_ID (+)) AND (Topic.TOPIC_STATUS_ID = Status.ROW_ID) CONNECT BY PRIOR Topic.ROW_ID = Response.MASTER_ID (+) OR Response.ROW_ID = Response.MASTER_ID (+)
Hoping to have this result:
Topic A
-Response A (to Topic A)
--Response B (to A)
---Response C (to B)
-Response D (to Topic A)
Topic B
Topic C
What am I doing wrong?
Is there a guide that explains better using JHeadstart with JDeveloper (rather than Oracle Designer, which we don't use)? The developer's guide for JHeadstart is hard to translate for use with JDeveloper...
Thanks!! -
How to build query to get tree architecture of self referencing table
Dear all,
I have the following table design :
This is a self referencing table representing a set of SubCategories which can have parent sub categories or not. I did not show here the Category table.
If the Subcategory has the ParentSubCategory ID = null, then this is a root subcategory otherwise it is a child of a parent sub category.
What I am looking for is the easy way to display the structure level by ProductCategoryID ?
Thanks for helpsyou can use a recursive logic based on CTE for that
something like this would be enough
;WITH ProdSubCat_Hiererchy
AS
SELECT psc.ProductSubCategoryID,c.CategoryName,psc.ParentSubCategoryID, psc.Name,CAST(psc.Name AS varchar(max)) AS [Path],1 AS [level]
FROM ProductSubCategory psc
INNER JOIN Category c
ON c.CategoryID = psc.ProductCategoryID
WHERE psc.ParentSubCategoryID IS NULL
UNION ALL
SELECT psc.ProductSubCategoryID,c.CategoryName,psc.ParentSubCategoryID, psc.Name,CAST(psch.[Path] + '/' + psc.Name AS varchar(max)) AS [Path],psch.[level] + 1
FROM ProductSubCategory psc
INNER JOIN Category c
ON c.CategoryID = psc.ProductCategoryID
INNER JOIN ProdSubCat_Hiererchy psch
ON psch.ProductSubCategoryID = psc.ParentSubCategoryID
SELECT *
FROM ProdSubCat_Hiererchy
ORDER BY LEFT([Path],CHARINDEX('/',[Path]+'/')-1),[Level]
OPTION (MAXRECURSION 0)
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
JPA: How to initialise an entity for a self-referencing table?
I am working on a project that requires a self-referencing table:
mysql> show create table attributes\G
*************************** 1. row ***************************
Table: attributes
Create Table: CREATE TABLE `attributes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`parent` int(11) DEFAULT NULL,
`type` int(11) DEFAULT NULL,
`name` varchar(128) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `parent` (`parent`),
KEY `type` (`type`),
CONSTRAINT `attributes_ibfk_1` FOREIGN KEY (`parent`) REFERENCES `attributes` (`id`),
CONSTRAINT `attributes_ibfk_2` FOREIGN KEY (`type`) REFERENCES `attributes` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=latin1
I used NetBeans to generate an entity class from the table:
@Entity
@Table(name = "attributes")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Attributes.findAll", query = "SELECT a FROM Attributes a"),
@NamedQuery(name = "Attributes.findById", query = "SELECT a FROM Attributes a WHERE a.id = :id"),
@NamedQuery(name = "Attributes.findByName", query = "SELECT a FROM Attributes a WHERE a.name = :name")})
public class Attributes implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Size(max = 128)
@Column(name = "name")
private String name;
@OneToMany(mappedBy = "parent")
private Collection<Attributes> attributesCollection;
@JoinColumn(name = "parent", referencedColumnName = "id")
@ManyToOne
private Attributes parent;
@OneToMany(mappedBy = "type")
private Collection<Attributes> attributesCollection1;
@JoinColumn(name = "type", referencedColumnName = "id")
@ManyToOne
private Attributes type;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "attributes")
private Collection<ItemAttributes> itemAttributesCollection;
@OneToMany(mappedBy = "ivalue")
private Collection<ItemAttributes> itemAttributesCollection1;
But how can I write a constructor for this entity? The auto-generated code gets around the issue by doing nothing; the constructor is empty. I can't help thinking that if I set the parent and type references to anything with new Attributes(), then it will recurse out of control. What else can/shall I do? I know how to rewrite it to not use the entity relations, but I'd prefer to make it work.Cymae wrote:
I don't want to call the hash table creation method because from what i understand about interfaces the idea is that your main method doesnt know the table is actually a hash table...is that right?That's not exactly the idea. The idea to use the interface as the type instead of the implementation, is that your class probably doesn't need to know the full type. This makes it easy to change the implementation of the interface if needed. However, somebody at some point has to create the concrete object, a HashTable.
Basically, an interface describes a behavior, and a class that implements an interface decides how to actually perform this behavior. It is obviously impossible to perform the behavior if you are not told how to perform it.
Table table = new HashTable() is the correct way to do it. This means that if you ever need you Table implementation to change, the only thing you need to change in your whole class is this line. For example you might want Table table = new FileTable(). -
Query output help: Display self-referencing table
Hello,
I'm trying to display in a cfoutput a self-referencing table.
I'll start by showing some of the data in the table.
There are only 3 columns, pl_id (auto increment id pri-key),
pl_name and pl_parent_id (it's 0 if it's a parent, otherwise it's
the pl_id value for the parent).
pl_id pl_name pl_parent_id
1 Country 0
2 Food 0
3 US 1
4 Japan 1
5 Hamburger 2
6 Idaho 3
7 Florida 3
8 Cheese 2
What I'm trying to output is something like this:
Country - US - Idaho (3 levels here) or
Country - US - Florida (or if there are only 2 levels like
the next line)
Food - Cheese
I've tried using a cfoutput with a cfloop as well as grouping
but not having any luck. Could someone clear my clouded head on
this one?
thanks much,
Joe
ps. Adobe should really use a fixed width font for these
forums, it's impossible to line up table info!JoeNH2k wrote:
> It would be nice if it were that easy, I (of course)
tried that. The sort order
> of the query doesn't matter. The data is not sorted once
the function runs. The
> sort has to come after the select box is populated by
the function. I need to
> get the data at this point and sort it, probably somehow
creating a structure
> or array from this data and sorting that(?).
>
<cfset myArr = ArrayNew(1)>
<cfloop query="qryGetAll">
<cfset temp = ArrayAppend(myArr,
"#getNameWithParent(pl_id)#")>
</cfloop>
<cfset ArraySort(myArr, "textnocase", "asc")>
<cfset myList = ArrayToList(myArr, ",")>
then loop through myList to populate your <select>...
how about that?
Azadi Saryev
Sabai-dee.com
Vientiane, Laos
http://www.sabai-dee.com -
Self referencing table many to many relationship
I am in a bit of a logic pickle, and I was wondering if someone could help me out.
I have a table in a database I am designing called document, it holds information on surprisingly on documents in our DMS.
I want to create the notion that a document can have multiple related documents, and those documents can be the related documents for many documents.
So it is a self referencing table, I have done these before so no big deal, but this time is a many to many relation, it wasnt before.
Maybe something like:
document
docid (pk)
related_doc
docid (pk) (fk to document.docid)
related_docid (pk) fk to document.docid)
Does anyone have any experience with this or any advise I might find sueful?
Thanks!A junction table can be used to resolve a many-to-many relationship as is in your example. There are two PK/FK relationships between document and related_document table. This will prevent denormalization of data.
The other option could be to have just one table with two columns (parent_doc_id and child_doc_id) and have a PK constraint on both the columns - just like bill-of-materials.
But I think the approach you have in your posting will work well.
Shakti
http://www.impact-sol.com
Developers of Guggi Oracle - Tool for DBAs and Developers -
Self referencing table and SQL statement
In my database, I have a self-referencing table, the table itself is for projects, and it allows users to get a hierarchical view of the company.
Here is the SQL (modifier is the term we use for project code, BBCI is the top project)
SELECT
modifier, modifierDescription, level
FROM
modifier
WHERE
level <= 2
CONNECT BY PRIOR
modifier = parentModifier
START WITH modifier = 'BBCI'
ORDER BY level
That perticular query gets the first two levels in the structure. I use this information to produce a tree structure in a web app.
But users have requested it would be good if in the tree structure is showed an + or - depending on whether there were anymore children under each parent, or better still the number of children under it, for example
BBCI
+ BBCI_CHILD
+ BBCI_CHILD2
- BBCI_CHILD3
or
BBCI
+ BBCI_CHILD (3 projects underneath)
+ BBCI_CHILD2 (2 projects underneath)
- BBCI_CHILD3 (0 projects underneath)
I am really stumped on this issue, and I am sure there is a way to do this in the web app, so for example do a query for each child node to see how many child nodes are underneath, but I figure it would be a lot tidier and faster if I could do it from a single SQL statement. Unfortunately I have tried to do this and am very much stuck.
If you need more information please let me know
Thanks!
JonYou may be able to do this using analytical functions but it depends on the Oracle version you are using. It can also be done with standard SQL - you just need to count the number of child rows for each modifier/project first and supply that list as an in-line view:
SELECT decode(modifier,'X',null,decode(child_rows,null,'-','+')),
m.modifier,
decode(modifier,'X',null,'('||nvl(cq.child_rows,0)||' projects underneath)')
FROM modifier m,
(select parentModifier,
count(parentModifier) child_rows
from modifier
where parentModifier is not null
group by parentModifier) cq
WHERE m.modifier=cq.parentModifier(+)
AND level <= 2
CONNECT BY PRIOR
m.modifier = m.parentModifier
START WITH modifier = 'X'
ORDER BY level, modifier;
which gives you something like...
D MODIFIER DECODE(MODIFIER,'X',NULL
X
- Y1 (0 projects underneath)
+ Y2 (2 projects underneath)
+ Y3 (3 projects underneath)
The decode stuff is just to show you the result, you can format the output in your calling code. Just extend the columns to include everything you want, modifierDescription etc..
Hope this helps. -
Self referencing table and contraint
Hi,
I have a self referencing table, used to store information on projects in an organization. There is a pimary key (modifier) and a foreign key to the modifier field (parentModifier)
Note: (modifier = project in the organization)
Basically, the parentModifier cannot be equal to the modifier in the same table, or equal to any of its children, otehrwise you get wierd recursive relationships. Its like saying you cannot be your own father, or one of your children cannot be your father. To get a list of the modifiers the parentModifier cannot be, the following statement can be used:
select
modifier
from
modifier
where
modifier = 'A'
and
level >= 1
connect by prior
modifier = parentModifier
start with
modifier = 'A'
order by
level;
So, now, I guess the way to do this is perform that query in a trigger before each row is being updated, so the pseudo code would be something like:
BEFORE UPDATE ON modifier
FOR EACH ROW
DECLARE
modifierToChange varchar2(255);
modifierList ???;
BEGIN
select
modifier
into
modifierList
from
modifier
where
modifier = 'A'
and
level >= 1
connect by prior
modifier = parentModifier
start with
modifier = 'A'
order by
level;
if modifierToChange in modifierList
return error
else
execute query
end if
END
As you can see my PL/SQL is limitied. At the moment I can handle this at the application layer (in php), but if the admin going to SQL Plus and starts to fiddle, they can easy break the system, by setting an invalid relationship.
I was wondeirng, if anyone could give me some help or advice, it would be fantastic,
Thanks!Having a unique key on mod_id would be enough to make sure the same element is not in the structure more than once. By allowing it to happed you will have all the descendants of the dup element following it when you walk the tree.
Let's say this is the intended behavior.
Consider the following test scenario:
create table modifier (
mod_id varchar2(10),
parent_mod_id varchar2(10)
insert into modifier (mod_id, parent_mod_id) values ('a', null);
insert into modifier (mod_id, parent_mod_id) values ('aa', 'a');
insert into modifier (mod_id, parent_mod_id) values ('ab', 'a');
insert into modifier (mod_id, parent_mod_id) values ('ac', 'a');
insert into modifier (mod_id, parent_mod_id) values ('aaa', 'aa');
insert into modifier (mod_id, parent_mod_id) values ('aab', 'aa');
insert into modifier (mod_id, parent_mod_id) values ('aac', 'aa');
insert into modifier (mod_id, parent_mod_id) values ('aba', 'ab');
insert into modifier (mod_id, parent_mod_id) values ('abb', 'ab');
insert into modifier (mod_id, parent_mod_id) values ('abc', 'ab');
insert into modifier (mod_id, parent_mod_id) values ('aca', 'ac');
insert into modifier (mod_id, parent_mod_id) values ('acb', 'ac');
insert into modifier (mod_id, parent_mod_id) values ('acc', 'ac');
insert into modifier (mod_id, parent_mod_id) values ('b', null);
insert into modifier (mod_id, parent_mod_id) values ('ba', 'b');
insert into modifier (mod_id, parent_mod_id) values ('bb', 'b');
insert into modifier (mod_id, parent_mod_id) values ('bc', 'b');
insert into modifier (mod_id, parent_mod_id) values ('baa', 'ba');
insert into modifier (mod_id, parent_mod_id) values ('bab', 'ba');
insert into modifier (mod_id, parent_mod_id) values ('bac', 'ba');
insert into modifier (mod_id, parent_mod_id) values ('bba', 'bb');
insert into modifier (mod_id, parent_mod_id) values ('bbb', 'bb');
insert into modifier (mod_id, parent_mod_id) values ('bbc', 'bb');
insert into modifier (mod_id, parent_mod_id) values ('bca', 'bc');
insert into modifier (mod_id, parent_mod_id) values ('bcb', 'bc');
insert into modifier (mod_id, parent_mod_id) values ('bcc', 'bc');
commit;
SQL> select lpad(' ', 2 * (level - 1)) || mod_id item
2 from modifier
3 start with parent_mod_id is null
4 connect by prior mod_id = parent_mod_id;
ITEM
a
aa
aaa
aab
aac
ab
aba
abb
abc
ac
aca
acb
acc
b
ba
baa
bab
bac
bb
bba
bbb
bbc
bc
bca
bcb
bcc
26 rows selected
Create a function to verify if a mod_id already is parent_mod_id's ascendant or descendant:
create or replace function exists_in_parents_branch
i_mod_id in varchar2
,i_parent_mod_id in varchar2
) return boolean is
pragma autonomous_transaction;
v_dummy varchar2(10);
begin
select mod_id
into v_dummy
from (select mod_id
from modifier
where mod_id = i_mod_id
connect by prior mod_id = parent_mod_id
start with mod_id = i_parent_mod_id
union
select mod_id
from modifier
where mod_id = i_mod_id
connect by prior parent_mod_id = mod_id
start with mod_id = i_parent_mod_id);
return true;
exception
when no_data_found then
return false;
end exists_in_parents_branch;
Create a trigger that calls the function above for every insert and update
create or replace trigger biu_modifier
before insert or update on modifier
for each row
begin
if exists_in_parents_branch(:new.mod_id, :new.parent_mod_id) then
raise_application_error(-20000, 'Cannot insert or update because of recursive relationship.');
end if;
end biu_modifier;
You are all set.
Here is a statement that should fail:
SQL> insert into modifier (mod_id, parent_mod_id) values ('bcc', 'b');
insert into modifier (mod_id, parent_mod_id) values ('bcc', 'b')
ERROR at line 1:
ORA-20000: Cannot insert or update because of recursive relationship.
ORA-06512: at "RC.BIU_MODIFIER", line 3
ORA-04088: error during execution of trigger 'RC.BIU_MODIFIER'
Here is a statement that should succeed:
SQL> insert into modifier (mod_id, parent_mod_id) values ('aaaa','aaa');
1 row created. -
Table 2 Cel A1 Referencing Table 1 Cel A1
Hi,
I must be missing something...
I have 2 tables set up on the same sheet in Numbers 09. I set A1 in Table 2 to equal A1 in Table 1. Now if I add a row above Row A in Table 1, my A1 in Table 2 = Table 1 A2. I've tried playing with the Relative and Absolute selections in the function to no avail. How do I specify that a cel in a table always equals the same cel in another table no matter what is done to the referenced table?
Thanks!You use INDIRECT.
Table 2 A1 = INDIRECT("Table 1::A1")
or if you want to make it easier to fill in an entire row
A1 =INDIRECT(ADDRESS(ROW(),COLUMN(),,,"Table 1"))
You can take this second formula and fill it across/down. The first formula you would have to edit for each cell.
Maybe you are looking for
-
How to get the text of a multiple-choice response
If call report-quiz-interactions, i got only the response value. <row display-seq="1" transcript-id="2007071200" interaction-id="2007027923" sco-id="2007071193" score="0"> <name>jazz doe</name> <sco-name>Thursday Meeting</sco-name> <date-created>200
-
Thunderbolt to large display port monitor
I have a 27" HP monitor (2560 x 1440) with a display port connection. It is not the mini display port, but the larger displayport. (image below) I am wondering if cables exist to connect a thunderbolt MacBook Pro to this monitor? http://news.hopeindu
-
I just bought a 2.5 GHz macbook pro recently so I am still new to this. I'm switching from HP. My problem is this: I have a program "crack dat pat" that's locked onto my HP HD. Thus, I can't reformat the HD or transfer the program file onto another H
-
If I consider heap size, should I follow component binding or Value binding
Hi, I have an Web application my pages gets change rapidly in run time(components get disable and invisible at run-time depends on user input), So in that case which kind of binding approach I have to follow if I consider Heap memory of run time.
-
Hi experts, I want to insert a field for the header part of the ME21n. So I choose the MM06E005 enhancement and I created a project in smod. then I create a field in CI_EKKODB include table , and I double click in 0101 screen and insert that field in