create empty row in dbgrid - oracle11g

I wanted to insert several lines to database using DBGrid.
on my query, I selected for example:
select * from cust where id='0';
that code will return no record at all so my dbgrid will not show anything but an empty row. Now I wanted to put in data in empty row with new data. However my data needs 2 lines from dbgrid. I wanted dbgrid creates an empty row right after I fill last column in first row. How do I code that? (without inserting the first row data because later I'll insert everything with a seperated button).
thanks!

you can add records in your table with NULLin each column.
For example, suppose the table where the DBGrid is binded to has 4 columns, than you can try this code to add empty records
Query1.InsertRecord([null, null, null, null]);
With this code you can add as many empty records as you like in the DBGrid
That is assuming that the query component you are using supports the InsertRecord method...

Related

How do I populate an empty column in my sql database?

How do I populate an empty column in my sql database?
I have a list that I want in the last column of my database. If I use executemany it just adds rows on the bottom of my database. Is there a way to fill it from the top? The column is currently populated with NULL values.
Just to be clear. I want the first item in the list to be put in the first row and item n on the list to be put into row n.
Thanks in advance
*Always take backup of your database, just incase you want to revert it back to original state.
Each row in your database table should have a unique primary key. As you mentioned you have a list to be uploaded in the last column, I assume you have some kind of relationship that distinguishes which list item goes to which row in the last column of the table.
You an update a single row by simple update syntax as below:
UPDATE table_name
SET last_column = somevalue_from_list
WHERE id = unique_row_id;
If you want to update all the rows with the same value then
UPDATE table_name
SET last_column = one_value_for_all_rows;
Follow the below suggestion only when you are using phpmyadmin to manage your tables:
If you want to update each row with the unique value from the list then my suggestion will be to export your table in csv format, open in excel like software and add your last column values in last column of each row and then import the changed table back to the database.
Hope this help.

Need to delete/insert that corresponding row in that table, as there is duplicate data coming up- PLSQL

I need a help in getting the PLSQL procedure to : Insert/Delete the rows of a table , because as I used Update functionality getting duplicates for that particular Sequence ID field.
So for a particular sequence ID row, whenever I insert the data, it should be the latest in that table.
The last sentence you wrote suggests that you have to
delete row(s) whose ID equals that particular "sequence ID" value
then insert a new row
If you expected some code to be written, you should have posted some more info (CREATE TABLE and INSERT INTO sample data, as well as the way you manipulate it by inserting new row, showing what you expect to happen with old one(s)). It is difficult to write code based on unknown data model.
A guess...
INSERT INTO schema_name.table_name(
primary_key_column
, other_column
)
VALUES(
(SELECT max(primary_key_column)+1 FROM schema_name.table_name),
, 'other_value'
);
COMMIT;
This is the procedure I am using:
https://drive.google.com/file/d/1eGbxSppjexpICKh6pzuW0ZzckVxA6BB0/view?usp=sharing
My requirement when we need to insert the new data , the previous data should be deleted for the corresponding ID.
In the above procedure I am updating the data.

PhpExcel Dynamic Header in first Row

I have below SQL and I want to write field values in first row and rest of the row and values. How do I achieve using PHPEXCEL.
Can someone post full example.
I found so many example how to write fixed rows when you know the field name but without knowing field name I like to print header in first row and rest as values.
$query = "SELECT * FROM uam_user";

Insert into table access 2010

How can i copy contents of my whole table in sql access and update one column to the same table.
So basically is selecting the whole table and updating one column and pasting that to the same table. thanks.
To clone an existing table back into the same table, but using a different value for one field, use something like the following (see notes that follow!):
INSERT INTO Table1 ( FldA, FldB, MyDate, StateCode )
SELECT Table1.FldA, Table1.FldB, Table1.MyDate, "FL" AS Expr1
FROM Table1;
You can't easily use the * to select/update all fields because your need to change one field would result in a "duplicate destination" error. If needed, you could use an 'IF' statement to change to different values (i.e. IF(FldA="VA","FL",IF(FldA="MD","TX",Flda))

How can I insert a new table row into every other row in an existing table?

Ok I have a sqlite db, that has roughly 100 rows. It is kind of a strange thing that I'm trying to do, but I need to insert a new row between each of the existing rows.
I have been trying to use the Insert statement as follows, but haven't had any luck:
insert into t1(column1) values("hello") where id%2 == 0
So I'm basically trying to use the %-operator to tell me if the id is even or odd. For every even id number, I'd like to insert a new row.
What am I missing? What can I do differently? How can I insert a new row into every other row and have the index updated as well?
Thanks
Your question assumes that the rows have some kind of built-in order to them, and that you can insert rows between other rows. That's not true.
It is true that rows have an order on disk, and that the id column is usually assigned in order, but that's an implementation detail. When you perform a query, the database is free to return the rows in any order it chooses, unless you specify what you want with an ORDER BY clause.
Now, I'm assuming what you really want is to insert rows between the existing rows in id order. One way to get what you want would look like this:
UPDATE t1 SET id = id * 2
INSERT INTO t1 (id, column) SELECT id+1, "hello" FROM t1
The UPDATE would double the ids of all the existing rows (so 1,2,3 becomes 2,4,6); then the INSERT would perform a query on t1 and use the result to insert a new set of rows with id values one more than the existing rows (so 2,4,6 becomes 3,5,7).
I haven't tested the above statements, so I don't know if they would work or if they require some extra trickery (like a temporary table) since we are querying and updating the same table in one statement. Also I may have made a syntax error.
Don't consider the rows as pre-ordered in the database. A database will store them as they come in, or according to an index. It's your task to order them on retrieval (i.e. when you query for data) according to your needs.

Resources