Q: Add the data to the tables. Be sure to use the sequences for the PKs.
I need to add data into the table that I had made but there is some error that said "SQL command not properly ended "
Codes :
INSERT INTO actors(actor_id, stage_name, first_name, last_name, birth_date)
VALUES(actor_id_seq.NEXTVAL, 'Brad Pitt', 'William', 'Pitt', TO_DATE('18-DEC-1963','DD-MON-YYYY'));
INSERT INTO actors(actor_id, stage_name, first_name, last_name, birth_date)
VALUES(actor_id_seq.NEXTVAL, 'Amitabh Bachchan', 'Amit', 'Srivastav', TO_DATE('11-10-1942','DD-MM-YYYY'));
INSERT INTO actors(actor_id, stage_name, first_name, last_name, birth_date)
VALUES(actor_id_seq.NEXTVAL, 'Aamir Khan', 'Aamir', 'Hussain Khan', TO_DATE('14 March 1965','DD Month YYYY'));
INSERT INTO actors(actor_id, stage_name, first_name, last_name, birth_date)
VALUES(actor_id_seq.NEXTVAL, 'Akshay Kumar', 'Rajiv', 'Bhatia', TO_DATE('09/09/1967','DD/MM/YYYY'));
I tested code you posted (on my database, using SQL*Plus); it is correctly written, there's nothing wrong with it.
I presume you're using SQL Workshop. If so, then: it runs statement-by-statement, so you'd have to highlight one INSERT and run it. Then highlight another, run it. And so forth.
Or, enclose the whole code you wrote into BEGIN-END (and make it an anonymous PL/SQL block) and then run it at once, e.g.
begin
insert into actors (actor_id, ...) values (actor_id_seq.nextval, ...);
insert into actors ...
insert into actors ...
end;
/
Related
I have an instance of a ClickHouse server running and I have successfully connected to it through a client. I'm using Tabix.io to run my queries. I have created a DB and a table called "names". I want to input a lot of randomly generated names inside that table. I know that running multiple commands like this:
insert into names (id, first_name, last_name) values (1, 'Stephana', 'Bromell');
insert into names (id, first_name, last_name) values (2, 'Babita', 'Leroux');
insert into names (id, first_name, last_name) values (3, 'Pace', 'Christofides');
...
insert into names (id, first_name, last_name) values (999, 'Ralph', 'Jackson');
is not supported and therefore it is only the first query that is executed. In other words only Stephana Bromell appear in the "names" table.
What is the ClickHouse alternative for inserting larger amounts of data?
multiple values in a single insert.
insert into names (id, first_name, last_name) values (1, 'Stephana', 'Bromell') (2, 'Babita', 'Leroux') (3, 'Pace', 'Christofides') (999, 'Ralph', 'Jackson');
How about batch inserting using http client with CSV
create csv file (names.csv) with content:
1,Stephana,Bromell
2,Babita,Leroux
3,Pace,Christofides
...
999,Ralph,Jackson
call HTTP API:
curl -i -X POST \
-T "./names.csv" \
'http://localhost:8123/?query=INSERT%20INTO%20names%20FORMAT%20CSV'
i have button with dynamic action execute pl/sql Code
on button click i have to execute two queries, initially insert in a table
and then update in another table
INSERT INTO student (student_name,
student_father,
student_dob,
student_gender,
country,
email_id,
whatsapp_number,
good_time_to_contact,
time_requested,
mobile_number,
state_province,
city,
zip_code,
skype_id,
street_adress,
course,
language_required,
class_days,
application_id,
updated_by)
SELECT first_name || ' ' || last_name AS StudentName,
father_name,
date_of_birth,
gender,
country_id,
email,
whatsapp_number,
time_to_contact,
learning_time,
mobile_number,
state_province,
city,
zip_code,
skype_id,
street_address,
course_id,
language,
class_days,
:P164_APP_ID,
:App_user
FROM student_app
WHERE app_id = :P164_APP_ID;
UPDATE student_app
SET gr_number =
(SELECT gr_number
FROM student
WHERE application_id = :P164_APP_ID),
updated_by = :App_user,
app_status = '6-STUDYING',
updated_ts = CURRENT_TIMESTAMP
WHERE app_id = :P164_APP_ID;
i am using these pl/sql code but does insert in the table nor update either.
while these code execute fine when i execute from oracle sql developer
please help me out i am using oracle apex 18.2
It seems that you didn't commit, did you?
Also, check whether you put page item(s) you use (P164_APP_ID) into the Items to submit dynamic action property (it is right below the PL/SQL code).
If your items do contain the values in the session (that you have to submit to the page, as Littlefoot said) and it still doesn't work, try adding your query to a Process in the Processing tab, with the server-side condition set to pressing the button you're pressing. I can't remember if you can set multiple statements to be run in a single process, but it's worth a try.
Something like:
Processing Tab
Code Section
Condition Section
I've two table in the database, the first one is Person and the second is Pilot. as following:
Person Table:
CREATE TABLE person(
person_id NUMBER PRIMARY KEY,
last_name VARCHAR2(30) NOT NULL,
first_name VARCHAR2(30) NOT NULL,
hire_date VARCHAR2(30) NOT NULL,
job_type CHAR NOT NULL,
job_status CHAR NOT NULL
);
/
INSERT INTO person VALUES (1000, 'Smith', 'Ryan', '04-MAY-90','F', 'I');
INSERT INTO person VALUES (1170, 'Brown', 'Dean', '01-DEC-92','P', 'A');
INSERT INTO person VALUES (2010, 'Fisher', 'Jane', '12-FEB-95','F', 'I');
INSERT INTO person VALUES (2080, 'Brewster', 'Andre', '28-JUL-98', 'F', 'A');
INSERT INTO person VALUES (3190, 'Clark', 'Dan', '04-APR-01','P', 'A');
INSERT INTO person VALUES (3500, 'Jackson', 'Tyler', '01-NOV-05', 'F', 'A');
INSERT INTO person VALUES (4000, 'Miller', 'Mary', '11-JAN-08', 'F', 'A');
INSERT INTO person VALUES (4100, 'Jackson', 'Peter', '08-AUG-11', 'P','I');
INSERT INTO person VALUES (4200, 'Smith', 'Ryan', '08-DEC-12', 'F','A');
COMMIT;
/
Pilot Table:
CREATE TABLE pilot(
person_id NUMBER PRIMARY KEY,
pilot_type VARCHAR2(100) NOT NULL,
CONSTRAINT fk_person_pilot FOREIGN KEY (person_id)
REFERENCES person(person_id)
);
/
INSERT INTO pilot VALUES (1170, 'Commercial pilot');
INSERT INTO pilot VALUES (2010, 'Airline transport pilot');
INSERT INTO pilot VALUES (3500, 'Airline transport pilot');
COMMIT;
/
I'm asked to write a pl/sql block of code that accepts the last name from the user and return the result as following:
1) if the last name is not in the table, it returns all the rows in the table.
2) if the last name is in the table, it shows all of the employee's information.
So far I'm doing well with the code, but I got stuck in the case that there are two employees with the last name. here is the cursor that I wrote:
cursor person_info is
select last_name, first_name, hire_date, job_type, job_status, nvl(pilot_type, '-----------')
from person
full outer join pilot
on person.person_id = pilot.person_id
where upper(last_name) = upper(v_last_name)
group by last_name, first_name, hire_date, job_type, job_status, pilot_type
order by last_name, first_name, hire_date asc;
Logically, there are three cases to be covered:
the first case, when the entered last name is in the table, I return all the rows in the table and that's done.
The second case when there is only one employee with the entered last name, and this case is done as well. The last case when there are more than one employee having the same last name like for example 'Jackson' or 'Smith' in this case, my program crashes and give me the error that my select into statement returns more than one row.
select person_id
into v_n
from person
where upper(last_name) = upper(v_last_name);
if v_n = 1 then
open person_info;
fetch person_info into v_last_name, v_first_name, v_hire_date, v_job_type, v_job_status, v_pilot_type;
Can someone help me in guiding me how to fetch the data correctly? I'm not allowed to create any temporary tables or views.
I'm so sorry for making the problem longer than it should, but I was trying to be as clear as possible in explaining the problem.
Thank you in advance.
if the error is
"ORA-01422 exact fetch returns more than requested number of rows" then I think your answer is here https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:981494932508
If you EXPECT the query to return more than one row, you would code:
for x in ( select * from t where ... )
loop
-- process the X record here
end loop;
Your immediate issue is that you're selecting the matching person_id into a variable, and then seeing if that specific ID is 1. You don't have an actual ID 1 anyway so that check would never match; but it is that querying matching multiple rows that gets the error, as you can't put two matching IDs into a single scalar variable.
The way you've structured it looks like you are trying to count how many matching rows there are, rather than looking for a specific ID:
select count(person_id)
into v_n
from person
where upper(last_name) = upper(v_last_name);
if v_n = 1 then
....
When you do have multiple matches then you will need to use the same mechanism to return all of those as you do when there are no matches and you return all employees. You may find the logic should be in the cursor query rather then in PL/SQL logic. It depends on the details of the assignment though, and how it expects you to return the data in both (or all three) scenarios.
It's also possible you just aren't expected to hit this problem - it isn't clear if the assignment is finding all employees, or only those that are pilots. The issue still exists in general, but with the data you show there aren't any duplicate pilot last names. If you haven't learned about this kind of error yet perhaps you're getting a bit ahead of what your tutor expects.
How can I ask SQLDeveloper to generate CRUD templates for a given table, and place them in a SQLWorksheet, so that I can fill in the arguments by hand and execute the DML operation requested?
The feature I'm looking for would be roughtly equivalant to the MS SQLServer SSMS "Script Table as" -> "Select | Insert | Update To" -> "Query Editor" which is available when Right clicking a Table.
Additionally if you have any tips on how to look at the definition of Two tables from the same Connection at once, I would be most appreciative.
drag and drop your table to a worksheet
This generates
INSERT
INTO EMPLOYEES
(
EMPLOYEE_ID,
FIRST_NAME,
LAST_NAME,
EMAIL,
PHONE_NUMBER,
HIRE_DATE,
JOB_ID,
SALARY,
COMMISSION_PCT,
MANAGER_ID,
DEPARTMENT_ID
)
VALUES
(
:v0,
:v1,
:v2,
:v3,
:v4,
:v5,
:v6,
:v7,
:v8,
:v9,
:v10
);
If you select multiple objects and choose 'SELECT' and 'JOIN', we'll join the tables together, assuming you have a Foreign Key constraint linking them.
So I created the following trigger, when I am creating the issue its not coming out to the command promt and keeps blinking on the the next line.
drop trigger insert_data_to_employee;
CREATE OR REPLACE TRIGGER insert_data_to_employee
AFTER INSERT ON dummy_emp
FOR EACH ROW
BEGIN
-- Insert record into employee table
INSERT INTO employee
( lname,
ssn,
salary,
dno)
VALUES
( 'smith',
'123456785',
98765,
1);
END;/
please help !! any help is much appreciated
I just validated my suspicious.
In SQLPlus if you'll input the command like that - the UI will not "understand" that you finished the command, and will expect more characters before parsing the text you submitted.
you have to put the ending mark "/" on a new line.
run:
drop trigger insert_data_to_employee;
CREATE OR REPLACE TRIGGER insert_data_to_employee
AFTER INSERT ON dummy_emp
FOR EACH ROW
BEGIN
-- Insert record into employee table
INSERT INTO employee
( lname,
ssn,
salary,
dno)
VALUES
( 'smith',
'123456785',
98765,
1);
END;
/
And it will compile.
Please not that this is an SQLPlus thing, not a "syntax" issue.
that's the way this UI handles multiple lines submitted in a command prompt app.