How to insert into table type variables
hi all,
how to assingn values to table type variable, i am getting error.
declare
dept1 dept%rowtype;
begin
dept1:=(100,'SHIPPING','HYDERABAD');
end;
ERROR at line 4:
ORA-06550: line 4, column 8:
PLS-00382: expression is of wrong type
regards,
Sri Ram.
You can do like this
declare
dept1 dept%rowtype;
begin
dept1.deptno := 10;
dept1.dname := 'IT';
end;
/
Similar Messages
-
How to insert a table with variable rows in smart form
Hi all,
How to insert a table with variable rows in smart form?
Any help would be appreciated.
Regards,
Mahesh.Hi,
Right click the mouse->create->table
If you want 5 columns, you need to declare 5 cells in one line type of the table
Click on Table -> Details, then do the following
Line Type 1 2 3 4 5
L1 2mm 3mm etc
Here specify the width of the columns as many as you want..
then in the header/main area of the table, click create Table Line, Rowtype is L1, automatically 5 cells will come,In each cell create a text element, display the variable to be printed there. -
How to Populate a table type variable from a cursor
Hi
I have a stored procedure (P1) that returns a ref cursor as the output.
Another procedure (P2) receives this ref cursor (C).
In this procedure (P2), I want to do a Bulk Collect from this ref cursor (C) in
a table type variable that has been declared locally in the procedure P2. I have created appropriate Object Type and Table Types at the database level.
Please advise how to do it. I tried to do it in different ways, but was not able to do it - each time I faced incompatible data-type related issues.
Regards
MadhupWhat I wrote was unclear. Syntactically it is valid and does something. But consider the advantage of a decent design.
SQL> create or replace procedure p1 (o out sys_refcursor) as
2 begin
3 open o for select * from emp;
4 end p1;
5 /
Procedure created.
SQL> create or replace procedure p2(i sys_refcursor) as
2 type emp_tab is table of emp%rowtype;
3 l_emp_tab emp_tab;
4 begin
5 fetch i bulk collect into l_emp_tab;
6 close i;
7
8 for i in 1..l_emp_tab.count loop
9 NULL;
10 end loop;
11 end p2;
12 /
Procedure created.
SQL> CREATE OR REPLACE PROCEDURE p3 IS
2
3 TYPE myarray IS TABLE OF emp%ROWTYPE;
4 l_data myarray;
5
6 CURSOR r IS
7 SELECT * FROM emp;
8
9 BEGIN
10 OPEN r;
11 LOOP
12 FETCH r BULK COLLECT INTO l_data;
13
14 FOR j IN 1 .. l_data.COUNT
15 LOOP
16 NULL;
17 END LOOP;
18
19 EXIT WHEN r%NOTFOUND;
20 END LOOP;
21 CLOSE r;
22 END p3;
23 /
Procedure created.
SQL> set serverout on
SQL> set timing on
SQL> declare
2 r sys_refcursor;
3 begin
4 FOR i IN 1 .. 10000 LOOP
5 p1(r);
6 p2(r);
7 END LOOP;
8 end;
9 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:01.71
SQL> begin
2 FOR i IN 1 .. 10000 LOOP
3 p3;
4 END LOOP;
5 end;
6 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:01.21
SQL> Again sorry for being less than clear. -
How to insert into table when ID auto increment?
I have a table Employee with EmloyeeID, EmployeeName, Email...
When i design table in database, i created a Sequence and then Trigger for EmployeeID to auto increment.
Now in ADF, actually in my web form: I don't want enter values for EmployeeID to insert into table,
but still error : required for EmployeeID...
how can i do it? ThanksUser,
Always mention your JDev version every time you start a new thread.
Check this out : Andrejus Baranovskis Blog: How To Implement Gapless Sequence in ADF BC
-Arun -
Error when inserting into table - Undefined Variable
DB = Oracle 10.2.0.1
WEBSERV = Apache 2.0.55
LANG = PHP5
I have created (or more accurately, copied) a php script to insert data into one of my database tables when I press submit. The code is as follows (my connect string works fine and its included in the dbutils.php file):
<?php
if($submit == "submit"){
include "dbutils.php";
$query = "insert into users values (seq_user_usr_id.NEXTVAL, '$usr_name')";
$cursor = OCIParse ($db_conn, $query);
if ($cursor == false){
echo OCIError($cursor)."<BR>";
exit;
$result = OCIExecute ($cursor);
if ($result == false){
echo OCIError($cursor)."<BR>";
exit;
OCICommit ($db_conn);
OCILogoff ($db_conn);
else{
echo '
<html><body>
<form method="post" action="index.php">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Please enter a username:</td>
<td><input type="text" name="usr_name"></input><br></td>
</tr>
<tr>
<td><input type="submit" name="button" value="Submit"></input></td>
</tr>
</table>
</form>
</body></html>
?></p>I am getting the following error regarding an undefined variable:
[Fri Jan 20 13:11:22 2006] [error] [client 127.0.0.1] PHP Notice: Undefined variable: submit in C:\\Program Files\\Apache Group\\Apache2\\htdocs\\mywebsite\\test.php on line 3
Where would I declare this variable? It is just a check to see if the submit button is pressed as far as I can see. Any help would be greatfully appreciated.
W8I have changed the code to this:
<?php
if($submit == "submit"){
include "dbutils.php";
$usr_name = $_POST['usr_name'];
$query = "insert into users (column1, column2) values (seq_user_usr_id.NEXTVAL, '$usr_name')";
$cursor = OCIParse ($db_conn, $query);
if ($cursor == false){
echo OCIError($cursor)."
exit;
$result = OCIExecute ($cursor);
if ($result == false){
echo OCIError($cursor)."
exit;
OCICommit ($db_conn);
OCILogoff ($db_conn);
else{
$submit = $_POST['submit'];
echo '
<html><body>
<form method="post" action="index.php">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Please enter a username:</td>
<td><input type="text" name="usr_name"></input>
</td>
</tr>
<tr>
<td><input type="submit" name="submit" value="submit"></input></td>
</tr>
</table>
</form>
</body></html>
?>And now I am getting the following error:
[Mon Jan 23 13:45:32 2006] [error] [client 127.0.0.1] PHP Notice: Undefined index: submit in C:\\Program Files\\Apache Group\\Apache2\\htdocs\\mywebsite\\test2.php on line 24Does anyone have any ideas?
I am struggling to find an example to work from to get this working. If anyone can point me to any literature that will explain the code so that I can work this out for myself that would also be a great help. -
How to insert into table from an Datatable ?
Hi Friend,
I have a datatable that is created at some point in my SSIS as an object.
I need to insert the data into a sql table, how should I do that ?
I have this:
Dim oleDA As New OleDbDataAdapter
Dim dt As New DataTable
Dim col As DataColumn
Dim row As DataRow
Dim sMsg As String
oleDA.Fill(dt, Dts.Variables("history").Value
and want to insert into a table in a SQL DB
Dim sqlCon As New SqlClient.SqlConnection("server=Myserver\SQL2008R2;database=MyDB;Integrated Security=SSPI")
Dim sqlreader As SqlClient.SqlDataReader
sqlCon.Open()
Thanks in advance,
Pat
Patrick AlexanderConvert it to a ADO .Net recordset and store it in a object variable in SSIS.
Then you can use it to populate the table using foreach loop with ado enumerator
http://www.codeproject.com/Articles/10503/Simplest-code-to-convert-an-ADO-NET-DataTable-to-a
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
How to insert into table, of table description of table
Dear All,
I need to take the table description of the table and i need to insert that description in to a new table column , please help me to how to write the query for these.
many thanks in advance
Sreenivasulu Puser627163 wrote:
Dear All,
I need to take the table description of the table and i need to insert that description in to a new table column , please help me to how to write the >query for these.Why insert into a new column into the same table ? That would be madness. :) (kidding)
You can explore with this :
[oracle@g5 ~]$ sqlplus scott/tiger
SQL*Plus: Release 11.1.0.6.0 - Production on Tue Jun 2 09:23:10 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create table dtable (tablename varchar2(20),col_name varchar2(20),Not_null varchar2(1), datatype varchar2(20) );
Table created.
SQL> desc dtable
Name Null? Type
TABLENAME VARCHAR2(20)
COL_NAME VARCHAR2(20)
NOT_NULL VARCHAR2(1)
DATATYPE VARCHAR2(20)
SQL> set wrap off
SQL> SELECT column_name "Name", nullable "Null?",
CONCAT (CONCAT (CONCAT (data_type, '('), data_length), ')') "Type"
FROM user_tab_columns
WHERE table_name = 'EMP';
Name N Type
EMPNO N NUMBER(22)
ENAME Y VARCHAR2(10)
JOB Y VARCHAR2(9)
MGR Y NUMBER(22)
HIREDATE Y DATE(7)
SAL Y NUMBER(22)
COMM Y NUMBER(22)
DEPTNO Y NUMBER(22)
8 rows selected.
SQL> INSERT INTO dtable
SELECT 'emp', column_name, nullable,
CONCAT (CONCAT (CONCAT (data_type, '('), data_length), ')') "Type"
FROM user_tab_columns
WHERE table_name = 'EMP';
8 rows created.
SQL> commit;
Commit complete.
SQL> select * from dtable;
TABLENAME COL_NAME N DATATYPE
emp EMPNO N NUMBER(22)
emp ENAME Y VARCHAR2(10)
emp JOB Y VARCHAR2(9)
emp MGR Y NUMBER(22)
emp HIREDATE Y DATE(7)
emp SAL Y NUMBER(22)
emp COMM Y NUMBER(22)
emp DEPTNO Y NUMBER(22)
8 rows selected.
many thanks in advancecheers
Sreenivasulu P -
How to INSERT into table using CORRELATED subquery
I have 3 tables:
1.TEMP_PHONE(person_id, phonenumber, phone_type) - this holds all phone numbers relating to a person(just a temporary holding area)
2.PHONE_CONNECT(PERSON_ID, PHONE_ID) this table shows all the phone numbers relating to an individual. Phone_id is a unique number to identify a phonenumber and type(cell, work, home) - so in this table a person can have multiple phone ids)
3.MASTER_PHONE(PHONE_ID, PHONENUMBER, PHONE_TYPE) this is a master phone table. each combination of phone number and type has a unique identifier-phone_id.
What i need to figure out is how to populate PHONE_CONNECT with the information from TEMP_PHONE IF PERSON_ID already exists but phone_id is different. In other words, if the person gets a new phone number, i need to insert a new row into phone_connect.
Before that step is started, the master_phone is populated first with a new phone_id associated to the phonenumber/type
any help would be much appreciated. Thanks in advance.
So far, this is what i have come up with, but not sure if it makes sense:
insert into phone_connect(person_id)
select a.person_id
from temp_phone a
where
person_id = (select b.person_id from phone_connect b, master_phone c
where
a.person_id=b.person_id
and b.phone_id <> c.phone_id
and c.phonenumber||c.phone_type=a.phonenumber||a.phone_type);
update phone_connect c
set phone_id=(
select b.phone_id
from temp_phone a, master_phone b
where a.person_id = c.person_id
and a.phonenumber||a.phone_type = b.phonenumber||b.phone_type)
where phone_id is null;It does. You are right. But that's what i need help with. I don't think my code is correct. After the insert, the code is actually updating the same exact record I just inserted. I'm sure this all can be done with one insert. I just really don't know how to show that in my code.
I need to insert a new record into phone_connect with person_id and phone_id. phone_id is already populated in master_phone. I guess my problem is how to go about creating the joins to all three tables to make sure im inserting the data correctly, or not inserting data that already exists. -
How to insert into collection type of objects?
Hello,
Can any one help with the follwoing code below,where i cant insert into an instance of the table type within the pl/sql block.
create type courselist is table of varchar2(25);
create type student as object
(name varchar2(20),
courses courselist);
create type student_typ is table of student;
create or replace procedure test_nested as
my_courses1 student_typ:=student_typ(student('harry',courselist('eco 2010','math 2010','acct 2010')));
n_numb number;
begin
dbms_output.put_line('hello initial'||'-'||my_courses1.count);
my_courses1.extend;
n_numb:=my_courses1.next(my_courses1.first);
dbms_output.put_line('Next Subscript :'||n_numb);
dbms_output.put_line('hello after extend'||'-'||my_courses1.count);
my_courses1(n_numb):=student_typ(student('Potter',courselist('eng 2010','bio 2010')));
dbms_output.put_line(my_courses1(n_numb).name);
exception
when others then
dbms_output.put_line(sqlerrm);
end;Look at:
my_courses1(n_numb):=student_typ(student('Potter',courselist('eng 2010','bio 2010')));my_courses1(n_numb) is of student type while student_typ(student('Potter',courselist('eng 2010','bio 2010'))) is table of student type. Change it to:
my_courses1(n_numb):=student('Potter',courselist('eng 2010','bio 2010'));and you will be fine:
SQL> create or replace
2 procedure test_nested
3 as
4 my_courses1 student_typ:=student_typ(student('harry',courselist('eco 2010','math 2010','acct 2010')));
5 n_numb number;
6 begin
7 dbms_output.put_line('hello initial'||'-'||my_courses1.count);
8 my_courses1.extend;
9 n_numb:=my_courses1.next(my_courses1.first);
10 dbms_output.put_line('Next Subscript :'||n_numb);
11 dbms_output.put_line('hello after extend'||'-'||my_courses1.count);
12 my_courses1(n_numb):=student('Potter',courselist('eng 2010','bio 2010'));
13 dbms_output.put_line(my_courses1(n_numb).name);
14 exception
15 when others then
16 dbms_output.put_line(sqlerrm);
17 end;
18 /
Procedure created.
SQL> exec test_nested
hello initial-1
Next Subscript :2
hello after extend-2
Potter
PL/SQL procedure successfully completed.
SQL> SY. -
How to insert into table through reports
hi,
i m working on oracle reports 10g,i made a report which fatching some data & contains some function , i want to insert values of that functions into a table & how to update it if user again run that report.
like
data1 data2 data3
function1 function2
the values of function 1 & 2 shouls be insert into a table. if that user exist in table then update it otherwise insert that values;
thxsU can use SRW.DO_SQL built-in procedure . Check the reports online help from the reports builder.
Rajesh
FUNCTION CREATETAB RETURN BOOLEAN IS
BEGIN
SRW.DO_SQL('CREATE TABLE CHECK (EMPNO NUMBER NOT NULL
PRIMARY KEY, SAL NUMBER (10,2)) PCTFREE 5 PCTUSED 75');
RETURN(TRUE);
EXCEPTION
WHEN SRW.DO_SQL_FAILURE THEN
SRW.MESSAGE(100, 'ERROR WHILE CREATING CHECK TABLE.');
SRW.MESSAGE(50, 'REPORT WAS STOPPED BEFORE THE RUNTIME
PARAMETER FORM.');
RAISE
SRW.PROGRAM_ABORT;
END;
Edited by: RajeshAlex on Sep 30, 2008 12:10 PM -
How to insert into table from a xml with XDE for java?
want to insert into the oracle tables from the xml with XDE for java, some sample better. thank you.
XML Document may be stored in a SQL database with XML SQL Utility.
http://download-west.oracle.com/docs/cd/B13789_01/appdev.101/b10794/adx08xsu.htm#i1008168
XML Document may be stored in a SQL database with Oracle XML DB.
http://download-west.oracle.com/docs/cd/B13789_01/appdev.101/b10790/xdb03usg.htm#CEGFECFH -
How to pass table type variable into function from SQL*PLUS ?
How to pass a table type variable from sql*plus prompt into a function ?
Thanx in advance.Krishna,
Do you mean like this?SQL> DECLARE
2 TYPE t_tbl IS TABLE OF VARCHAR2(20);
3 l_sample_tbl t_tbl;
4
5 FUNCTION print_contents ( p_tbl IN t_tbl )
6 RETURN VARCHAR2
7 IS
8 l_string VARCHAR2(1000);
9 BEGIN
10 FOR i IN 1..p_tbl.COUNT LOOP
11 IF (i = 1) THEN
12 l_string := p_tbl(i);
13 ELSE
14 l_string := l_string || ', ' || p_tbl(i);
15 END IF;
16 END LOOP;
17 RETURN (l_string);
18 END print_contents;
19
20 BEGIN
21 l_sample_tbl := t_tbl();
22 l_sample_tbl.EXTEND;
23 l_sample_tbl(1) := 'one';
24 l_sample_tbl.EXTEND;
25 l_sample_tbl(2) := 'two';
26 l_sample_tbl.EXTEND;
27 l_sample_tbl(3) := 'three';
28 l_sample_tbl.EXTEND;
29 l_sample_tbl(4) := 'four';
30 l_sample_tbl.EXTEND;
31 l_sample_tbl(5) := 'five';
32 DBMS_OUTPUT.PUT_LINE(print_contents(l_sample_tbl));
33 END;
34 /
one, two, three, four, five
PL/SQL procedure successfully completed.
SQL> HTH,
T. -
How to insert into a table with a nested table which refer to another table
Hello everybody,
As the title of this thread might not be very understandable, I'm going to explain it :
In a context of a library, I have an object table about Book, and an object table about Subscriber.
In the table Subscriber, I have a nested table modeling the Loan made by the subscriber.
And finally, this nested table refers to the Book table.
Here the code concerning the creation of theses tables :
Book :
create or replace type TBook as object
number int,
title varchar2(50)
Loan :
create or replace type TLoan as object
book ref TBook,
loaning_date date
create or replace type NTLoan as table of TLoan;
Subscriber :
create or replace type TSubscriber as object
sub_id int,
name varchar2(25)
loans NTLoan
Now, my problem is how to insert into a table of TSubscriber... I tried this query, without any success...
insert into OSubscriber values
*(1, 'LEVEQUE', NTLoan(*
select TLoan(ref(b), '10/03/85') from OBook b where b.number = 1)
Of course, there is an occurrence of book in the table OBook with the number attribute 1.
Oracle returned me this error :
SQL error : ORA-00936: missing expression
00936. 00000 - "missing expression"
Thank you for your help1) NUMBER is a reserved word - you can't use it as identifier:
SQL> create or replace type TBook as object
2 (
3 number int,
4 title varchar2(50)
5 );
6 /
Warning: Type created with compilation errors.
SQL> show err
Errors for TYPE TBOOK:
LINE/COL ERROR
0/0 PL/SQL: Compilation unit analysis terminated
3/1 PLS-00330: invalid use of type name or subtype name2) Subquery must be enclosed in parenthesis:
SQL> create table OSubscriber of TSubscriber
2 nested table loans store as loans
3 /
Table created.
SQL> create table OBook of TBook
2 /
Table created.
SQL> insert
2 into OBook
3 values(
4 1,
5 'No Title'
6 )
7 /
1 row created.
SQL> commit
2 /
Commit complete.
SQL> insert into OSubscriber
2 values(
3 1,
4 'LEVEQUE',
5 NTLoan(
6 (select TLoan(ref(b),DATE '1985-10-03') from OBook b where b.num = 1)
7 )
8 )
9 /
1 row created.
SQL> select *
2 from OSubscriber
3 /
SUB_ID NAME
LOANS(BOOK, LOANING_DATE)
1 LEVEQUE
NTLOAN(TLOAN(000022020863025C8D48614D708DB5CD98524013DC88599E34C3D34E9B9DBA1418E49F1EB2, '03-OCT-85'))
SQL> SY. -
How to insert into more than one table at a time also..
hi,
i am a newbee.
how to insert into more than one table at a time
also
how to get a autoincremented value of an id say transactionid for a particular accountid.
pls assume table as
transactionid accountid
101 50
102 30
103 50
104 35
i want 102 for accountid 30 and 103 for accountid 50.
thank u@blushadow,
You can only insert into one table at a time. Take a look here :
Re: insert into 2 tables
@Raja,
I want how to extract the last incremented value not to insert.Also, I don't understand your thread title... which was "how to insert into more than one table at a time also.. "
Insert, extract... ? Can you clarify your job ?
Nicolas. -
How to insert into 2 tables from the same page (with one button link)
Hi,
I have the following 2 tables....
Employees
emp_id number not null
name varchar2(30) not null
email varchar2(50)
hire_date date
dept_id number
PK = emp_id
FK = dept_id
Notes
note_id number not null
added_on date not null
added_by varchar2(30) not null
note varchar2(4000)
emp_id number not null
PK = note_id
FK = emp_id
I want to do an insert into both tables via the application and also via the same page (with one button link). I have made a form to add an employee with an add button - adding an employee is no problem.
Now, on the same page, I have added a html text area in another region, where the user can write a note. But how do I get the note to insert into the Notes table when the user clicks the add button?
In other words, when the user clicks 'add', the employee information should be inserted into the Employees table and the note should be inserted into the Notes table.
How do I go about doing this?
Thanks.Hi,
These are my After Submit Processes...
After Submit
30 Process Row of NOTES Automatic Row Processing (DML) Unconditional
30 Process Row of EMPLOYEES Automatic Row Processing (DML) Unconditional
40 reset page Clear Cache for all Items on Pages (PageID,PageID,PageID) Unconditional
40 reset page Clear Cache for all Items on Pages (PageID,PageID,PageID) Unconditional
40 reset page Clear Cache for all Items on Pages (PageID,PageID,PageID) Unconditional
40 reset page Clear Cache for all Items on Pages (PageID,PageID,PageID) Unconditional
50 Insert into Tables PL/SQL anonymous block Conditional
My pl/sql code is the same as posted earlier.
Upon inserting data into the forms and clicking the add button, I get this error...
ORA-06550: line 1, column 102: PL/SQL: ORA-00904: "NOTES": invalid identifier ORA-06550: line 1, column 7: PL/SQL: SQL Statement ignored
Error Unable to process row of table EMPLOYEES.
Is there something wrong with the pl/sql code or is it something else?
Maybe you are looking for
-
hi, I have a requirement where i have 2 columns in a table .. one should be read only and the other should be edittable... so i have inserted two cell editors of input field type..and made one as read only and the other one not read only. but wen i r
-
Problem printing cd cover artwork
I select print to bring up the artwork for songs purchased and it shows the mosaic with the song list but when I print, all that prints in the place where the album cover should be is a big black box. The only part that prints correctly is the song l
-
Communication between servlet & rich client - ObjectStream or OutputStream?
Hi, I need to send a text file from a servlet to a rich client. Is it better to send it over OutpputStream or wrap it up as an Object(eg: StringBuffer) and send it over OutputStream? Will the performance be significantly be affected if I try to wrap
-
I can open and read my email but can not open any links
I Can open my email but can not open any links
-
Greetings folks. I'm stuck in the Windows world and am looking to replace my desktop with an iMac. Today, my employer requires a windows based build, and I have a requirement to see the consoles of several machines at the home office. I've learned th