0

I have a Sql query as:

SET @title1 = 'text_title';
SET @content1 = 'Text_contents';

INSERT INTO `tablename` (`ID`, `content`, `title`)
     VALUES
     (101, @content1, @title1)
ON DUPLICATE KEY UPDATE
    content = VALUES(content),
    title = VALUES(title);

I want to laod a text file and use its contents for the content's column, instead of declaring it with SET, and if possible, load the text file's name as the title.

How can I do so?

If my question needs some corrections, please let me know. I looked around the internet and SO, and I believe my syntaxes weren't right with what I tried.

To be exact, I tried the following:

UPDATE table_names
SET name = Content
FROM (
    SELECT * FROM OPENROWSET(BULK 'D:\ttt.txt', SINGLE_CLOB)) AS Content
WHERE ID = 3;

.

LOAD DATA 'D:\\ttt.txt' 
INTO TABLE table_names 
WHERE ID = 3;

And some variations that I tested all through.

Any help is appreciated.

4
  • Try: SELECT Content.Bulkcolumn AS Content FROM OPENROWSET(BULK 'D:\ttt.txt', SINGLE_CLOB) AS Content; Because the column name returned is Bulkcolumn, and you are using Content. Commented Mar 3, 2022 at 10:18
  • @Luuk If you can, please guide me to form the whole query. As even with many searches done previously, I get confused with how to use the value returned by the SELECT, like in your suggestion's case Commented Mar 3, 2022 at 10:35
  • Wait, this question is about mysql.... I did see OPENROWSET and I thought that it was about MS-SQL..... Commented Mar 3, 2022 at 10:45
  • Oh Im sorry, mysql does not seem to have OPENROWSET. I thought Sql used the same language/syntaxing as MsSql Commented Mar 3, 2022 at 10:48

1 Answer 1

1

In MySQL you can do:

UPDATE table_names
SET name = LOAD_FILE('D:\\ttt.txt')
WHERE ID=3;

see: LOAD_FILE

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.