Create a View with a GTT.
Hi.
I would like to create a view for a GTT, but I create the GTT on my application, when I try to create the view it says the GTT doesn't exist (I create the view before on my Data Base), this view has trigger instead of insert, and when I am trying to insert rows to the view the trigger fire and insert the same rows on my GTT under this for each session created:
insert into GTT (PK, value1) values (:new.PK, new.value1);
exception when dup_val_on_index then
update GTT set value1= :new.value1
where pk= :new.PK;
What can I do???
Thanks.
Following our Re: Global Temporary Table???? from yesterday evening (at least for me that was even night...).
Why not give us your tries ? That would be simplest to help you.
Anyway, here below a working example :
SQL> create global temporary table gtt_emp as select * from emp;
Table created.
SQL> alter table gtt_emp add constraint gtt_emp_pk primary key (empno);
Table altered.
SQL> create or replace view vw_gtt_emp as select * from gtt_emp;
View created.
SQL> create or replace trigger trg_vw_gtt_emp
2 instead of insert on vw_gtt_emp
3 for each row
4 begin
5 insert into gtt_emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
6 values (:new.EMPNO, :new.ENAME, :new.JOB, :new.MGR, :new.HIREDATE, :new.SAL, :new.COMM, :new.DEPTNO);
7 exception when dup_val_on_index then
8 update gtt_emp set ENAME =:new.ENAME,
9 JOB =:new.JOB,
10 MGR =:new.MGR,
11 HIREDATE=:new.HIREDATE,
12 SAL =:new.SAL,
13 COMM =:new.COMM,
14 DEPTNO =:new.DEPTNO
15 where EMPNO = :new.EMPNO;
16 end;
17 /
Trigger created.
SQL> show err
No errors.
SQL>
SQL> insert into vw_gtt_emp select * from emp where empno=7369;
1 row created.
SQL> select * from vw_gtt_emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17/12/80 800 20
SQL> insert into vw_gtt_emp select empno,'TOTO',job,mgr,hiredate,sal,comm,deptno from emp where empno=7369;
1 row created.
SQL> select * from vw_gtt_emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 TOTO CLERK 7902 17/12/80 800 20
SQL> Nicolas.
Similar Messages
-
How can i create a view with jdevlopper 10132
hi,
i want to know how to create a view with JDeveloper 10132.
thanksSorry, but I had to jump in here.
7rouz - you've certainly violated the 10 commandments for posting here...
Do you want to:
1). Create a database view directly in the database
2). Model a database view using the database modeller
3). Create an ADF BC View Object
4). Create some type of visual object (web page, Swing panel)
5). something else.
Your question is too ambiguous to yield an answer, unless by luck.
Regards,
John -
How to create a view with parameter?
who can tell me hwo to create a view with
parameters just like a cursor?Hi,
This is not possible in Oracle. What u can do is create the view without the where clasue and supply the where clause at runtime.
Hope this helps...
Regards,
Ganesh R -
Need help in creating a view with Encryption for hiding the code used by the multiple users
Hi,
Can anyone help me out in creating view with encryption data to hide the stored procedure logic with other users.
I have create a stored procedure with encryted view but while running this manually temporary views are getting created, therefore the problem is if there are 500 entries then 500 temp views will get created.
Any solution to aviod creating temporary views, please refer my code below
USE [etl_validation]
GO
/****** Object: StoredProcedure [dbo].[Pr_DBAccess_mod] Script Date: 05/23/2014 12:53:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Pr_DBAccess_mod](@ETL_CONFIG_ID INT)
AS
BEGIN
DECLARE @openquery NVARCHAR(MAX),
@DATABASENAME NVARCHAR(100),
@HIERNAME NVARCHAR(100),
@TABLENAME NVARCHAR(100),
@SERVERTYPE NVARCHAR(100),
@SERVERNAME NVARCHAR(100),
@USERNAME NVARCHAR(100),
@PASSWORD NVARCHAR(100),
@ETL_CONFIG_IDN NVARCHAR(100);
SET @ETL_CONFIG_IDN=CAST(@ETL_CONFIG_ID AS NVARCHAR);
SET @TABLENAME='Department';
SET @SERVERTYPE='SQL';
SET @SERVERNAME ='192.168.31.176';
SET @DATABASENAME='AdventureWorks2008R2';
SET @HIERNAME = 'HumanResources';
IF @SERVERTYPE='SQL'
BEGIN
/*SET @openquery= 'SELECT * INTO ##TestTable
FROM OPENROWSET(''SQLNCLI'',''server=192.168.31.176;Trusted_Connection=yes;'','''+@query+''')'
SET @openquery= 'CREATE VIEW '+@TABLENAME+@ETL_CONFIG_IDN+
' WITH ENCRYPTION AS SELECT * FROM OPENROWSET(''SQLNCLI'',''SERVER='+@SERVERNAME+';TRUSTED_CONNECTION=YES;'',''SELECT * FROM '+@DATABASENAME+'.'+@HIERNAME+'.'+@TABLENAME+''')'
SELECT @openquery
END
EXECUTE sp_executesql @openquery
ENDHi aa_rif,
According to your description and code message, you execute the sp_executesql statement in your stored procedure, it indeed create many views with a tablename and ETL_CONFIG_ID named. If you need not to use these temporary views, you can delete them when
it contains the tablename in one view name.
In addition, if you want to create view with encryption in SQL Server, you can use directly the ENCRYPTION option to encrypt the T-SQL of a view in create view commands, for more information, see:
http://learnsqlserver.in/4/Create-View-With-Encryption.aspx. if not, you can descript more detail about requriements, so that more forum members can involve into the thread and help you
out.
Regards,
Sofiya Li
Sofiya Li
TechNet Community Support -
Creating Materialized View with the Distinct key word
Hi
I need help to create Materialized View with the Distinct key word.
my query is
select distinct col1, col2 from t1;
is there any alternate of DISTINCT because I can not refresh the MV as fast on demand if I am using it and Fast on Demand is a must for me.hi
check out this link
http://download-west.oracle.com/docs/cd/B12037_01/server.101/b10736/basicmv.htm#i1007299
http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/intro.htm#sthref183
hope this helps
CHeers -
How to create a view with a column of counts of the occurence of values
If my table is:
ID
1
2
3
3
5
5
5
I want to create a view with the following result:
ID COUNT
1 1
2 1
3 2
5 3
How would I accomplish this?Sorry, my mistake. I was thinking about counting distinct events.
I created a table with your example values:
You should do a projection with a calculated column = 1:
And then add this calculated column as an aggregated measure on the aggregation node:
Result:
Cheers,
Fernando -
How to create a view with parameters; read the documentation but nothing!
Hello!
I'm new to the Oracle world but together with my coworkers we need to very quickly study Oracle to figure out whether we'll add Oracle to our list of supported databases or not.
Question: How do I create a view with parameters?
I've read the documentation but I could not find this! I found the sql syntax to create a view but no parameters whatsoever...
I have found on the web some very complicated way of doing this, but doesn't Oracle support Views with parameters?
The goal here is to return a recordset, don't forget, so,please don't speak about stored procedures unless you are going to tell me how to get a recordset out of a stored procedure! ;)
Thanks for all your help and attention!
Jorge C.You can set up a parameterized view via context as follows:
1. Set up a procedure to set your context values:
create or replace procedure p_set_context (p_context IN VARCHAR2,p_param_name IN VARCHAR2,p_value IN VARCHAR2)
as
BEGIN
sys.dbms_session.set_context(p_context,p_param_name,p_value);
END;
2. Create your context using the procedure you just created
create or replace context my_ctx using p_set_context
3. This is the test table I'll use
create table my_table(col1 number)
and populate it:
begin
for v_index in 1..10
loop
insert into my_table values(v_index);
end loop;
end;
and the view that will be parameterised
create or replace view v_my_table as select col1 from my_table where col1 between sys_context('my_ctx','start_range') and sys_context('my_ctx','end_range')
4. Now set the parameters using the procedure above.
begin
p_set_context('my_ctx','start_range','1');
p_set_context('my_ctx','end_range','5');
end;
5. Selecting from my_table will give you 1 to 10 (no surprise there :-) )
selectng from v_my_table will give you 1 to 5
You can use the context to set formats etc using the same principle. A common gotcha to watch for is trying to set the context directly using DBMS_SESSION.SET_CONTEXT instead of creating a procedure. This belongs to SYS and SYS won't have the privileges to set your context so you get an insufficient privileges result leading to much headscratching and unnecessary grants (at least that's my understanding of it).
Sorry Jorge, as you're new to Oracle I should also have pointed out for completeness sake, that you can change the parameters at any time through recalling the p_set_context, for example, following on from above, after your "select * from v_my_table" and seeing 1 to 5, you could then do
begin
p_set_context('my_ctx','start_range','3');
end;
and when you requery 'Select * from v_my_table' you will now see rows 3 to 5.
Bit of a simplistic example, but you can see how easy it is. :-)
Message was edited by:
ian512 -
Create a View with Aggregation Function (COUNT)
I've been looking up and down for a way to create a view with a few basic fields and some other fields containing aggregation function.
For instance:
To display a view that contain all the Contract Agreement and the corresponding count of the PO releases.
Agreement Nbr, Total PO releases
I need this view so that I can create a search help with this view.
I found something about the "CREATE VIEW" statement, but I don't have any idea how to use it.
Any helps toward this matter is very much appreciated, thanks.Hello Aldern
I guess you have read about the SQL statement "CREATE VIEW". When we create a view in the dictionary this SQL statement is finally called to create the view on the DB. Thus, since we do not have any aggregation options in views you cannot achieve what you want using views.
The solution for your problem is to create a <b>search help</b> having a <b>search help exit</b>. Within the exit you can do your aggregation functions and add these values to the displayed search help data.
Regards
Uwe -
it's posible create a view with parameters?
i want to create a view and pass it parameters, in the same way when i create a procedure or function.
i never have seen it, but i would like to know if that's posible
thanksYou cannot create a view with parameters. The only way is to use a stored proc to dynamically create the sql statement. The substitution variable approach does not work. SQL*Plus will prompt for the value of the variable at compile time (i.e. when you create the view) and use the value you provide in the view's query.
SQL> create or replace view jws_test_v as
2 select * from jws_test where flag = '&flg'
3 /
Enter value for flg: AA
old 2: select * from jws_test where flag = '&flg'
new 2: select * from jws_test where flag = 'AA'
View created.
SQL> select * from jws_test_v
2 /
no rows selected
SQL> select text from user_views where view_name = 'JWS_TEST_V'
2 /
TEXT
select "LEV1","LEV2","LEV3","LEV4","LEV5","LEV6","FC","FLAG","ONAFT","ONAPT","CU
PEFT","CUPEPT" from jws_test where flag = 'AA'This makes sense, since substitution vartiables are a sqlplus construct, not a sql or Oracle construct. A view constructed in this way would not be callable from anywhere other than sqlplus. -
Creating a view with a primary key
I want to create a view with a defined primary key. I understand
the view is created within a select statement, but do not
understand how you would define a particular field as a primary
key in the view. Also if your select statement attempts to build
the view and has duplicate keys in the select result set, what
would happen when the duplicate key is found? Would it just not
include the duplicate key in the view?
Thanks in advance for your help.
-PatI have a rather difficult problem with duplicate invoice numbers
contained in unique records. In other words I have many records
that appear as follows:
3593, 0004009090, CUSTOMER, TAX, 20000117,014011976-01
4411, 0004009090, CUSTOMER, TAX, 20000718,014011976-01
The last field is invoice number '014011976-01' In my case I am
building a flat file using UTL_FILE for loading into SAP
Business Warehouse. In SAP I need to have Invoice number as a
key in which case I can't have duplicate invoice numbers. All
the SQL I have tried to date returns a large amount of records
similar to the above records. I am selecting these records from
4 different schemas which represent 4 different companies. I
realize the data is the problem and that the vendor of the
product I am working with should not allow records with
duplicate invoice numbers, but I have to get the data loaded as
that is what they want and are paying for. So back to my View. I
was hoping to create a view and be able to work in the view to
remove duplicate records prior to writing them to a file. Any
suggestions are welcomed.
Thanks
-Pat -
How to create table view with reference table
Hi experts,
How to create table view with reference table in SE11, plz gve me stp by stp procedure.
pints grnded for hlp.Hi
Go to Tcode se11 choose view and enter the name and create a popup opens up choose database view option
enter the description
On the left hand side choose the table name.
Click on view fields tab and choose your table fields.Here you can choose which fields you want in your view.
Save and then activate.
Hope this helps.
Regards,
Harish -
How to create a view with columns from multiple rows
I have posted this in SQL/PSL forum, but I hope database experts in this group can give me ideas too, also the need is from BI reports.
I have a table, say, project_milestones, which has these columns in concern:
proj_id, milestone_name, actual_end_date
with data:
proj_id, milestone_name, actual_end_date
===== ================ ==============
1001, Key Element Approve, 2009-10-02
1001, Final Synopsis, 2009-10-07
1001, Final Protocol Approved, 2009-10-15
1001, FPFV, 2010-01-10
1001, LPFV, 2010-03-12
1002, Key Element Approve, 2008-12-02
1002, Final Synopsis, 2009-01-07
1002, Final Protocol Approved, 2009-01-12
1002, FPFV, 2009-03-30
1002, LPFV, 2009-10-04
There are about 10 milestones in each project.
I have to create a view to flat these data at project level, looks like this:
proj_id, key_element_date, final_synopsis_date, final_protocol_approved_date, FPFV_date, LPFV_date, key_element_to_final_synopsis_days, final_synopsis_final_protocol_days, ....
How can I do this?
Thanks,user9175541 wrote:
I have posted this in SQL/PSL forum, but I hope database experts in this group can give me ideas too, also the need is from BI reports.
I have a table, say, project_milestones, which has these columns in concern:
proj_id, milestone_name, actual_end_date
with data:
proj_id, milestone_name, actual_end_date
===== ================ ==============
1001, Key Element Approve, 2009-10-02
1001, Final Synopsis, 2009-10-07
1001, Final Protocol Approved, 2009-10-15
1001, FPFV, 2010-01-10
1001, LPFV, 2010-03-12
1002, Key Element Approve, 2008-12-02
1002, Final Synopsis, 2009-01-07
1002, Final Protocol Approved, 2009-01-12
1002, FPFV, 2009-03-30
1002, LPFV, 2009-10-04
There are about 10 milestones in each project.
I have to create a view to flat these data at project level, looks like this:
proj_id, key_element_date, final_synopsis_date, final_protocol_approved_date, FPFV_date, LPFV_date, key_element_to_final_synopsis_days, final_synopsis_final_protocol_days, ....
How can I do this?
Thanks,Create a pivot table and put "milestone_name" in the Columns section under the Labels.
Put "actual_end_date" in the Measures section and change the Aggregation Rule to "Max."
The rest of the attributes keep in Rows section. -
Creating a view with existing GeoRaster columns and new SDO_GEOMETRY column
Hi,
In a nutshell, I already have 1 real table, which has several attributes including types such as text, numbers etc. but also a GeoRaster column. This table works great, has its metadata stored properly and is spatially indexed; no worries.
I am then creating a view based on the above mentioned table, including the GeoRaster column. This worked, no problems. However now I want the same view to also have a SDO_GEOMETRY column which explicitly stores the spatial extent for each GeoRaster. Note the original table does not have this SDO_GEOMETRY column. So, I have created a revised SQL statement to create the view, but now it dynamically adds a new column and puts the GeoRaster.spatialextents into the SDO_GEOMETRY column.
This worked, the data made it into the view, but when we try to view the SDO_GEOMETRY in a viewer, we get errors. I added a system metadata entry for the view, but this did not help. Also, it is not possible to spatially index a view so I knew that was not the problem.
I think what has happened is the SDO_GEOMETRY column is in a sort of "limbo", where because it was not contained in the original table (and indexed there) and it is not able to be indexed in a view, it cannot be manipulated/viewed/used spatially.
Here is a snippet describing the original table:
"IMAGERY_ID" NUMBER NOT NULL ENABLE,
"CAM_ANGLE_X" NUMBER,
"CAM_ANGLE_Y" NUMBER,
"CAM_ANGLE_Z" NUMBER,
"SPEED" NUMBER,
"HEADING" NUMBER,
"IMAGE_GEOR" "SDO_GEORASTER",
"ACQUISITION_TIME" TIMESTAMP (6),
"SENSOR_ID" NUMBER,
"DOWNWARD_LOOKING" CHAR(1 BYTE),
"ORG_ID" NUMBER,
"POC_ID" NUMBER,
"FILE_NAME" VARCHAR2(100 BYTE),
"CORRELATION_ID" VARCHAR2(256 BYTE),
And here is the statement I used to create the new view:
CREATE VIEW level_0_img_view (imagery_id, cam_angle_x, cam_angle_y, cam_angle_z, speed, heading, image_geor, acquisition_time, sensor_id, downward_looking, org_id, poc_id, file_name, correlation_id, geor_extents)
AS
SELECT a.imagery_id, a.cam_angle_x, a.cam_angle_y, a.cam_angle_z, a.speed, a.heading, a.image_geor, a.acquisition_time, a.sensor_id, a.downward_looking, a.org_id, a.poc_id, a.file_name, a.correlation_id, a.image_geor.spatialextent
FROM imagery a
WHERE a.file_name LIKE '%.lev0';
Note in the above statement that the "geor_extents" column is the new column added dynamically (and not in the original table). Note the new column with the SDO_GEOMETRY data is flawless, I have looked at the records in SQL developer and all the data is there.
Any ideas?
In case you're wondering, I do have reasons for: (i) wanting an explicit column with the SDO_GEOMTRY (serving via WFS), and (ii) not wanting to alter the original table to include the equivalent SDO_GEOMETRY column.
Cheers,
M.Hi,
if you are having problems to display your view spatial columns in MapBuilder/MapViewer, you may be missing to register the view information in the metadata (name and spatial columns).
For example, lets see the following table that simulates your case:
SQL> desc pci_image;
Name Null? Type
GEORID NOT NULL NUMBER
TYPE VARCHAR2(32)
GEORASTER MDSYS.SDO_GEORASTER
-- create a view
create view pci_img_view (georid,georaster,geor_extents)
as
select a.georid,a.georaster,a.georaster.spatialextent
from pci_image a;
-- register metadata for view spatial columns (GeoRaster and geometry column)
insert into user_sdo_geom_metadata
select 'PCI_IMG_VIEW','GEORASTER.SPATIALEXTENT', diminfo, srid
from user_sdo_geom_metadata where table_name = 'PCI_IMAGE'
insert into user_sdo_geom_metadata
select 'PCI_IMG_VIEW','GEOR_EXTENTS', diminfo, srid
from user_sdo_geom_metadata where table_name = 'PCI_IMAGE'
There is no need to index the spatial columns if they have been indexed before.
Now, if you go in MapBuilder you should see the the view name in the list of geometry tables, and be able to create a theme on column GEOR_EXTENTS (select it on the combo box) and to preview it.
For the GeoRaster column, currently the view name is not shown on the list of GeoRaster tables in MapBuilder.
For GeoRaster data, MapBuilder uses the contents of metadata view user_sdo_geor_sysdata, and then it would be needed to register the view contents there. We will talk with Jeffrey to check if there is any problem in registering
view contents in this metadata view. If the view name and georaster column is registered in user_sdo_geor_sysdata,
then it should show in MapBuilder. But you can still create a GeoRaster theme for this view using a SQL command, and should be able to preview it in MapBuilder.
-- create a GeoRaster theme based on view Georaster column.
insert into user_sdo_themes values (
'PCI_IMAGE_V_GEOR',
'View of georaster column',
'PCI_IMG_VIEW',
'GEORASTER',
'<?xml version="1.0" standalone="yes"?>
<styling_rules theme_type="georaster" raster_id="1" raster_table="RDT_PCI" raster_bands="0,1,2">
</styling_rules>');
-- commit changes
commit;
Joao -
Create folder view with files and tasks
Good day to you,
we want to support our software development procces with Vibe. What we are doing is, we make changes to the source code and protocol corresponding things in certain files.
We think in so called "releases" and every release consists of tasks and a list of changes. This list is held in an excel file, so I would like to create a folder view, which consists of tasks and files.
So far I could create a custom folder view with attachments at the top and a task list at the bottom, based on the task family.
The problem is, the attachment view as a standard folder view does not allow colleborative editing of attached files. You can only view and download attached files, but not open them via Office addin. Therefore you can not lock or version files, which is mandatory for collaborative work.
I would like to mix the file folder view with it's possibilities with a task folder view.
Any ideas?
Warm regards
bitschnauThere's no out of the box way to achieve what you're looking for.
Two solutions:
1. Your users would need to open the entry first and then click on the "edit this file" link.
2. You could code your own folder view or landing page element and build what you need.
HTH
Cheers
Erik
PS: Feel free to contact me offlist if you need professional support. -
Create Materialized View with GROUP BY
I have a table
treecluster NUMBER(3)
treenumber NUMBER(3)
treedate DATE
nestnumber NUMBER(3)
eggs NUMBER(3)
nestlings NUMBER(3)
fledglings NUMBER(3)
nestfate VARCHAR2(10)
nestfailurecode NUMBER(2)
I want to group the data by treecluster, treenumber, year, and nest number and get a max eggs, nestlings, fledglings. I am doing this with the following:
SELECT treecluster, treenumber, to_char(nestchecksdate, 'YYYY'), nestnumber,
max(eggs), max(nestlings), max(fledglings)
FROM nestchecks
GROUP BY treecluster, treenumber, to_char(nestchecksdate, 'YYYY'), nestnumber;
This works fine.
The last record for a year has a nestfate and nestfailurecode value.
I need to group all information and then also get the nestfate and nestfailurecode for the year. How do I go about getting this information?
I am really trying to create a summary materialized view based on a data table so the select I am trying to craft would be a part of a create materialized view as SELECT...
so I want to be able to group the info and add in the nestfate and failurecode in one step.
Thanks!try this:
SQL> select * from table_tree;
TREECLUSTER TREENUMBER NESTCHECK NESTNUMBER EGGS NESTLINGS FLEDGLINGS NESTFATE NESTFAILURECODE
4 167 17-MAY-00 2 0 0
4 167 24-MAY-00 2 3 0
4 167 30-MAY-00 2 3 0
4 167 12-JUN-00 2 0 1 FAILURE 2
select a.treecluster, a.treenumber, to_char(a.nestyear,'YYYY') nestyear,
a.nestnumber, a.eggs, a.nestlings, a.fledglings, a.nestfate, a.nestfailurecode
from (select max(treecluster) treecluster, max(treenumber) treenumber,
max(nestchecksdate) nestyear,
max(nestnumber) nestnumber, max(eggs) eggs, max(nestlings) nestlings,
nvl(max(FLEDGLINGS),0) FLEDGLINGS, max(NESTFATE) NESTFATE,
max(nestfailurecode) nestfailurecode
from table_tree) a
TREECLUSTER TREENUMBER NEST NESTNUMBER EGGS NESTLINGS FLEDGLINGS NESTFATE NESTFAILURECODE
4 167 2000 2 3 1 0 FAILURE 2hope this helps
Maybe you are looking for
-
This week Firefox would not allow me to open a blank tab when I click on the + tab at the top or when I press Ctrl T. I used to be able to open new blank tabs. This is frustrating. I have looked at the tools/options and help sections and cannot figur
-
SPA IP phones doesn't show calling number after the call was picked UP
Hello, Our different CISCO SPA IP phones models (at this time we are using 7.4.8a version) are working with Broadsoft AS. And now we have a problem: when CISCO SPA IP PHONE pickups the call ( by pressing BLF lamp) and the call is connected, Cisco
-
Before, when reading PDF files, I was able to copy and paste part of the book. Now it is not possible. I can copy but when pasting gets nothing. Antes, quando lia arquivos PDF, eu conseguia copiar e colar parte do livro. Agora isso não é possível. Eu
-
my i pod is not working after low bettry i putted on charging after 5% bettry it going on and off automatically.i touched the buttons so many times but all in vane plz help me
-
How do I link Elements11 to an existing shutterfly account
I see how to establish a new shutterfly account, but how do I link to an exisiting account?